Install Laravel Nginx 16.04

Install Laravel Nginx 16.04

What is Laravel?

Laravel is an open source PHP framework designed to organize, develop, and easily deploy modern web applications. It is built on the Model-View-Controller (MVC) architectural pattern. Laravel emerged in 2011 and has since become one of the most popular open source web frameworks. It is widely used for developing robust web applications faster than other frameworks.

Laravel is built on components from the Symfony framework, which are focused on the performance, security, and scalability of applications. It is also heavily influenced by Ruby on Rails. Laravel includes a number of features that make developing web apps easier. These features include object-oriented libraries, built-in authentication and authorization, database queries and template engines, routing systems, and unit testing.

What is Nginx?

Nginx (pronounced “engine-ex”) is a lightweight web server that is used to serve web applications. It was originally developed by Igor Sysoev in 2002, and has since become one of the most popular web servers. Nginx is used by millions of websites and is an essential component of modern web architectures. It is often used in combination with other technologies such as PHP, MySQL, and Apache.

Nginx is designed to handle high traffic loads and is more efficient than other web servers. Unlike Apache, Nginx does not use a single-threaded, process-driven model. Instead, it uses an event-driven, non-blocking model that uses a very small memory footprint. Nginx is optimized for performance and can serve more requests per second than other web servers.

Installing Nginx On Ubuntu 16.04

In this guide, we will show you how to install Nginx on an Ubuntu 16.04 server. This guide should work for most other versions of Ubuntu, including 14.04 and 18.04.

Before getting started, you will need an Ubuntu 16.04 server with a non-root user that has sudo privileges. You can learn more about setting up an Ubuntu 16.04 server in our Initial Server Setup guide.

To begin, update the package list and install Nginx:

$ sudo apt update

$ sudo apt install nginx

Once the installation is complete, you can test the installation by typing:

$ systemctl status nginx

The output should look something like this:

● nginx.service – A high performance web server and a reverse proxy server

Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)

Active: active (running) since Mon 2020-04-20 02:45:44 UTC; 7min ago

Main PID: 3385 (nginx)

Tasks: 2 (limit: 1152)

CGroup: /system.slice/nginx.service

├─3385 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;

└─3386 nginx: worker process

Configuring Firewall for Nginx

Once installed, Nginx will be listening for incoming requests on port 80. To make sure that Nginx can receive requests from outside of your server, you will need to configure your server’s firewall. You can do this by typing:

$ sudo ufw allow ‘Nginx Full’

Once the firewall is configured, you can test that it is working by typing:

$ sudo ufw status

The output should look like this:

Status: active

To Action From

— —— —-

Nginx Full ALLOW Anywhere

Nginx Full (v6) ALLOW Anywhere (v6)

Installing PHP For Nginx

Once Nginx is installed and the firewall is configured, you can set up PHP. To do this, type:

$ sudo apt install php-fpm php-mysql

PHP-FPM (FastCGI Process Manager) is an implementation of FastCGI for PHP that is optimized for enhanced performance. This will handle the dynamic processing of your PHP code.

Once the installation is complete, you can test that it is working by typing:

$ php -v

The output should look something like this:

PHP 7.2.15-0ubuntu0.18.04.1 (cli) (built: Feb 8 2019 10:12:39) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Configuring Nginx With Laravel

Once PHP is installed, you can configure Nginx to serve your Laravel application. To do this, you will need to create a new server block in Nginx’s configuration files. This will tell Nginx to proxy requests for your Laravel application to the PHP-FPM server.

Create a new server block configuration file by typing:

$ sudo nano /etc/nginx/sites-available/laravel

Add the following to the file:

server {

listen 80;

root /var/www/;

index index.php index.html index.htm;


location / {

try_files $uri $uri/ /index.php?$query_string;


location ~ .php$ {

include snippets/fastcgi-php.conf;

fastcgi_pass unix:/run/php/php7.2-fpm.sock;


location ~ /.ht {

deny all;



Save and close the file, then enable the server block by typing:

$ sudo ln -s /etc/nginx/sites-available/laravel /etc/nginx/sites-enabled/

Test the configuration file for syntax errors by typing:

$ sudo nginx -t

If there are no issues, you can restart Nginx by typing:

$ sudo systemctl restart nginx

Using Composer to Install Laravel

Once you have Nginx and PHP set up, you can install Laravel using the Composer package manager. It is recommended that you use Composer to install Laravel instead of downloading the zip package from the Laravel website.

To install Composer, you first need to install the dependencies it requires. You can do this by typing:

$ sudo apt install composer

Once the installation is complete, you can install Laravel by typing:

$ composer create-project –prefer-dist laravel/laravel example-project

This will create a new Laravel project in a folder called “example-project”. Change to this directory by typing:

$ cd example-project

You can now test the configuration by running the development server. To do this, type:

$ php artisan serve

Leave a Reply

Your email address will not be published. Required fields are marked *