PHP is built as both a CLI and CGI program, which can be used for CGI processing. If you are running a web server that PHP has module support for, you should generally go for that solution for performance reasons. However, the CGI version enables users to run different PHP-enabled pages under different user-ids. Here in this post, you will learn how to enable PHP CGI with apache on Ubuntu.
Install PHP CGI
Install the php5-cgi package from the following command:
Enable mod actions in apache
In order to set up Apache to use PHP-CGI on Ubuntu systems, you must enable the mod_actions module.
Now edit the /etc/apache2/sites-enabled/000-default file and add below settings to the end of the file before the ending VirtualHost tag.
- #Settings for CGI
- ScriptAlias /local-bin /usr/bin
- AddHandler application/x-httpd-php5 php
- Action application/x-httpd-php5 /local-bin/php-cgi
In the above example, the path to the php-cgi binary is /usr/bin/php-cgi. All files with the php extension will be handed to the PHP CGI binary.
Finally save the file and restart apache. when you run phpinfo. The server api will be CGI/FastCGI.