0% found this document useful (0 votes)
198 views8 pages

b.10. How To Install Laravel 5.6 PHP Framework With Nginx On Ubuntu 18.04

Como instalar Laravel 5.6 PHP Framework con Nginx en Ubuntu 18.04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
198 views8 pages

b.10. How To Install Laravel 5.6 PHP Framework With Nginx On Ubuntu 18.04

Como instalar Laravel 5.6 PHP Framework con Nginx en Ubuntu 18.04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

8/6/2018 How to Install Laravel 5.6 PHP Framework with Nginx on Ubuntu 18.

04
English | Deutsch Log in or Sign up

Tutorials Tags Forums Linux Commands Subscribe ISPConfig News

 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.

How to Install Laravel 5.6 PHP Framework with Nginx on Ubuntu


18.04

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

Step 1 - Update Ubuntu

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.

sudo apt update


sudo apt upgrade

Reboot your server and then connect again using ssh.

Step 2 - Install Nginx

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.

sudo apt install nginx -y

After the installation is complete, start the nginx service and add it to start automatically at system boot using the systemctl command.

systemctl start nginx


systemctl enable nginx

Nginx is running on port 80, check related stats using the netstat command.

netstat -plntu

Or you can use the curl command as well.

curl -I localhost

Step 3 - Install PHP 7.2 and PHP-FPM

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

Uncomment the following CGI line, and change the value to 0.

cgi.fix_pathinfo=0

That's it. Save and exit.

Now we can start PHP-FPM and enable it to start automatically at system boot.

systemctl start php7.2-fpm


systemctl enable php7.2-fpm

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:

netstat -pl | grep php7.2-fpm

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.

Step 4 - Install MariaDB

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.

Install MariaDB from the repository using the following command.

sudo apt install mariadb-server mariadb-client -y

After the installation is complete, run MariaDB and enable it to launch at system boot.

systemcl start mysql


systemctl enable mysql

MariaDB started on port 3306, check it using the netstat command.

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.

Set root password? [Y/n] Y


Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

MariaDB installation and configuration has been completed.

Step 5 - Install PHP Composer

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.

Install PHP Composer with the following command.

sudo apt install composer -y

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

PHP Composer installed on Ubuntu 18.04.

Step 6 - Configure Nginx virtual host for Laravel

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

Paste the following configuration there.

server {
listen 80;
listen [::]:80 ipv6only=on;

# Log files for Debugging


access_log /var/log/nginx/laravel-access.log;
error_log /var/log/nginx/laravel-error.log;

# Webroot Directory for Laravel project


root /var/www/laravel/public;
index index.php index.html index.htm;

# Your Domain Name


server_name laravel.hakase-labs.co;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

# PHP-FPM Configuration Nginx


location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

That's it. Save and exit.

Now activate the virtual host by creating a symlink of the 'laravel' file to the 'sites-enabled' directory.

Then test nginx configuration and make sure there is no error.

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.

systemctl restart nginx

Step 7 - Install Laravel

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.

sudo apt install unzip -y

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.

Run the following composer command.

composer create-project laravel/laravel .

You need to wait for the Laravel installation.

Laravel installation is complete.

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

chown -R www-data:root /var/www/laravel


chmod 755 /var/www/laravel/storage

Laravel Installation has been completed without any error.

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/.

And you should see the Laravel home page.

Laravel Installation with Nginx, PHP-FPM 7.2 and MariaDB on Ubuntu 18.04 is successful.

References
https://laravel.com/docs/5.6/installation

view as pdf | print

Share this page:

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

Author: Muhammad Arul


Published: Jun 07, 2018
Tags: linux, php, programming, ubuntu, web server

 Share This Page

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

The Perfect Server - Ubuntu 18.04 (Bionic Beaver)


with Apache, PHP, MySQL, PureFTPD, BIND, Postfix,
Dovecot and ISPConfig 3.1

How to use grep to search for strings in files on the


shell

Setting, Changing And Resetting MySQL Root


Passwords

How to use the Linux ftp command to up- and


download files on the shell

Linux pstree Command Tutorial for Beginners (8


Examples)

Linux Basics - Set a Static IP on Ubuntu

How to Install Apache Maven on Ubuntu 18.04 LTS

A Beginner's Guide To LVM

The Perfect Server - Debian 9 (Stretch) with


Apache, BIND, Dovecot, PureFTPD and ISPConfig
3.1

Linux sort Command Tutorial for Beginners (8


Examples)

Xenforo skin by Xenfocus Contribute Contact Help Imprint and Legal Notice

Howtoforge © projektfarm GmbH. Terms and Rules Privacy Policy

https://www.howtoforge.com/tutorial/ubuntu-laravel-php-nginx/ 8/8

You might also like