Sei sulla pagina 1di 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 TagsTags ForumsForums LinuxLinux CommandsCommands SubscribeSubscribe
English |
Deutsch
Log in or Sign up
Tutorials
TagsTags
ForumsForums
LinuxLinux CommandsCommands
SubscribeSubscribe
ISPConfigISPConfig
NewsNews
 TutorialTutorial searchsearch
TutorialsTutorials
HowHow toto InstallInstall LaravelLaravel 5.65.6 PHPPHP FrameworkFramework withwith NginxNginx onon UbuntuUbuntu 18.0418.04

Ad

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 MVC (Model-View-Controller) design pattern. Created by Taylor Otwell in 2011, it as an attempt to provide an advanced alternative to the CodeIgniter (CI) framework. In 2011, Laravel released version 1 and version 2, and the latest version 5.6 comes with more and improved features like Command-Line (CLI) support named 'artisan', support for different database systems, Route improvements etc.

This tutorial exists for these OS versions

On this page

In this tutorial, I will guide you step-by-step on how to install Laravel version 5.6 with Nginx as the web server, PHP-FPM 7.2, and MariaDB. Laravel 5.6 will run under LEMP stack with Ubuntu 18.04 as OS version.

There is a version of this tutorial for Laravel on CentOS 7 as well.

What we will do Prerequisites Step 1 - Update Ubuntu Step 2 - Install Nginx Step 3 - Install PHP 7.2 and PHP-FPM Step 4 - Install MariaDB Step 5 - Install PHP Composer Step 6 - Configure Nginx virtual host for Laravel Step 7 - Install Laravel Step 8 - Testing References

What we will do Verify Email Lists Fast Reach Real People By Letting ZeroBounce Be
What we
will do
Verify Email Lists Fast
Reach Real People By Letting
ZeroBounce Be Your Email
List Veri er.
Update Ubuntu
Repository
Install Nginx
Install PHP-FPM 7.2
Install MariaDB
Install PHP Composer
Configure Nginx Virtual Host for Laravel
Install Laravel
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

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

related stats using the netstat command. netstat -plntu Or you can use the curl command as

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

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 -

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

3306, check it using the netstat command. netstat -plntu Next, configure the MariaDB root password with

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

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

will get the results as shown in the screenshot. composer PHP Composer installed on Ubuntu 18.04.

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.

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

now restart the nginx service. systemctl restart nginx Step 7 - Install Laravel Before we start

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.

. You need to wait for the Laravel installation. Laravel installation is complete. We need to

Laravel installation is complete.

the Laravel installation. Laravel installation is complete. We need to change the ownership of the Laravel

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.

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
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
Suggested articles

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 
0 Comment(s)
Add comment
Name *
Email *





p
SubmitSubmit commentcomment
I'm not a robot
reCAPTCHA
Privacy - Terms
TutorialsTutorials
HowHow toto InstallInstall LaravelLaravel 5.65.6 PHPPHP FrameworkFramework withwith NginxNginx onon UbuntuUbuntu 18.0418.04
SignSign upup now!now!
SignSign upup now!now!
 TutorialTutorial InfoInfo Author: Published: Muhammad Arul Jun 07, 2018 Tags: linux, php, programming, ubuntu,
 TutorialTutorial InfoInfo
Author:
Published:
Muhammad Arul
Jun 07, 2018
Tags: linux, php, programming, ubuntu, web server
 ShareShare ThisThis PagePage
40.2k Followers

8/6/2018

How to Install Laravel 5.6 PHP Framework with Nginx on Ubuntu 18.04

Xenforo skin by Xenfocus Howtoforge © projektfarm GmbH.  PopularPopular TutorialsTutorials The Perfect Server
 PopularPopular TutorialsTutorials The Perfect Server - Ubuntu 18.04 (Bionic Beaver) with Apache, PHP, MySQL,
 PopularPopular TutorialsTutorials
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)