Installing Nginx, PHP and spawn-fcgi on Ubuntu 10.04 (Lucid) using apt-get

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 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 --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 “No usable dialog-like program is installed” and you care, install dialog.

root@zero:/# apt-get install dialog 

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 dialog

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

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 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/

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.22_1171]
Rating: 5.0/5 (4 votes cast)
Installing Nginx, PHP and spawn-fcgi on Ubuntu 10.04 (Lucid) using apt-get, 5.0 out of 5 based on 4 ratings

One Response to Installing Nginx, PHP and spawn-fcgi on Ubuntu 10.04 (Lucid) using apt-get

  1. After installing php5-gd and rtenarsitg Apache2, I still got the same error messages. Looking thru the error logs I noticed: failed to open stream: Permission denied in /var/www/wp-admin/includes/file.php on line 348 . Line 347-8 has: $new_file = $uploads['path'] . /$filename copy( $tmp_file, $new_file );Ahh, more file permissions, this time on the uploads dir. Once I gave the Apache process recursive write perms to wp-content/uploads and restarted, all was good.Thanks for the tips!

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>