Tuesday, 28 May 2013


Nginx is an open source powerful HTTP server, installation of nginx is very simple and easy. First of all we have to add repositories in sources.list file. You can use the command "vim /etc/apt/sources.list". Repositories for Ubuntu and Debian are listed below.
Ubuntu 10.04:
deb http://nginx.org/packages/ubuntu/ lucid nginx
      deb-src http://nginx.org/packages/ubuntu/ lucid nginx
Debian 6:
deb http://nginx.org/packages/debian/ squeeze nginx
      deb-src http://nginx.org/packages/debian/ squeeze nginx

After adding repositories to sources.list now run this command to install nginx on your system:
 
 # apt-get install nginx

you can check the installation by running nginx:
 
You can also verify whether it is listening on HTTP Port i.e 80 or not by using netstat.
# netstat -nlp | grep 80
Now its the time to add PHP support for nginx. Now add repositories for installation of PHP in sources.list using vim.
 deb http://packages.dotdeb.org stable all
 deb-src http://packages.dotdeb.org stable all

Now do apt-get update, and get the authentic GnuPG key for the repositories:
         # sudo apt-get update
         # wget http://www.dotdeb.org/dotdeb.gpg
         # cat dotdeb.gpg | sudo apt-key add -
Now install PHP by using apt-get
# sudo apt-get install php5-cli php5-fpm php5-cgi
spawn-fcgi will be used to add php support for nginx
# sudo apt-get install spawn-fcgi
After installation now we will configure default file of nginx to make it run with php script. The path of that file is /etc/nginx/sites-available/default.
# vim /etc/nginx/sites-available/default
server { listen 80; #root /var/www; #index index.html index.htm; server_name localhost; access_log /var/log/nginx/localhost.access.log; ## Default location location / { root /var/www; index index.php; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name; }
}
After setting the default file, path for your web pages will be /var/www/ you have to place all the pages here on this path to make them live over the internet.
Now you can make php pages and can make them live by using nginx.

No comments:

Post a Comment