# Ubuntu install Laravel

I am using digitalocean VPS service, since GitHub Student Developer Pack (opens new window) have $50 in platform credit for new users.

OS: Ubuntu 18.04.3 (LTS) x64

How to Install and Configure Laravel with LEMP on Ubuntu 18.04 (opens new window)


  1. Initial Server Setup with Ubuntu 18.04 guide
  2. Install Linux, Nginx, MySQL, PHP (LEMP stack)
  3. Install Composer
  4. Install Git and setup Github ssh login
  5. Clone github project, deploy

# 1. Initial Server Setup with Ubuntu 18.04


Get Ip

# ~/.ssh is used by default
ssh [email protected]


# ufw setup

ufw (opens new window) is an easy Firewall Management tool.

ufw app list

# Allow OpenSSH to make sure we can use ssh service after enabled ufw
ufw allow OpenSSH
ufw enable
ufw status

# Install VNC

How to Install and Configure VNC on Ubuntu 18.04 (opens new window)

sudo apt update
sudo apt install xfce4 xfce4-goodies
sudo apt install tightvncserver

#For copy & paste https://unix.stackexchange.com/a/274692
sudo apt-get install autocutsel

# setup password between 6 to 8 


# Close vncserver before setup configuring VNC Server
vncserver -kill :1
# backup original xstartup file
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak

nano ~/.vnc/xstartup

copy in xstartup

xrdb $HOME/.Xresources
autocutsel -fork
startxfce4 &
# make it executable
sudo chmod +x ~/.vnc/xstartup
# restart

# Create an SSH connection forwards to the localhost connection for VNC.
ssh -L 5901: [email protected]

# Or open 5901 port to use remote url access
sudo ufw allow 5901

# Contect VNC

Use any VNC Client tool, i am using Jump Desktop (opens new window) -c

Click Use default config

How to fix "Failed to Execute Default Web Browser. Input/Output Error." (opens new window)

sudo apt-get install firefox

# 2. Install Nginx, MySQL, PHP (LEMP stack)

# Nginx


sudo apt update
sudo apt install nginx

#Open port 80,443
sudo ufw allow 'Nginx HTTP'
sudo ufw allow 'Nginx HTTPS'

now, go to localhost in Browser will display welcome page


sudo apt install mysql-server

# inside mysql environment
sudo mysql

# Check authentication method of each MySQL user accounts
SELECT user,authentication_string,plugin,host FROM mysql.user;

| user             | authentication_string                     | plugin                | host      |
| root             |                                           | auth_socket           | localhost |
| mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost |

change auth_socket to mysql_native_password

# change authentication method and set password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

# reload the grant tables

#login mysql
mysql -u root -p
# create database - booking

# create user - booking_user which have all permission of database - booking
GRANT ALL ON booking.* TO 'booking_user'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

# Allow Remote Access to MySQL


# change bind-address from to
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

sudo systemctl restart mysql
ufw allow mysql
# Try in mysql client


# add universe repository to install php
sudo add-apt-repository universe

sudo apt install php-fpm php-mysql
sudo apt install php-mbstring php-xml php-bcmath

# Nginx Architecture

sites-available - linkup -> sites-enabled

# setup server block configuration(example.com) in sites-available
sudo nano /etc/nginx/sites-available/example.com
server {
        listen 80;
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name example.com;

        location / {
                try_files $uri $uri/ =404;

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;

        location ~ /\.ht {
                deny all;
# linkup sites-available/example.com to sites-enabled/
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

# unlink the default configuration file 
sudo unlink /etc/nginx/sites-enabled/default

# check have not errors
sudo nginx -t

sudo systemctl reload nginx

# create index.php
sudo nano /var/www/html/index.php

now, we need add one record in /etc/hosts example.com


Or, use Server IP:

# 3.Install Composer

sudo apt update
sudo apt install curl php-cli php-mbstring git unzip

cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php

copy Installer Signature (SHA-384) in https://composer.github.io/pubkeys.html

# paster here

# verify installation script, if correct output will display "Installer verified"

php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

# install composer in /usr/local/bin
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

# 4. Install Git and setup Github ssh login

sudo apt-get install git

git config --global user.name "Your name"
git config --global user.email email

# use ssh ( Optional )

sudo apt-get install ssh
ssh-keygen -t rsa -C "github email"

#copy output
cat ~/.ssh/id_rsa.pub

# test
ssh -T [email protected]


# 5. Clone github project, deploy

cd /var/www/
# Clone own project
# Option 1. use ssh (setup in above step) 
sudo git clone [email protected]:WingCH/Booking_Web.git

# Option 1. use https

# setup this config in order to input password once only
# https://blog.csdn.net/Aifore/article/details/82870825
git config --global credential.helper store
# input password after this command 
#(if using two factor authentication need to use personal access token https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line )
sudo git clone https://github.com/WingCH/Booking_Web.git

cd Booking_Web

# give the web server user write access to the storage and cache
sudo chown -R www-data.www-data storage
sudo chown -R www-data.www-data bootstrap/cache
# copy and rename .env.example to .env
mv .env.example .env
# install Laravel lib
composer install
# generate APP_KEY into .env
php artisan key:generate

# Create and edit nginx config file
sudo nano /etc/nginx/sites-available/booking

Copy https://laravel.com/docs/5.8/deployment#server-configuration

# modify `server_name` and `root`
server_name server_domain_or_IP;
root /var/www/Booking_Web/public;
sudo ln -s /etc/nginx/sites-available/booking /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

now, we need add one record in /etc/hosts your_server_name

Successful access website, it is because no database record.

ufw allow mysql
ufw status



Last Updated: Fri Nov 15 2019 12:22:29 GMT+0000
(adsbygoogle = window.adsbygoogle || []).push({});