Setup notes [ubuntu]: nginx + upstart php-cgi

Quick setup guide for serving php pages with nginx on Ubuntu

Goal: serve phpmyadmin from the local machine from /opt/phpmyadmin answering to the domain http://phpmyadmin.local/

Used in this guide:

  • Ubuntu 11.04
  • nginx 0.8.54
  • php5-cgi 5.3.5
  • phpmyadmin 3.4.5


sudo apt-get install nginx php5-cgi


sudo apt-get install php5-gd php5-mcrypt php5-mysql


Append to: /etc/hosts

[shell] phpmyadmin.local


# /etc/init/php-fastcgi.conf
# php-fastcgi – starts php-cgi as an external FASTCGI process

description “php-fastcgi – keep up php-fastcgi”

start on runlevel [2345]
stop on runlevel [!2345]
exec /usr/bin/sudo -u www-data PHP_FCGI_CHILDREN=5 PHP_FCGI_MAX_REQUESTS=125 /usr/bin/php-cgi -q -b /tmp/php-fastcgi.socket


server {
listen 80;
server_name phpmyadmin.local;

root /opt/phpmyadmin;
index index.php;

location ~ .php$ {
fastcgi_pass unix:/tmp/php-fastcgi.socket;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;


Install phpmyadmin

Get latest package from:

cd /tmp
wget “”
sudo mkdir /opt/phpmyadmin
cd /opt/phpmyadmin
sudo tar -xvf /tmp/phpMyAdmin-3.4.5-english.tar.bz2 –strip-components=1
sudo sudo
sudo vim sudo # Configure for local settings
sudo chown www-data:www-data -R /opt/phpmyadmin

Putting it all together

sudo service php-fastcgi start
sudo ln -s /etc/nginx/sites-available/phpmyadmin /etc/nginx/sites-enabled/phpmyadmin
sudo service nginx restart

You should now be able to navigate to http://phpmyadmin.local/ to configure and access phpmyadmin


I have not proof tested these notes yet. I will remove this warning when tested.

This entry was posted in Coding and tagged , , , , . Bookmark the permalink. Both comments and trackbacks are currently closed.


  1. December 26, 2011 2:54 am

    I have a question. How do you know that following variables will be passed to php-cgi process?

    I have looked at the upstart manual and should it not be like


    • December 31, 2011 2:54 pm

      Upstart supports both ways. By setting the environment variables using the env command they will be applied before any command is run. So it saves you setting the variables multiple times if you have multiple commands.
      But as we only have one command and we have placed the vars on the right hand side of sudo, they are in the most appropriate place.

One Trackback