14

I'm trying to figure out what which is the best Apache MPM I can install on my VPS. I saw some benchmarks and MPM Worker seems to perform better than the Prefork one but for some reason everyone seems to be recommending Prefork over Worker for PHP setups.

Is this just because some PHP functions are not thread-safe? Only setlocale() comes to mind, but I'll be using the same locale on every instance so I don't think that will be a problem. My VPS has little memory and I feel that the worker MPM would be a better match for my needs, however I'm not sure.

Can someone help me make up my mind about this? Thanks!


PS: I've also looked into nginx and lighttpd. nginx seems awesome but I'm trying to avoid compiling from source and I still don't quite understand what php-fpm is for. Regarding lighttpd - it was incredible easy to setup PHP/FCGI with it, but I heard that it has memory leaks. Is this still true?

Alix Axel
  • 2,653
  • 6
  • 28
  • 28
  • 2
    The problem is that while the core PHP is now supposed to be thread safe, when it comes to extensions, all bets are off. – mattdm Feb 05 '11 at 18:53

1 Answers1

14

You should use prefork when using apache + mod_php. The FAQ clearly outlines the reason why:

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

Why shouldn't I use Apache2 with a threaded MPM in a production environment?

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.

nginx + php-fpm is also an excellent way to run php applications. nginx has native support for FastCGI and php-fpm is one of the best ways to run php in a FastCGI environment. See the php documentation here:

http://www.php.net/manual/en/install.fpm.php

dialt0ne
  • 3,027
  • 17
  • 27
  • Regarding Apache MPMs I think I got it, prefork is the way to go. I'm inclined to a nginx or lighttpd setup due the the high memory consumption of Apache. Lighttpd and PHP-FCGI works out of box when installing with aptitude, however I'm not sure if the memory leaks everyone keeps talking about back in 06/07 are still present. I also read Nginx has a lower CPU usage but I can't get it to work with PHP-CGI let alone with PHP-FPM. Is there an easy way to install this on Ubuntu using the package manager? Do you recommend any reading on this subject? – Alix Axel Feb 05 '11 at 23:55
  • With multiverse enabled, I was able to "apt-get install nginx" on lucid and it runs like a champ - I'm using on production systems. There's a good starting point example here, http://www.howtoforge.com/installing-php-5.3-nginx-and-php-fpm-on-ubuntu-debian but as always YMMV. – dialt0ne Feb 06 '11 at 00:31
  • I'm able to install nginx using apt but I'm failing to bind it to the PHP interpreter. The link you provided has a new source that seems to provide the `php5-fpm` package. I'm going to try it out. – Alix Axel Feb 06 '11 at 01:08
  • This link might be better http://www.howtoforge.com/installing-nginx-with-php-5.3-and-php-fpm-on-ubuntu-lucid-lynx-10.04-without-compiling-anything I am using the brianmercer repo for my production systems for php5-fpm. – dialt0ne Feb 06 '11 at 04:00