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

Packages:

[shell]
sudo apt-get install nginx php5-cgi
[/shell]

Extras:

[shell]
sudo apt-get install php5-gd php5-mcrypt php5-mysql
[/shell]

Files:

Append to: /etc/hosts

[shell]
127.0.1.1 phpmyadmin.local
[/shell]

/etc/init/php-fastcgi.conf

[shell]
# /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]
respawn
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
[/shell]

/etc/nginx/sites-available/phpmyadmin.local

[shell]
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;
}

}
[/shell]

Install phpmyadmin

Get latest package from: http://www.phpmyadmin.net/home_page/downloads.php

[shell]
cd /tmp
wget “http://sourceforge.net/projects/phpmyadmin/files%2FphpMyAdmin%2F3.4.5%2FphpMyAdmin-3.4.5-english.tar.bz2″
sudo mkdir /opt/phpmyadmin
cd /opt/phpmyadmin
sudo tar -xvf /tmp/phpMyAdmin-3.4.5-english.tar.bz2 –strip-components=1
sudo config.sample.inc.php sudo config.inc.php
sudo vim sudo config.inc.php # Configure for local settings
sudo chown www-data:www-data -R /opt/phpmyadmin
[/shell]

Putting it all together

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

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

WARNING:

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. Post a comment or leave a trackback: Trackback URL.

2 Comments

  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?
    PHP_FCGI_CHILDREN=5
    PHP_FCGI_MAX_REQUESTS=125

    I have looked at the upstart manual and should it not be like
    env PHP_FCGI_CHILDREN=5

    Thanks

    • 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

Post a Comment

Your email is never published nor shared. 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>