What is difference of PHP handler (CGI vs FastCGI vs Mod_PHP vs suPHP )?

Solution 1:

Those are not really "6 PHP Types", rather two PHP types, each running in 3 different Apache implementations.

suphp, suphp_worker and suphp_event

suPHP itself is a wrapper for PHP, running PHP under given user rights (eg differing from the rights Apache runs under) plus an Apache module (mod_suphp) which allows you to run suPHP - basically in a CGI mode. CGI mode simplified means, that each request passed through to PHP starts a new PHP (runtime) process. This is expensive, in terms of CPU usage, and slower compared to a persistent PHP runtime (~about 3-5 times, i'd guess).

I assume this first variant uses the Apache's prefork MPM, which is widely used and tested but rather slow, compared to other MPMs. Prefork does what it name implies: It forks a given amount of apache processes and holds them available for incoming requests.

The next (suphp_worker) uses the worker MPM instead. Worker is a mix of pre-spawned processes and threads, which is generally faster than prefork (for delivering static contents about twice) and uses less memory.

The last (suphp_event) seems to use suPHP + MPM event, which uses yet again another process/thread model than worker. From benchmarks i've seen, event and worker are about the same speed - the event MPM (at least using Apache 2.2, which your provider probably does) is marked as experimental.

mod_php, mod_php_ruid2 and mod_php_itk

This is a differnt kind of PHP handler implementation: Apache pre-starts a PHP runtime and passes incoming requests to it, spawning new processes as needed. This is considerable faster than suPHP but comes with the downside of having no user right separation: all the php processes run under the same rights as Apache itself.

The first variant probably uses the prefork MPM (described above) as mod_php is incompatible with the thread models from worker or event.

The second variant (mod_php_ruid2) seems to use the Apache module mod_ruid2 in addition, which allows you to run each Apache VirtualHost under differnt user rights - this includes PHP processes. It has a long list of incompabilities which you should consider.

The last variant (mod_php_itk) uses the third party ITK MPM for Apache, a fork of the Apache prefork MPM with the option run each VirtualHost under given user rights. It also gives you the ability to enforce additional limits (eg amount of clients) per VirtualHost.

Suggestion

If those are your only choice, and you are "alone" on your Machine (aka: you do not plan shared hosting) i would probably stick with good ol' mod_php.

If you are planing multiple websites you need to check with your priorities:

  • security over performance: go with suphp_worker. Both (worker MPM and suPHP) are widely tested and give you a good starting point for security. Performance for static files should be good, PHP not so much.
  • performance over security: Probably mod_php_ruid2, but only because i have bad experience with ITK

I do prefer using a third option, which uses FastCGI, giving you even more possibilities to separate rights and access priviliges - but this seems not to be offered.