Skip to content

Instantly share code, notes, and snippets.

@BenaddiRar
Last active February 27, 2023 12:27
Show Gist options
  • Save BenaddiRar/6d3bd6d7301b1f7cd1ca822f1843c5f5 to your computer and use it in GitHub Desktop.
Save BenaddiRar/6d3bd6d7301b1f7cd1ca822f1843c5f5 to your computer and use it in GitHub Desktop.
Prepare your UBUNTU SERVER for a Laravel application

Prepare your UBUNTU SERVER for a Laravel application

This documentation includes all the installation needed to prepare an ubuntu server for a laravel project.

ZSH

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

PHP

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

NGINX

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

Composer

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

MariaDB

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

CRON

Installation and activation of CRON on your server

apt install cron
systemctl enable --now cron

SUPERVISORD

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

SSH

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

Redis

Install Redis

sudo apt-get update
sudo apt install redis
redis-cli --version

NodeJS

Install NodeJS

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt install nodejs
node -v

Laravel Echo

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment