Nginx (pronounced “engine x”) is a free, open-source, high-performance HTTP server known for its stability, rich feature set, simple configuration, and low resource consumption.
This tutorial shows how to install Nginx on an Ubuntu 10.04 server with PHP5 support (through spawn-fcgi) and MySQL support using apt-get.
Thanks to
@dfrg_msc and
@nileshgr, it’s been brought to my attention that as of November 29, 2011, PHP-FPM became a part of PHP-5.4 and is also available in 5.3.3. The bad news would be that PHP-FPM is not in the Ubuntu repositories (atleast, not for 10.04 and lower since it uses 5.3.2). Luckily, there is a debian/ubuntu repository which does it all for you. I will create a new how-to and link to if from here.
Ubuntu PPA
This PPA is maintained by volunteers and is not distributed by nginx.org. There are some extra compiled-in modules.
You can get the latest stable version of Nginx from the Nginx PPA on Launchpad.
You will need to have root privileges to perform the following commands.
root@zero:/# sudo -s
root@zero:/# nginx=stable # use nginx=development for latest development version
root@zero:/# add-apt-repository ppa:nginx/$nginx
root@zero:/# apt-get update
root@zero:/# apt-get install nginx
If you get GPG errors with keys you can run:
root@zero:/# gpg --keyserver keyserver.ubuntu.com --recv 10101010
root@zero:/# gpg --export --armor 10101010| sudo apt-key add -
Where “10101010″ is the last 8 symbols of the key giving you problems. You can repeat this for all problematic keys.
If you get an error similar to “bash: add-apt-repository: command not found” install python-software-properties.
root@zero:/# apt-get install python-software-properties
Start Nginx
root@zero:/# /etc/init.d/nginx start
At this point you should be able to access your servers public IP address and see the default “Welcome to Nginx” (or in my case a 404 page) screen.

Nginx default 404 page
To make nginx start at boot time, run
root@zero:/# update-rc.d nginx defaults
Install MySQL
root@zero:/# apt-get install mysql-server mysql-client
If like me, you use a separate MySQL server, you don’t need to install mysql-server. If you install mysql-server, you will be asked for a “root” password for MySQL. Make it secure and write it down for later usage.
Install PHP (you may not need everything I have listed or may need more)
root@zero:/# apt-get install php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
Then open /etc/php5/cgi/php.ini and add the line cgi.fix_pathinfo = 1 right at the end of the file:
root@zero:/# nano -w /etc/php5/cgi/php.ini
Install spawn-fcgi
root@zero:/# apt-get install spawn-fcgi
To start a PHP spawn-fcgi daemon on localhost port 9000 and running as the user and group www-data – run the following command:
root@zero:/# /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
I suggest adding the above to your /etc/rc.local file to prevent the need to rerun the command every time you reboot your server.
root@zero:/# nano -w /etc/rc.local
Put it right above the “exit 0″ line.
(still typing rest of tutorial)
VN:F [1.9.16_1159]
Rating: 10.0/10 (3 votes cast)
VN:F [1.9.16_1159]
Rating: +4 (from 4 votes)