b.10. How To Install Laravel 5.6 PHP Framework With Nginx On Ubuntu 18.04
b.10. How To Install Laravel 5.6 PHP Framework With Nginx On Ubuntu 18.04
04
English | Deutsch Log in or Sign up
Tutorial search
Tutorials How to Install Laravel 5.6 PHP Framework with Nginx on Ubuntu 18.04
Ad Scan your Web-Server for Malware with ISPProtect now. Get Free Trial.
Laravel is a free and open source PHP framework that implements the
This tutorial exists for these OS versions
MVC (Model-View-Controller) design pattern. Created by Taylor Otwell in
2011, it as an attempt to provide an advanced alternative to the
Ubuntu 18.04 (Bionic Beaver)
CodeIgniter (CI) framework. In 2011, Laravel released version 1 and
Ubuntu 16.04 (Xenial Xerus)
version 2, and the latest version 5.6 comes with more and improved
Ubuntu 15.10 (Wily Werewolf)
features like Command-Line (CLI) support named 'artisan', support for
different database systems, Route improvements etc.
On this page
In this tutorial, I will guide you step-by-step on how to install Laravel What we will do
version 5.6 with Nginx as the web server, PHP-FPM 7.2, and MariaDB. Prerequisites
Laravel 5.6 will run under LEMP stack with Ubuntu 18.04 as OS version. Step 1 - Update Ubuntu
Step 2 - Install Nginx
Step 3 - Install PHP 7.2 and PHP-FPM
There is a version of this tutorial for Laravel on CentOS 7 as well. Step 4 - Install MariaDB
Step 5 - Install PHP Composer
Step 6 - Configure Nginx virtual host for Laravel
Step 7 - Install Laravel
What we Step 8 - Testing
will do References
Update Ubuntu
Repository
Install Nginx
Install PHP-FPM 7.2
Install MariaDB
Verify Email Lists Fast Install PHP Composer
Configure Nginx Virtual Host for Laravel
Reach Real People By Letting
ZeroBounce Be Your Email
Install Laravel
List Veri er. Testing
Prerequisites
Ubuntu 18.04 server
Root privileges
Before we start with the installation, we need to update the repository and then update all packages to the latest version. So to do that, first
login to the Ubuntu server using ssh.
ssh root@ip
Now, update your Ubuntu repository and upgrade all packages on your system to the latest version.
https://www.howtoforge.com/tutorial/ubuntu-laravel-php-nginx/ 1/8
8/6/2018 How to Install Laravel 5.6 PHP Framework with Nginx on Ubuntu 18.04
In this step, we will install Nginx 1.14 to the system. It's available on default ubuntu repository, you just need to install it with the following apt
command.
After the installation is complete, start the nginx service and add it to start automatically at system boot using the systemctl command.
Nginx is running on port 80, check related stats using the netstat command.
netstat -plntu
curl -I localhost
Nginx is installed, and now we need to install PHP-FPM version 7 on the system. We will install PHP 7.2 and some PHP extensions needed by
Laravel.
Install PHP and PHP-FPM 7.2 with all extensions needed using the following command.
sudo apt install php7.2 php7.2-curl php7.2-common php7.2-cli php7.2-mysql php7.2-mbstring php7.2-fpm php7.2-xml php7.2-zip -y
Next, go to the PHP configuration directory and edit the php.ini file present in the fpm directory.
cd /etc/php/7.2/
vim fpm/php.ini
cgi.fix_pathinfo=0
Now we can start PHP-FPM and enable it to start automatically at system boot.
By default on Ubuntu, PHP-FPM is running under the sock file. Check the PHP-FPM sock file with the netstat command in the following way:
https://www.howtoforge.com/tutorial/ubuntu-laravel-php-nginx/ 2/8
8/6/2018 How to Install Laravel 5.6 PHP Framework with Nginx on Ubuntu 18.04
PHP and PHP-FPM 7.2 has been installed on the Ubuntu 18.04 systems.
This is optional, but when your Laravel project is based on MySQL, you need to do this for your project. We will install MariaDB latest version
10.1 on to the system.
After the installation is complete, run MariaDB and enable it to launch at system boot.
netstat -plntu
Next, configure the MariaDB root password with the 'mysql_secure_installation' command below.
mysql_secure_installation
Input your root password, remove anonymous users, disallow root login remotely etc.
The composer is a package manager for the PHP programming language. Created in 2011, it's inspired by Node.js 'npm' and Ruby's named
'bundler'. On ubuntu 18.04, composer is available in the repository, so we can install it using the apt command.
https://www.howtoforge.com/tutorial/ubuntu-laravel-php-nginx/ 3/8
8/6/2018 How to Install Laravel 5.6 PHP Framework with Nginx on Ubuntu 18.04
After the installation has been completed, run 'composer' command and you will get the results as shown in the screenshot.
composer
In this step, we will configure the nginx virtual host for Laravel. But before we do that, we must decide the directory for our Laravel project. In
our case, we will use '/var/www/laravel' directory for the project. Just create it with mkdir.
mkdir -p /var/www/laravel
Next, go to the nginx configuration directory and create a new virtual host file 'laravel' under the 'sites-available' directory.
cd /etc/nginx/
vim sites-available/laravel
server {
listen 80;
listen [::]:80 ipv6only=on;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
Now activate the virtual host by creating a symlink of the 'laravel' file to the 'sites-enabled' directory.
https://www.howtoforge.com/tutorial/ubuntu-laravel-php-nginx/ 4/8
8/6/2018 How to Install Laravel 5.6 PHP Framework with Nginx on Ubuntu 18.04
ln -s /etc/nginx/sites-available/laravel /etc/nginx/sites-enabled/
nginx -t
Nginx virtual host for laravel has been created, now restart the nginx service.
Before we start with Laravel installation, make sure the unzip utility is installed on your system. If you do not have the tool, install it using the
following command.
We've already defined a directory for Laravel : '/var/www/laravel' directory. Go to that directory.
cd /var/www/laravel
Install Laravel with the composer command. There are two ways to install Laravel: Installing via the Laravel Installer and Installing via Composer
create project.
We will install latest Laravel version 5.6 via the composer create project.
We need to change the ownership of the Laravel project directory to 'www-data' user, and change the permission of the storage directory to
755.
https://www.howtoforge.com/tutorial/ubuntu-laravel-php-nginx/ 5/8
8/6/2018 How to Install Laravel 5.6 PHP Framework with Nginx on Ubuntu 18.04
Step 8 - Testing
In the virtual host configuration file, we've already defined the domain name for Laravel 'laravel.hakase-labs.co'.
Open your web browser and visit the domain you installed Laravel on, mine here on the test server is http://laravel.hakase-labs.co/.
Laravel Installation with Nginx, PHP-FPM 7.2 and MariaDB on Ubuntu 18.04 is successful.
References
https://laravel.com/docs/5.6/installation
Suggested articles
https://www.howtoforge.com/tutorial/ubuntu-laravel-php-nginx/ 6/8
8/6/2018 How to Install Laravel 5.6 PHP Framework with Nginx on Ubuntu 18.04
0 Comment(s)
Add comment
Name * Email *
p
Submit comment
I'm not a robot
reCAPTCHA
Privacy - Terms
Tutorials How to Install Laravel 5.6 PHP Framework with Nginx on Ubuntu 18.04
Sign up now!
Tutorial Info
40.2k Followers
https://www.howtoforge.com/tutorial/ubuntu-laravel-php-nginx/ 7/8
8/6/2018 How to Install Laravel 5.6 PHP Framework with Nginx on Ubuntu 18.04
Popular Tutorials
Xenforo skin by Xenfocus Contribute Contact Help Imprint and Legal Notice
https://www.howtoforge.com/tutorial/ubuntu-laravel-php-nginx/ 8/8