Comments on Installing Nginx With PHP 5.3 And PHP-FPM On Ubuntu Lucid Lynx (10.04) Without Compiling Anything

Installing Nginx With PHP 5.3 And PHP-FPM On Ubuntu Lucid Lynx (10.04) Without Compiling Anything Since Apache is most of the time a memory hungy process, people started to look for different ways to host their website. Apache is clearly not the only webserver available. A few good examples are lighttpd and nginx. In this tutorial I will show you how to install it on your Ubuntu server. This tutorial also applies to Debian, though. There is only a very small difference.

13 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: Brian Mercer

Thanks for the write up.  I went through it with a fresh system and found a couple opportunities for improvement.

First, neither nginx or php5-fpm start automatically upon installation.  Your "sudo /etc/init.d/nginx restart" covers starting nginx and "sudo /etc/init.d/php5-fpm restart" would cover starting php5-fpm if people do it, but you say it isn't necessary.

So please add

sudo service nginx restart

and

sudo service php5-fpm restart

Ubuntu is pushing us towards this way of restarting services which is compatible with the new upstart system, but is backwards compatible to the old init files.

Second, there is no need for php5-cgi or php5-cli or php5-suhosin.  You could get away with only:

sudo apt-get install php5-fpm

since that will install php5-common automatically.  Installing php5-cli may be useful, but is not required and of course php5-suhosin is a security measure and advisable, but not necessary.  php5-cgi is what we're abandoning by using fpm, so not used.

Thanks again.

By:

Made the changes you suggested. Thanks for packaging PHP-FPM!

By: Patrick

Great writeup, thanks. Couple of suggestions:

1) As noted above, a minimal Feisty server install does not include 'python-software-properties' or friends (iso-codes python-apt python-gnupginterface python-support unattended-upgrades), so there's no avoiding this. . .

sudo apt get install python-software-properties

 . . . if you want this. . .

add-apt-repository ppa:brianmercer/php

. . . to work.

2)  Many of these howtos are very unclear about what's required to for a trim php installation and all offer different package combinations. Your howto is very clear, but it might be worth highlighting these points of Brian's in the post itself:

  • php-fpm - required, php5-common automatically added by aptitude
  • php5-cgi replaced by php-fpm, so not used
  • php5-cli an optional client tool
  • php5-suhosin an optional security package
Thanks again - appreciate the post.

By: Olav Frengstad

 I started with a totaly ripped Ubuntu install and for step #2 you might need to do

sudo apt get install python-software-properties

 to be able to add custom repository.

By:

Probably only for Desktop systems I guess?

By: server0owner

No its not only on desktop versions. I got this package missing on several servers running Ubuntu Server 10.04.3 LTS. (Provider: Rapidspeeds.com)

By: Spaniard

Good article, and it works (on my ubuntu 10.04 VPS). Thanks for the "ppa:brianmercer" thing.

In near future, I would like to see an updated version of this article but using php 5.3.3 with built-in php-fpm.

PS. The 4 lines after "include fastcgi_params" are unnecessary.

By:

Since PHP 5.3.3 hasn't been packaged officially or with the built-in FPM this is kind of hard to do just yet.

 

Thanks for the comment, I've changed it.

By: yves

Thank you for the clear instructions.

Please update the site when Nginx includes a complete PHP solution (ie something more automatic).

 

Also, a small thing regarding the start-up scripts, they're both S20

S20nginx
S20php5-fpm

I wondered if php5 shouldn't be started first... I know there shouldn't much time difference, but just because accepted requests need php to be ready (like php needs mysql to be ready first).

 

By:

It doesn't really matter. This is out-of-the-box behaviour so its best to just leave it like that.


The only problem you might experience is that nginx is started before php-fpm, which means you'll get a 503 error for a few seconds while FPM starts up.

By: Jon L.

I'm curious, why do you use an upstream context to pass out to the fastcgi connection?
Passing directly to the fastcgi address works fine as well.

By: Andre

I did everything in this tutorial, still not working. I an error saying "[warn] 873#0: conflicting server name "localhost" on 0.0.0.0:80, ignored" any suggestion on what I'm doing wrong?

By: Anonymous

Hi! I found the nginx has its own php5 repository in ppa launchpad at https://launchpad.net/~nginx/+archive/php5