nginx ubuntu

how to install nginx server in ubuntu

How to Install nginx server in ubuntu ? it  is really simple to do following steps will guide you the whole process in the end you will running nginx server.This tutorials are tested on Digital Oceans VPS  10$pm (recommended) but it will work on all . Learning practically is the best learning method i have ever encountered, so in my advice kindly do the tutorials as you read it this while help to understand easily.

Tools Needed

Putty (What is Putty more Info)

A VPS Subscription


Note : Follow me exactly better if you copy codes to avoid errors 

1) I am assuming you have logged in using putty to VPs account

2) To Update the system type 

sudo apt-get update

3) Good you have updated you system this will download all the installed applications latest version

4) Now you have to install MySQL free data management tools for managing database

To install MySQL  type in putty terminal 

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

it will ask for password enter accordingly



Now to invoke MySQL enter the following command

sudo mysql_install_db
followed by 
sudo /usr/bin/mysql_secure_installation

It will ask for password enter which you had entered while installation.



Enter the root password

Now the terminal will ask if you want to change the root password , after this there are series of questions asked select yes for all



Congratulation you have installed MySQL

5) Lets Install Nginx  copy pate the following commands  in you terminal.

sudo apt-get install nginx
start it 
sudo service nginx start

To get your IP address for VPS  type this 

ifconfig eth0 | grep inet | awk '{ print $2 }'

Good work now check your IP in your browser It should display ” Welcome to nginx!”



You successful installed Nginx

6) Now Lets Install PHP copy pate the following commands  in you terminal.

sudo apt-get install php5-fpm

Configure PHP-FPM

Open php.ini file with this command 

sudo nano /etc/php5/fpm/php.ini

find this line  with search press Ctrl(Left)+W 

just replace 1 with 0



Save the change Ctrl(Left)+O then Enter

Open php5-fpm file with this command 

sudo nano /etc/php5/fpm/pool.d/www.conf

Search this line 

 listen =
replace it with 
listen = /var/run/php5-fpm.sock


Save the change Ctrl(Left)+O then Enter

Restart PHP 

sudo service php5-fpm restart

7) Configure nginx(

Open nginx config file with this command  

sudo nano /etc/nginx/sites-available/default
  It will look like this
server {
        #listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6

        root /usr/share/nginx/www;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules

delete till only the above codes  only  and copy exact code below 

server {
        listen   80;

        root /usr/share/nginx/www;
        index index.php index.html index.htm;


        location / {
                try_files $uri $uri/ /index.html;

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;

        # pass the PHP scripts to FastCGI server listening on
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;


Change in new code ( Just for information DON’T CHANGE AS THE WORKING FORMAT IS ALREADY GIVEN TO PASTE)

Add index.php  its should like index.php  index. html  index.htm

Replace the to your IP or Domain 

Replace  location ~ \.php$ {   to  “location ~ \.php$ {“ section

Save the change Ctrl(Left)+O then Enter

8) Make a PHP Info page

Type the following command to create  page

sudo nano /usr/share/nginx/www/info.php

add code to print info  


Save the change Ctrl(Left)+O then Enter

restart your server 

sudo service nginx restart

Type your IP or domain it should display like this image

nignx phpinfo

nignx phpinfo

Congraulations you will have a working VPS

This is referral link for Digital Ocean      Source: Digital Ocean


  • xami February 4, 2014 Reply

    not working showing error

    sudo service nginx start
    Starting nginx: nginx: [emerg] bind() to failed (98: Address already in use)
    nginx: [emerg] bind() to failed (98: Address already in use)
    nginx: [emerg] bind() to failed (98: Address already in use)
    nginx: [emerg] bind() to failed (98: Address already in use)
    nginx: [emerg] bind() to failed (98: Address already in use)
    nginx: [emerg] still could not bind()

    • Nishil Prasad April 6, 2014 Reply

      Hi Xami sorry for replying late, Can you address the last step you have taken

I am Here to Assist You