PHP as CGI or Apache Module

apache-2.2cgiinstallationPHP

I've always believed that PHP works better installed as an Apache module, but recently, someone on a local forum pointed out that running PHP as CGI is better security-wise. I've done some googling and it appears that Dreamhost defaults its PHP installation to working via CGI. Now I'm a little puzzled.

As far as I understand (I'm no sysadmin, just a web developer), there's the problem of user permissions when PHP is installed as an Apache module. And there's the problem of speed when using PHP via CGI (or it was).

What's the recommended way nowadays for installing PHP? On both shared and dedicated hosting.

Best Answer

Running PHP as a module is usually more efficient, but means all scripts run under the same user account (what-ever account Apache runs as) which can pose security concerns in a shared environment.

CGI is much slower as it starts a new PHP processes for every request that needs one, but can be configured to run each script as the user that owns it which can be much more secure in a shared environment.

FastCGI can be more of a pain to setup, but comes close to the speed of running as the PHP module.

Related Topic