Mobile app version of vmapp.org
Login or Join
Cooney921

: What are the pros and cons of running PHP as an Apache module or a FastCGI? My VPS is giving me the option between running PHP as an Apache Module or a FastCGI. How should one make this

@Cooney921

Posted in: #Apache #Php #Plesk #Vps

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.

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Cooney921

3 Comments

Sorted by latest first Latest Oldest Best

 

@Candy875

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:


The prefork MPM uses multiple child processes with one thread each. Each process handles one connection at a time. On many systems, prefork is comparable in speed to worker, but it uses more memory. Prefork's threadless design has advantages over worker in some situations: it can be used with non-thread-safe third-party modules, and it is easier to debug on platforms with poor thread debugging support.


So, IMHO, PHP with FastCGI is more suitable in production.

Moreover, my preference is for mod_fastcgi rather than mod_fcgid because it provides more functionalities, such as the ability to define an external process manager.

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:


Warning
A server deployed in CGI mode is open to several possible vulnerabilities. Please read our CGI security section to learn how to defend yourself from such attacks.


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:

php, fastcgi, fpm et apache (French)
php, fastcgi, and apache fpm (English with Google Translate)

10% popularity Vote Up Vote Down


 

@Turnbaugh106

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 :


Apache PHP Module : Simple, easy, standard, to be used in 90%.
PHP-CGI : Performant when there are a lot of static ressources (images, pictures, etc). A bit more complicated to configure, maintain.

10% popularity Vote Up Vote Down


 

@Dunderdale272

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme