In this guide we will help you install Nginx, a fast and lightweight HTTP and mail proxy server, under a system running Ubuntu 11.10 (Oneiric Ocelot) and Ubuntu 12.04 (Precise Pangolin). The guide is also workable for older versions of Ubuntu (11.04/10.10/10.04).  We have previously seen how to install the LAMP web server on Ubuntu, you can check the tutorial here.

Getting Started

1. MySQL Server Setup

Install first the MySQL server with this command:

sudo apt-get install mysql-server mysql-client

Note: during the installation, you will be prompted to enter a MySQL user password, you can change this password later using the instructions given here.

2. PHP5 Setup

To run PHP5 (FastCGI) with Nginx, we need to install the PHP-FPM package (daemon process) with the following command:

sudo apt-get install php5-fpm

You can also install these optional modules:

sudo apt-get install -y php-pear php5-mysql php5-curl php5-gd php5-idn php5-imagick php5-recode

sudo apt-get install -y php5-mcrypt php5-imap php5-mhash php5-memcache php5-ming php5-xmlrpc

sudo apt-get install -y php5-sqlite php5-tidy php5-snmp php5-xsl php5-json php5-ps php5-pspell

3. Nginx Setup

Install Nginx now with this command:

sudo apt-get install nginx

Then start it:

sudo /etc/init.d/nginx start

To configure Nginx, you can later edit this file:

sudo gedit /etc/nginx/nginx.conf

You can find here some help about configuring Nginx. To make Nginx listen for IPv4 and IPv6 on port 80, then do the following:

- Run this command:

sudo gedit /etc/nginx/sites-available/default

Then uncomment (take off "#") these two lines:

listen   80; ## listen for ipv4; this line is default and implied

listen   [::]:80 default ipv6only=on; ## listen for ipv6

- In the same file, uncomment also these lines required for running PHP5 with Nginx:

location ~ \.php$ {
   fastcgi_index index.php;
   include fastcgi_params;

- Press Ctrl+Q and save your file. Restart now Nginx with this command:

 sudo /etc/init.d/nginx restart

- To test if PHP5 is working or not with Nginx, open the terminal and run these commands:

echo "<?php phpinfo(); ?>" | sudo tee /usr/share/nginx/www/test.php

sudo /etc/init.d/nginx restart

Then open this link:


- You must see a page like this if PHP5 is working:

The root directory for installing your web pages is /usr/share/nginx/www, you can access it via nautilus with root privileges as follows:

gksudo nautilus /usr/share/nginx/www

The Nginx web server is now installed. You can find the main page here:


You can also replace localhost with your own hostname or server IP.

4. phpMyAdmin Setup

To install phpMyAdmin and make it run with Nging, then follow these instructions:

Via the terminal, run this command to install phpMyAdmin:

sudo apt-get install phpmyadmin

You will be prompted to select apache2 or lighttpd, press simply the ESC button:

Select No if you get this screen (Configure database for phpmyadmin with dbconfig-common):

phpmyadmin will be installed in this directory location:


To link phpMyAdmin with Nginx, run these commands from the terminal:

cd /tmp && wget

sudo cp default /etc/nginx/sites-available/

Restart now PHP5 with this command:

sudo /etc/init.d/php5-fpm restart

phpMyAdmin will be now accessible at this link:


Use "root" without quotes as username and the password set during the installation of the MySQL server to login to phpMyAdmin.

That's it!