Run PHP as CGI with Apache on Ubuntu

October 31st, 2012 by Laeeq | No comments

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:

  1. $ sudo apt-get install php5-cgi

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.

  1. $ sudo a2enmod actions

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.

  1. #Settings for CGI
  2. ScriptAlias /local-bin /usr/bin
  3. AddHandler application/x-httpd-php5 php
  4. 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.

You can subscribe to PHPZAG.COM posts by Email

 

Related Topics:

  • Wrapping Text using PHP
  • PHP 5.5 beta 4 is now available
  • Swapping Array Keys and Values
  • PHP Security
  • Working with Image Metadata in PHP
  • Converting Between Relative and Absolute File Path
  • Parsing File Paths with PHP
  • How to remove HTML Comments with PHP?
  • How to access .htaccess values?
  • Dealing With Common PHP Errors
  • Interview Questions and Answers for Freshers
  • Display numbers with ordinal suffix using PHP
  • Function to set COLLATION on database fields of Mysql
  • Read and write to remote files using PHP
  • Sharing PHP SESSION Variables between Multiple Subdomains
  • PHP 5.5.0 Alpha4 Development Preview Released
  • Check a string starts with http using PHP
  • Cross-Site Scripting Attacks (XSS)
  • PHP 5.4.11 and PHP 5.3.21 released!
  • PHP Memory Leak Issue
  •  

     

    1. No comments yet.
    1. No trackbacks yet.