QRdvark.com

Setting Up LEMP Stack On Ubuntu 15 10

Setting Up LEMP Stack On Ubuntu 15 10

  1. Abstract
  2. Installing Packages
  3. Configuration
  4. Credits
Abstract

In the beginning, the combination of Linux Apache MySQL PHP became affectionately known as the LAMP stack. Now a new breed of webserver is upon us in the form of nginx and growing in popularity. This tutorial shows how the combination of Linux NGINX MySQL PHP, or the LEMP stack can be setup on Ubuntu with a minimum of fuss. At the time of this writing, the ubuntu server is 15.10.

Installing Packages

Before installing any new packages, be sure the system is up to date.

sudo apt-get update

As a personal preference, using vim for GIT commits is prefered, so remove nano and intall vim. If nano is left installed, GIT will default to using nano rather than the wholesome goodness of vim.

sudo apt-get remove nano
sudo apt-get install vim

Install the nginx web server

sudo apt-get install nginx

Install the MySQL server and client

sudo apt-get install mysql-server php5-mysql

And install PHP

sudo apt-get install php5-fpm

Finally restart the web server

sudo service nginx start

You should now be able to see the default index page at http://localhost.

Configuration

Unlike the installation of LAMP, things do not 'just work' with the LEMP stack, and a little configuration is required. Notably, to PHP.

A small change needs to be made to the php.ini file for pathinfo.

Find the line below, even if commented out, uncomment it.

cgi.fix_pathinfo=1

And change it to

cgi.fix_pathinfo=0

Finally, the configuration file for the domain (loalhost) needs to be updated. A working file has been supplied here, which supports PHP being served by NGINX on port 80. Edit the existing file, or simply copy this file in its place. Remember to make a backup.

The configuration file can be found in /etc/nginx/sites-available/default

# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
        }
}

That just about does it for configuration. All that is now required is to create a PHP file for testing.

In /var/www/html create a file called index.php and in the file put


<?php phpinfo(); ?>

Finally, restart php-fpm and nginx

sudo service php5-fpm restart
sudo service nginx restart
Credits

Nothing to see here, move along...