What are the advantages and disadvantages of running PHP as a CGI compared to an Apache module?

When running PHP as a CGI, each request spawns a new process, which can lead to higher memory usage and slower performance compared to running PHP as an Apache module. However, running PHP as a CGI provides better security and isolation between processes, making it a more secure option for shared hosting environments.

// To run PHP as a CGI, you can use the following code snippet in your Apache configuration file:

AddHandler php-cgi .php
Action php-cgi /cgi-bin/php.cgi

<Directory "/path/to/cgi-bin">
    Options +ExecCGI
    SetHandler cgi-script
</Directory>