How to Run PHP as CGI

Running PHP as a CGI

If you need to run an older version of PHP in order to maintain compatibility with your legacy software, you may run PHP as a CGI. See below for instructions that apply to your hosting account type. The instructions in this article are written assuming that the intended version of PHP is 5.6, but may work for other versions as well.

If you have a Shared hosting account created BEFORE June 1, 2011, a VPS Account, or a Dedicated server:

Most VPS and Dedicated accounts fall into this category. However, your account has FastCGI, skip to the next section.

If you have a Shared hosting account, VPS account, or Dedicated servers with FastCGI:

Don't know which one you are? Contact our support team and they'll be able to tell you.

With System CGI Enabled

For Shared hosting accounts created BEFORE June 1, 2011, VPS Accounts, and Dedicated servers.

Add the following lines to your web directory's .htaccess file:

AddType application/x-httpd-php56 .php
Action application/x-httpd-php56 /cgi-sys/php56.cgi

Any custom PHP settings that were previously set in .htaccess will need to be ported to a php.ini located in the same directory as the php56.cgi file. The syntax for setting custom PHP settings in the php.ini file requires that the string "php_value" or "php_flag" is removed. Instead, an equals sign is placed after the settings attribute and before the desired value The following chart illustrates some common custom PHP settings and the new syntax required:

.htaccess Syntax php.ini Syntax
php_value memory_limit 64M memory_limit = 64M
php_flag allow_url_fopen on allow_url_fopen = on
php_value upload_max_filesize 64M upload_max_filesize = 64M
php_value post_max_size 64M post_max_size = 64M
php_flag register_globals off register_globals = off
php_flag magic_quotes_gpc 0 magic_quotes_gpc = off

Without System CGI

For Shared hosting accounts created BEFORE June 1, 2011, VPS Accounts, and Dedicated servers.

Place a copy of php56.cgi in your domain's cgi-bin directory:

  1. Connect to your account via SSH and copy the CGI version of PHP into your own cgi-bin directory with the following command:
    cp /usr/www/cgi-bin/php56.cgi ~/public_html/cgi-bin/

    (Note that this command may need to be changed if the domain name's cgi-bin has been mapped to a different directory via the ACC.)

  2. Create a .htaccess file in the directory where your PHP files reside, and add these lines:
    AddType application/x-httpd-php56 .php
    Action application/x-httpd-php56 /cgi-bin/php56.cgi

Any custom PHP settings that were previously set in .htaccess will need to be ported to a php.ini located in the same directory as the php56.cgi file. The syntax for setting custom PHP settings in the php.ini file requires that the string "php_value" or "php_flag" is removed. Instead, an equals sign is placed after the settings attribute and before the desired value The following chart illustrates some common custom PHP settings and the new syntax required:

.htaccess Syntax php.ini Syntax
php_value memory_limit 64M memory_limit = 64M
php_flag allow_url_fopen on allow_url_fopen = on
php_value upload_max_filesize 64M upload_max_filesize = 64M
php_value post_max_size 64M post_max_size = 64M
php_flag register_globals off register_globals = off
php_value magic_quotes_gpc 0 magic_quotes_gpc = off

Using PHP-CGIWrap

For Shared Hosting Accounts Created BEFORE June 1, 2011, VPS Accounts, and Dedicated Servers

Place a copy of php56.cgi in your top-level cgi-bin directory:

  1. Connect to your account via SSH and copy the CGI version of PHP into your own cgi-bin directory with the following command:
    cp /usr/www/cgi-bin/php56.cgi ~/public_html/cgi-bin/
  2. Create a .htaccess file in the directory where your PHP files reside, and add these lines:
    AddType application/x-httpd-php56 .php
    Action application/x-httpd-php56 /cgi-sys/php-cgiwrap/USERNAME/php56.cgi

Replace USERNAME with your pair Networks account username.

Using FastCGI

For Shared hosting accounts created AFTER June 1, 2011.

The fcgi-bin script is required for all shared hosting PHP users. It is not just an option to run older PHP versions. Deleting it will cause errors.

  1. Create a php56_wrapper.sh script in your top level fcgi-bin directory, with the following script contents:
    #!/bin/sh
    exec /usr/www/cgi-bin/php56.cgi
  2. You'll need to make the script executable with the following command:
    chmod 700 $HOME/public_html/fcgi-bin/php56_wrapper.sh
  3. Create a .htaccess file in the directory where your PHP files reside, and add these lines:
    AddType application/x-httpd-php56 .php
    Action application/x-httpd-php56 /fcgi-bin/php56_wrapper.sh
Updated on September 17, 2018

Was this article helpful?

Related Articles