My VPS is giving me the option between running PHP as an Apache Module or a FastCGI.
How should one make this decision? Performance? Security? Ease of use? Compatibility?
I'm using PLESK.
This question came from our site for professional and enthusiast programmers.
Linking PHP as an Apache HTTPD module makes them inseparable.
This is not without problems:
Indeed, many PHP libraries aren't threadsafe, so it's essential to use the prefork-mpm module for HTTPD 2.x in production to implements a non-threaded, pre-forking web server that handles requests in a manner similar to HTTPD 1.3.
But this approach strongly affects the performance, which can overload the CPU and RAM, causing timeouts and other troubles.
The manual page Apache Performance Tuning enlighten us a little more about the advantages and disadvantages:
So, IMHO, PHP with FastCGI is more suitable in production.
Anyway, there will be no more needs for the prefork-mpm module, and it will finally be possible to pass on the worker-mpm module, much more effective; except that the management process is handled through a shell script to launch the php-cgi executable, which isn't very convenient.
Fortunately, we can use the FastCGI Process Manager for PHP (PHP-FPM), a popular patch natively integrated since PHP 5.3.3. Unfortunately, if you are using PHP 5.2.x, you'll be confined to the classical FastCGI.
Still, it's vital to be aware of the possible vulnerabilities involved by the CGI mode, as reported on the manual page CGI and command line setups:
You can take a look at this blog post, which contains an example of practical use, and which was of great help in writing this response:
No. It is actually a bit more complicated then that. As far as I understood the question, when Apache is treating a request it loads all the PHP library (in case of PHP as Apache Module). Even when executing a static ressource request. So it consumes a lot of memory.
The other solution is a light weighted front httpserver. It will executes static request and forward php request to the PHP-CGI.
To resume this :
PHP with FAST CGI option runs as fast as it runs on LINUX OS. Microsoft has made lots of improvement in IIS7 for PHP to cover OPEN SOURCE SCRIPT (WordPress, Drupal, Joomla, etc...) hosting market.
I am hosting my PHP applications on IIS7 with FastCGI and running WordPress as smoothly as it runs on Linux Hosting. I just need to upload my php files into the public_html directory to run my php applications.