My first Nginx + php-fpm + percona stab at getting it set up on ubuntu 10.04

gateway69's picture

I wanted to start this thread to give anyone wanting to quickly get up and running to play around with nginx and such.. below is my first stab at sorta a howto, I used some info from other sites and next step is getting all the drupal things working like I want clean urls, imagecache, upload progress.

Note, this setup is very new to me coming from LAMP so please if you use these instructions use them only for testing out this setup.

Edited: Jan 25, 2012

My Current DB Choice, Percona

No reason im going with this, please insert your favorite flavor of db server

Install Options

gpg --keyserver  hkp:// --recv-keys 1C4CBDCDCD2EFD2A

Note this can take a while so dont cancel it..

gpg -a --export CD2EFD2A | sudo apt-key add -

Add these to your /etc/apt/sources.list depending on ubuntu dist name

make sure to change lenny to the ubuntu distro your using..
For 10.04 its lucid

so it should look like

Then run

apt-get update

If all goes well you can run this to install percona

sudo apt-get install percona-server-server-5.5


Here is a list of the basic install via apt

I have decided to use Brian Mercer's version for now
until I feel comrtable enough of compiling with source, I if
I need the bleeding edge version. for more info

This also includes extra modules such as upload progress etc..

add-apt-repository ppa:brianmercer/nginx
apt-get update
apt-get install nginx-custom

btw if you get add-apt-repository not found run this first

sudo apt-get install python-software-properties

btw you might not need the nginx-custom please use the link above
to decided which one to use.

current avail version as of this writing is

nginx -v
nginx: nginx version: nginx/1.0.9

to see what modules are compiled in use this command nginx -V


Next PHP-FPM a more updated version of the old spawn-fastcgi

Some Commands taking from

The change made was to swap

sudo add-apt-repository ppa:brianmercer/php


sudo add-apt-repository ppa:nginx/php5

sudo aptitude install python-software-properties
sudo add-apt-repository ppa:nginx/php5
sudo aptitude update

Then installing the php5 and php5-fpm

sudo aptitude install php5-cli php5-common php5-mysql php5-suhosin php5-gd php5-dev
sudo aptitude install php5-fpm php5-cgi php-pear php5-memcache php-apc
/etc/init.d/php5-fpm restart

You might see this warning [TODO: find reason and fix]

[WARNING] [pool www] pm.start_servers is not set

Also typing php5-fpm to see the version seems to spit out some errors it cant find config files?

Jan 25 11:12:47.359277 [ERROR] Unable to open file '/etc/php-fpm.conf', errno=2
Jan 25 11:12:47.359346 [ERROR] failed to load configuration file '/etc/php-fpm.conf'

Nginx Config Files

For my first test im going to use the included /etc/nginx/sites-avaiable/default
and make a copy of it lets say

I made only some minor changes to this config to start off to make sure everything would run.

My changes to the file

changed root to point to my actual web folder

root /var/www/;

added index.php to the line below that.

index index.php index.html index.htm;

The only other change is down in this section

pass the PHP scripts to FastCGI server listening on

I uncommeted the lines to make sure php would be working with this config.

        location ~ .php$ {
                fastcgi_index index.php;
                include fastcgi_params;

Then I created a sym link from of my new congif.. an example

ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

with being my config,

then I created my /var/www/ folder

Btw what permissions should be used here, im used to the old method of username:www-data but under nginx I have no idea
what to do about users, permissions.. any thoughts.

I did finally change the permissions on the folder like this

chown -R user:www-data

with user being the user who you want to have access in my case this was a plane ubuntu server install so the user
was root (not sure if this is a good idea)

anyhow after creating a index.php file in my new dir with this in it


and then pointing my browser to my ip I was greated by he familure php info page!

Yay.. well ok sure wasnt to hard, now the hard part of working though all the things that you need
to get up and running for drupal/pressflow and what sort of options for cache (varnish, memcached, nginx cache) and
then looking at a op code accelerator like apc..

anyhow I think my first test will be to make sure I can install drupal , get clean urls working and upload progress. I also
hear their is some issues with imagecache and big security holes for allowing someone to upload file like an image but disgued as
some php code to run on your server.

Installing Pressflow

I grabbed pressflow from git..

git clone /var/www/

if you dont have git installed you can do

apt-get install git-core

I created a new database via mysql, hopefully you know how to do that..

[Question] btw anyone know if phpmyadmin works with nginx-php-fpm-percona?

Issues so far with basic nginx.conf and virtual hosts..

Done: -- No clean urls
-- cant send email when setting up the system..
Done: -- No upload progress

Here is a screenshot from my admin/reports/status


Research all the configs from the two links below and try to learn..

Or all the hard work Perusio put into the config hes offering up

Granted this seems like quite a bit more work to get running, I'm not exactly sure
under the install section of the readme which php handler set up I should set up and
what files i need to edit based upon the current above setup.

Cheers.. hope this helps some people get started.
with your config after you get up and running...


Don't use

perusio's picture

that config. It's broken. Folks here will be glad to help you out get a decent one.

Please don't use my old

brianmercer's picture

Please don't use my old php-fpm ppa. i.e. sudo add-apt-repository ppa:brianmercer/php

I made that when 10.04 first came out. Once 10.10 came out with an official php-fpm that could be nicely backported to 10.04 there was no reason to use mine anymore. see

I recommend: sudo add-apt-repository ppa:nginx/php5


ahh ok thanks, hmm how do i

gateway69's picture

ahh ok thanks, hmm how do i remove your add-apt-repository ppa:brianmercer/php

Brian, are you saying I should just install use the ubuntu 10.04 lucid sources to install php+php-fpm ?

You can't use the 10.04

brianmercer's picture

You can't use the 10.04 version of php5 because it didn't include php-fpm. Which is why I had to make my own package.

First copy the config directory to be safe:

sudo cp -pr /etc/php5 /var/tmp


sudo add-apt-repository ppa:nginx/php5
sudo aptitude update
sudo aptitude full-upgrade

and that will upgrade you to a nice new version of php5 that has php-fpm.

You'll have to check your config files, because the config files changed some. You may want to install the package-maintainers version when it asks and then put in any changes again.

In my package the configuration file was all in /etc/php5/fpm/php5-fpm.conf. Then when they added fpm in 10.10 it was /etc/php5/fpm/main.conf and /etc/php5/fpm/pools.d/www.conf. I think in 11.10 they switched it to /etc/php5/fpm/php-fpm.conf and /etc/php5/fpm/pools.d/www.conf.

After you're upgraded you remove my repo by removing the proper files in /etc/apt/sources.d

thanks yea I was in the

gateway69's picture

thanks yea I was in the middle of trying to edit my comment before u posted..

im now running this Im now running 5.3.5-1ubuntu7.2ppa1~lucid I hope thats the right one this time...

so is it still good do use your ppa:brianmercer/nginx seems like some if not all the modules I need..


brianmercer's picture

Yes, the nginx repo is fine.

nm. They're trying to upgrade that repo to 5.3.8 today.

thanks guys of course again..

gateway69's picture

thanks guys of course again.. just trying to get things sorted, maybe build a drupal wiki here for all of this, I do what many others due and try to find a decent guide to get up and running with drupal, I do not mind taking the time to try all of this stuff out and hopefully get something together that everyone can use as a base.

Percona Server

grape's picture

I'm not saying anything bad about percona-server-5.5, but you may be happier with percona-server-5.1 as it is very well tested and has a good track record on Ubuntu Lucid. I use both, but deploy 5.1 for clients needing a stand-alone MySQL server because I don't like trouble.

yet another day of nginx.. im

gateway69's picture

yet another day of nginx.. im going to be taking the feedback that im getting and building a new vps box today what Im mainly going to do would be the following.

Same percona unless someone can point me to that its much buggier, slower, and has less bug fixes in it :)

php-fpm version found here
add-apt-repository ppa:nginx/php5

ppa:brianmercer/nginx with apt-get install nginx-custom for upload and cache-purge

ngix configs from (prob start here)

Then dig into the more advanced one that

Seems quite complicated but provides a lot of options from caching and performance options..

mean while hopefully learn a bit more today about this type of setup..

anything im missing?

Nice to see

perusio's picture

your progress and determination to get things done. I have one question: why did you rule out MariaDB? I've been using the 5.2 version since the beta release with no issues whatsoever. For it seems that they're much more ambitious than Percona. They're really motivated to provide an alternative to the Oracle MySQL. AFAIK runs on MariaDB.

It was recommend by Acquia

gateway69's picture

It was recommend by Acquia they seemed to have switched, I'm not married to anyone, i just want something better than the standard mysql that allows me to scale.. Im not opposed to MariaDB just using Percona first.. ..

Btw updated the howto, I have some questions still pending...

Acquia is not using percona.

Fidelix's picture

Acquia is not using percona.

not yet.. stay tuned..

gateway69's picture

not yet.. stay tuned..

I don't see a reason why. I

Fidelix's picture

I don't see a reason why.
I understand most of the differences between Percona and MariaDB, and I don't see anything replacing it (MariaDB) anytime soon... In both functionality and philosophy.

Fidelix, im not here to make

gateway69's picture

Fidelix, im not here to make anyone choose one db over the other, I personally am going to use percona right now with my test, this post is purely about getting up and running drupal with nginx and hopefully creating a howto for people that have the same interest as mine, I personally dont care who is using what but I will spend personal time looking at both options but will keep my thoughts and opinions out of this post..

So I have everything running

gateway69's picture

So I have everything running with a minor issue :)

I ended up using this vhost config file

beware this changes where required and ill post them to the wiki when I figure out my last issue, well is it ever the last issue? :)

so if you follow this guide and use the above config you will have to make some changes to your php-fpm config files because
it uses fastcgi_pass as a temp sock instead of ports, their claim is its faster and more secure, who am i to argue.

But what you will need to do is edit your www.conf file in this dir


make the change of

listen =


listen = /tmp/phpfpm.sock

you will need to restart php-fpm and prob nginx..

but I have this weird problem going to some URL's on drupal posts a white page and says "Welcome to Nginx"

for example

admin/reports/status this page shows a white page with welcome to nginx! is this some sort of cruel funny haha joke :)

anyone know what this is about?

never mind, found the issue,

gateway69's picture

never mind, found the issue, some how nginx didn't restart properly.. so doing this helped,

service nginx stop; killall nginx; service nginx start

error all gone :)

So im up for suggestions now on caching with nginx and pointers on what directions to go, I think apc is installed for php op code cache, but what about memcache, boost or what have you.. microcaching?

This is just speculative to say the least

perusio's picture

up until 5.3.8 php-fpm with UNIX sockets just colapsed under high-loads. There's no need to restart Nginx. The only reason for that is when you want to bind some sockets on a new port and release the previous. Sending a SIGHUP (reload) makes it parse the config files. Changing the type of socket of the FCGI upstream is a config change. Not a fd "re-binding". See:

Thanks for the feedback, Ill

gateway69's picture

Thanks for the feedback, Ill keep it as it is for now..

A few questions if you have a min.

If you where to take what I have done and expand it into setting up some caching which direction would you look at first?

Can I have several php-fpm worker bee's servers that the box running Nginx can connect to and use.. (out of the scope of this topic but thinking of how things should scale)


perusio's picture

is the way to go IMHO. No fishy third party modules like the purge module for Nginx. No messing around with expiration logic. I'm working on a crawler to keep the cache warm. Microcaching is the only strategy that scales with the load. Furthermore is very fast and simple. I'll publish the new project tomorrow with proper instructions.

I'm focusing on this solution as the only caching layer besides APC. Stay tuned.

Nice, deff intrested, im

gateway69's picture

Nice, deff intrested, im doing some bench marking on 2 virtual hosts one running LEMP and one running LAMP and doing some tests with ab im a bit confused right now as to why nginx rps are lower than the apache2 one.. anyhow.. another mystery to solve..

and guys whats with the -1 voting for people willing to help out?

Are you benchmarking static

wipeout_dude's picture

Are you benchmarking static contents (.html, .js, .gif, .jpg etc..) or php?

If its php then there could be lots of factors..
Are you running mod_php on the Apache server? If you are this will most likely be faster than php-fpm..
Have you got enough spare threads waiting in the pool for the concurrent requests you are firing at the server?

Nginx is VERY fast at serving static content.. I found similar php performance for Apache (php-fcgid) and nginx (php-fpm).. Since webpages are generally made up of php and various bits of static content nginx delivers the pages quicker..

The big saving from the nginx camp is memory.. Run your benchmarks and monitor memory usage, especially at higher request concurrency.. Nginx "should" be much lower..

Also, if your physical server your virtual hosts are running on is not dedicated to you then take benchmarks with a pince of salt.. You have no idea what other virtual servers are doing and what loads they are putting on the host server.. This could affect your results..

When you are done it would be interesting to see your comparative results between nginx and apache as well as how performance improved as you optimised settings..

wipeout_dude, I moved my post

gateway69's picture


I moved my post to here I dont want to clutter this post ..

but my first test was just using a pure ab to the localhost of 2 images, these are on my test vmware box and I didnt run them at the same time nor was anything else running to avoid some crazy stuff.. next I need to maybe start looking at dstat, jmeter..

Regarding caching beside APC

VisualFox's picture

Regarding caching beside APC I am using the boost module - - works well with nginx

Philippe Blanc

President and founder of VisualFox LLc
Founder of OYOAHA which helped to organize the first Drupal Con in Portland
President and founder of the short lived Blacktonic A

Hi gateway69, I don't intend

VisualFox's picture

Hi gateway69,

I don't intend to hijack this thread but I developed a working set of recipes for building a nginx/drupal/mysql stack so you may be interrested to take a look to it:

This stack use Monit to monitor the server

I also developed some perl script to manage this stack:

these scripts have a lot of shortcoming so be sure to understand what they are doing before using them. These scripts let you create new domain name - ala plesk - and let you install drupal in an automatic way (generating the db and basic backup for it)

Philippe Blanc

President and founder of VisualFox LLc
Founder of OYOAHA which helped to organize the first Drupal Con in Portland
President and founder of the short lived Blacktonic A

Amazon EC2

VisualFox's picture

If some people are interested I may create an AMI for it.

Philippe Blanc

President and founder of VisualFox LLc
Founder of OYOAHA which helped to organize the first Drupal Con in Portland
President and founder of the short lived Blacktonic A

thanks I took a look at them

gateway69's picture

thanks I took a look at them last night on my ipad, well just went though your scripts, nice work! Are you planning on updating any of these to maybe use the latest ngnix, php-fpm etc..

Thank you! I believe I

VisualFox's picture

Thank you!

I believe I already use the latest of ngnix and php-fpm at last the latest available for ubuntu 10.04 LTS. But yes I intent to continue to update these recipes and maybe provide a new set for the up coming ubuntu 12.04. Generally I update the recipes every time I deploy a new server. The s66c script need a little more work and there are some dead code I need to remove (originally s66c was tweeting about it's own activity but unfortunately this need to be removed)

feel free to fork the project if you want to customize it for your own need.

I think I one point I should also make a formal announcement about it. I mean one of the reason I when to github was to make sure other people can contribute to the project...

Philippe Blanc

President and founder of VisualFox LLc
Founder of OYOAHA which helped to organize the first Drupal Con in Portland
President and founder of the short lived Blacktonic A

Im a firm believer in sharing

gateway69's picture

Im a firm believer in sharing your work and providing solutions or other options for a community.. I might take u up on that fork, but I need to really focus on getting my first nginx server tuned to the what I need want. Cache is still a bit of a mystery for me, if i should use nginx static file caching, boost, memcache all of the above

cheers and thanks for the contributions.

You are very welcome to do

VisualFox's picture

You are very welcome to do that!

I finally went ahead and make a formal announcement both on nginx and node.js drupal's group.
For the cache, because I deal mostly with anonymous visit, Boost (which is static file caching) and APC did the trick to me. Moving some of the content to Amazon S3 and use Amazon CloudFront do wonder too. There are also this nice module: who put everything in the "cloud" and then again you can use CloudFront for uber fast delivery...

hope that help

Philippe Blanc

President and founder of VisualFox LLc
Founder of OYOAHA which helped to organize the first Drupal Con in Portland
President and founder of the short lived Blacktonic A

I'm wondering to know if its

yvmarques's picture

I'm wondering to know if its normal that you've some password and access keys in your files ?

nope! I may have committed

VisualFox's picture

nope! I may have committed something by mistake. Thank you for the feedback. I am investigating that now.

[EDIT] My mistake. Should never have been added to the respo. If that happen to someone else: Thanks again to report that.

Philippe Blanc

President and founder of VisualFox LLc
Founder of OYOAHA which helped to organize the first Drupal Con in Portland
President and founder of the short lived Blacktonic A


perusio's picture

use phpmyadmin it's a just a vulnerability trap: Use chive if you want a web based MySQL interface.

oh wow thats a great find, I

gateway69's picture

oh wow thats a great find, I have to say I never heard about this before.

Don't mind the

perusio's picture

noise there are plenty of armchair judges that instead of putting some time to help out someone just like to down vote someone they disagree with. It gives them the illusion of being powerful while really being mereley pathetic. Any voting system can be gamed.

Ignore them and proceed. It's part of the mask effect of the background noise.

Hmm tried out chive today,

gateway69's picture

Hmm tried out chive today, untared the archive into my drupal root and made a test folder, when I went to the index and logged in It would just sit their and eventually I would get an ajax time out and no db's or anything where loaded, do I have to tweak the vhost config for this to work properly? any pointers?

You can try

perusio's picture

my config. The only that you have to configure is the credentials for acessing the MySQL DBs. There's no other thing to configure on the application AFAIK.

the prob is im already

gateway69's picture

the prob is im already running a drupal conf for ngix.. any way they can live together or what I could config in the drupal one im using to make sure this works..


perusio's picture

problem are you referring to? Nginx supports vhosts. Also you could run Chive in a specific subdir. Let's call it private:

location ^~ /private/chive/ {
        ## Access is restricted.
        auth_basic "Restricted Access"; # auth realm
        auth_basic_user_file .htpasswd-users; # htpasswd file

        ## Use PATH_INFO for translating the requests to the
        ## FastCGI. This config follows Igor's suggestion here:
        ## This is preferable to using:
        ## fastcgi_split_path_info ^(.+.php)(.)$
        ## It saves one regex in the location. Hence it's faster.
        location ~ ^(?<script>.+.php)(?<path_info>.
)$ {
            include fastcgi.conf;
            ## The fastcgi_params must be redefined from the ones
            ## given in fastcgi.conf. No longer standard names
            ## but arbitrary: named patterns in regex.
            fastcgi_param SCRIPT_FILENAME $document_root$script;
            fastcgi_param SCRIPT_NAME $script;
            fastcgi_param PATH_INFO $path_info;
            ## Passing the request upstream to the FastCGI
            ## listener.
            fastcgi_pass phpcgi;

        ## Protect these locations. Replicating the .htaccess
        ## rules throughout the chive distro.
        location /private/chive/protected {

        location /private/chive/yii {

        ## Static file handling.
        location ~* /private/.+.(?:css|gif|htc|js|jpe?g|png|swf)$ {
            expires max;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
            ## Set the OS file cache.
            open_file_cache max=100 inactive=120s;
            open_file_cache_valid 45s;
            open_file_cache_min_uses 2;
            open_file_cache_errors off;

Install Chive under /path/to/drupal_root/private/chive. You're done.

Hey guys im going though my

gateway69's picture

Hey guys im going though my post above on setting up ngnix with specific modules for drupal, and php-fpm but im having a hard time finding any updated versions I could easily install with out compiling from source on ubuntu.

Any good ppa to use now, also should i just be compiling nginx from source and just compile the plugins.. whats your guys process for keeping up to date on stuff such as nginx and php

Unfortunately, the

brianmercer's picture

Unfortunately, the guys stopped publishing their php5 repo last week.

I made a new one for now: The precise package is different enough that it needed a later version of dpkg to install on lucid, so I saw that, who is an official debian maintainer, created a helper package. I copied his helper package and the lucid one is working for now.

However, I just saw that Ondrej Sury has now gone a different way, deleted the helper package, and is backporting the dpkg package itself to lucid...I'm not sure if I'll just leave mine as is, or do the same.

BTW, Ondrej's ppas are php5.4 which are not well tested with Drupal and if you try to use 5.4 on Lucid you'll find that any php modules in the Lucid repo which are not compiled with the php5 package will not install. That would include things like php-apc. So some php modules would need to be recompiled as well.

I'm planning to upgrade my machines to precise so I won't guarantee to keep that ppa for more than a couple months. Sorry I can't provide a long-term solution for you.

thanks for all your help, i

gateway69's picture

thanks for all your help, i keep wanting to push for nginx and php-fpm here at work but its so much easier to set up lamp.. anyhow.. thats besides the point.. ill keep plugging away.. esp with lucid

hmm, did i miss a step.. The

gateway69's picture

hmm, did i miss a step..

The following packages have been kept back:
linux-generic linux-image-generic php-pear php5-cgi php5-cli php5-common php5-dev php5-fpm php5-gd php5-mysql python-software-properties
0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.

That message is not

brianmercer's picture

That message is not descriptive enough. What do you get from
aptitude update
aptitude upgrade

I think he means that the

VisualFox's picture

I think he means that the previous version of php-fpm installed from some other ppa (nginx/php5 or nignx/php5.3) are not being replaced by the version of your ppa.

Philippe Blanc

President and founder of VisualFox LLc
Founder of OYOAHA which helped to organize the first Drupal Con in Portland
President and founder of the short lived Blacktonic A

correct, i had the

gateway69's picture

correct, i had the nginx/php-fpm stuff installed, remove that ppa added yours, did a update..

Yes, I was hoping that doing

brianmercer's picture

Yes, I was hoping that doing update and upgrade would provide more descriptive information about why they are not upgrading.

The other packages: linux-generic linux-image-generic php-pear python-software-properties, should have nothing to do with my repo. You might try to upgrade those first and get them out of the way.

I have gotten that message you stated where I've run the upgrade procedure without marking any packages for upgrade. Let me know if you get a different message from those two aptitude commands.

For nginx modules I suggest

brianmercer's picture

For nginx modules I suggest editing and recompiling a debian package rather than compiling from source. It's just easier since you don't have to redo all the distro-specific stuff like init scripts and configuration file locations.

Remember we are a little more

wipeout_dude's picture

Remember we are a little more than a month away from Ubuntu 12.04 LTS which includes php-fpm and nginx which will make it much easier to get a standard install running..

Do you have more information

VisualFox's picture

Do you have more information about these package? What version of php will be supported? 5.3 or the new 5.4? I am little nervous to run a production site on 5.4... with so little testing...

Philippe Blanc

President and founder of VisualFox LLc
Founder of OYOAHA which helped to organize the first Drupal Con in Portland
President and founder of the short lived Blacktonic A

PHP is 5.3 - FPM details here

wipeout_dude's picture

PHP is 5.3 - FPM details here

nginx is 1.1.14 - Details here

Awesome! Thank you so much!

VisualFox's picture

Awesome! Thank you so much!

Philippe Blanc

President and founder of VisualFox LLc
Founder of OYOAHA which helped to organize the first Drupal Con in Portland
President and founder of the short lived Blacktonic A

I'm surprised that they are

brianmercer's picture

I'm surprised that they are putting the dev branch of nginx in precise. An LTS release!

Somewhere I read (I think on

wipeout_dude's picture

Somewhere I read (I think on the nginx site or wiki somewhere) that the dev branch is the recommended one to use.. I guess the ubuntu devs agree.. :)

Well I guess it's different

brianmercer's picture

Well I guess it's different for a distro. I would not upgrade to the latest dev release because system breaking bugs/changes are introduced and are not discovered until a critical mass of systems are using the release. It's happened at least twice in the last few months that I've seen on the mailing list.

But if Ubuntu wants to install 1.14 that is months old and then backport all the security and bug fixes from 1.15 on, I suppose they can do that fairly safely.

Im grabbing the latest 12.04

gateway69's picture

Im grabbing the latest 12.04 and going to install it on vmware image to test it out.. cheers..