This documentation includes all the installation needed to prepare an ubuntu server for a laravel project.
First i prefer to use "ZSH" shell for my server
sudo apt install zsh
zsh --version
echo $SHELL
chsh -s $(which zsh)
After that you van add all your alias
nano ~/.zshrc
Install all desired PHP versions:
apt-get install software-properties-common gnupg2 -y
add-apt-repository ppa:ondrej/php
apt-get update -y
apt-get install php7.4 php7.4-fpm php7.4-curl php7.4-mysql php7.4-cli php7.4-bcmath php7.4-common php7.4-xml php7.4-mbstring php7.4-intl php7.4-gd php7.4-pcntl php7.4-zip php7.4-soap -y
apt-get install php8.1 php8.1-fpm php8.1-curl php8.1-mysql php8.1-cli php8.1-bcmath php8.1-common php8.1-xml php8.1-mbstring php8.1-intl php8.1-gd php8.1-zip php8.1-soap -y
You can change the default php version used in command line just by using this command
update-alternatives --config php
For my webserver i prefer to use nginx
apt-get install nginx -y
And to add a site
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
systemctl restart nginx
After that you need to install composer.
dd1
sudo apt update
sudo apt install unzip
dd2
cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
HASH=`curl -sS https://composer.github.io/installer.sig`
echo $HASH
dd3
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
dd4
composer --version
For the database I am using MariaDB
dd1
sudo apt update
sudo apt install mariadb-server
sudo mysql_secure_installation
To disable root login without password. From mysql console
GRANT ALL ON *.* TO root@localhost IDENTIFIED BY 'MY_PASSWORD' WITH GRANT OPTION;
Create DB and User and PRIVILEGES:
CREATE DATABASE db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'db_user'@'localhost' IDENTIFIED BY '@XY-xy_//@';
GRANT ALL PRIVILEGES ON db_name.* TO 'db_user'@'localhost'
To export/import databases, use this command :
mysql -u root -p db_name < db_name.sql
mysqldump -u root -p db_name > db_name.sql
Installation and activation of CRON on your server
apt install cron
systemctl enable --now cron
Installation and activation of SUPERVISORD on your server
apt-get update -y
apt-get install supervisor -y
supervisord -v
systemctl enable supervisor
systemctl status supervisor
Enable Supervisor Web Interface
nano /etc/supervisor/supervisord.conf
Add the following lines:
[inet_http_server]
port=*:9001
username=super-admin
password=SpVisor2022**
dd1
systemctl restart supervisor
Update SSH to disable password login and change default port for security reasons
dd1
ssh-copy-id your-user-name@your-ubuntu-server-name
// or specify another .pub file
ssh-copy-id -i ~/.ssh/file.pub your-user-name@your-ubuntu-server-name
dd2
nano /etc/ssh/sshd_config
dd3
# After you replaced the line:
PasswordAuthentication yes
# with the line:
PasswordAuthentication no
sudo service ssh restart
Change SSH PORT :
nano /etc/ssh/sshd_config
Port 417
sudo service ssh restart
Install Redis
sudo apt-get update
sudo apt install redis
redis-cli --version
Install NodeJS
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt install nodejs
node -v
Install Laravel Echo Server
The following are required to function properly :
- Laravel > 5.3
- Node > 6.0+
- Redis > 3+
npm install -g laravel-echo-server
sudo apt install nodejs
node -v