Nginx with PHP-FPM is generally faster than Apache with mod_php
, but the resulting performance improvement depends on the environment (PHP code complexity, users/load, hardware, etc.), where you deploy your solution or web application.
We need to dig a bit deeper into webservers to understand why there are no plain comparisons of PHP performance for webservers.
PHP support in Nginx
Apache uses mod_php
to interpret PHP code. Lighttpd, a competitor to Nginx during the early days, used its own spawn_fcgi
(another FastCGI implementation) to improve speed and resulted in being able to serve more users with the same or less amount of resources as Apache. Thus gaining popularity.
Nginx is a bit more different to Lighttpd. As of today Nginx supports a lot of functionality and can also be configured to run spawn_fcgi
, but it was never as closely bundled with it as was Lighttpd. Which allowed to re-think about PHP support for webservers and probably led to the FastCGI Process Manager project (PHP-FPM).
PHP-FPM is available in Ubuntu via the php-fpm
package as of 12.04. The Ubuntu package comes pre-configured, but it's worth reading up on how to fine tune pool parameters for your needs (impatcs: complexity of code, available RAM and CPU processing power, execution time). There are also guides available which explain how to setup dedicated pools for different applications yielding for not only more performance, but also security. If you care about performance you should take the time to get to know the main components of your new server stack.
Configuring Nginx
Please read the Nginx documentation in the english project wiki. I found it to be very helpful for understanding how Apache is configured, why Nginx does things differently (e.g. if
is evil) and how you achieve speed improvements with Nginx.
If you replace Apache with Nginx and try to configure it the same way as Apache, you won't get much speed improvement at all or your configuration will just not work.
Nginx basically aims for reducing complexity while still providing a wide feature set.
And who said you cannot run an Apache behind Nginx?