Comments on Using PHP5-FPM With Apache2 On Ubuntu 12.04 LTS

Using PHP5-FPM With Apache2 On Ubuntu 12.04 LTS This tutorial shows how you can install an Apache2 webserver on an Ubuntu 12.04 LTS server with PHP5 (through PHP-FPM) and MySQL support. PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.

12 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: Omar

Is it mandatory to complete step no. 8 or that's just an option to reduce tcp overhead?

By: admin

That step is totally optional. It is just an alternative to using TCP.

By: Ralph

Syntax error
FastCgiExternalServer: redefinition of previously defined class "/usr/lib/cgi-bin/php5-fcgi"
 
Obviously some information in the guide is misleading since you cannot redefine FastCgiExternalServer on each virtual host. This can only be defined once.

By: Donovan

Just a note that 12.04 requires you to use multiverse instead of universe.

By: Charlie

It would be very helpful if you could comment on step 8 and the TCP overhead. Are there benefits to either approach?

By: Scott Nightingale

Thank you.  Excellent tutorial.  I setup php-fcgi the hard way back in 10.04.  Following this was a breath of fresh air.  Went very smoothly, thanks for taking the time to document this.

 Cheers - Scott

By: subhojit777

Thanks for sharing. I followed every steps in this article. I am a Drupal Developer. I can access my sites from localhost.

I created a virtual host from this link http://blog.code4hire.com/2011/03/setting-up-virtual-hosts-for-apache-on-ubuntu-for-local-development/.

So everything under <IfModule mod_fastcgi.c>
 inside default sites is also copied to the virtual host settings. I was getting an error that you cannot declare FastCgiExternalServer twice. Therefore I created a blank php5-fcgi inside the docroot of my site like this:

FastCgiExternalServer /var/www/mysite/docroot/.cgi-bin/php5-fcgi -socket /tmp/php5-fpm.sock -pass-header Authorization -idle-timeout 3600
 

But it is still not working and I am getting a 403 access forbidden error.

By: Dayson

To get PhpMyAdmin working with Apache, you also need to do include the following line in /etc/apache2/apache2.conf. Include /etc/phpmyadmin/apache.conf

By: hdixon

Nice how-to. Worked perfect. Thanks much!

By: Infoget

If appears this error:

FastCGI: failed to connect to server "/usr/lib/cgi-bin/php5-fcgi": connect() failed

then check php5-fpm configuration (etc/php5/fpm/pool.d/www.conf) and comment this line:

listen = /var/php5-fpm.sock

and add/uncomment line: 

listen = 127.0.0.1:9000

 and restart:

 sudo service php5-fpm restart && sudo service apache2 restart

By: Ivan

Don't forget to add multiverse to your package sources. There is no libapache2-mod-fastcgi in standard packages in 12.04

By: Dan Jallits

The recommended setup is to build Apache with the default MPM-Prefork.

We do not recommend using a threaded MPM in production with Apache 2. Use the prefork MPM, which is the default MPM with Apache 2.0 and 2.2.

http://www.php.net/manual/en/install.unix.apache2.php

PHP is glue. It is the glue used to build cool web applications by sticking dozens of 3rd-party libraries together and making it all appear as one coherent entity through an intuitive and easy to learn language interface. The flexibility and power of PHP relies on the stability and robustness of the underlying platform. It needs a working OS, a working web server and working 3rd-party libraries to glue together. When any of these stop working PHP needs ways to identify the problems and fix them quickly. When you make the underlying framework more complex by not having completely separate execution threads, completely separate memory segments and a strong sandbox for each request to play in, further weaknesses are introduced into PHP's system.

If you want to use a threaded MPM, look at a FastCGI configuration where PHP is running in its own memory space.  

http://www.php.net/manual/en/faq.installation.php#faq.installation.apache2

PHP recommends using FastCGI which is what we are doing by implementing PHP-FPM.