PHP as CGI or Apache Module?

Solution 1:

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.

Solution 2:

Generally speaking, the only reason you would want to run CGI is in a shared environment.

This allows you to have an suEXEC style (see: suPHP) arrangement where scripts are only executed as the owner's UID/GID and have limited permission to anything else on the filesystem.

Otherwise mod_php is far more efficient and often easier to debug.

Solution 3:

With FastCGI I can restart PHP without restarting the server (just kill the PHP processes, server will notice it and immediately restart them).