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.3, but may work for other versions as well.

For Shared Hosting Accounts Created Before June 1, 2011, and Most VPS Accounts and Dedicated Servers:

For Shared Hosting Accounts and VPS Accounts and Dedicated Servers with FastCGI:

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

With System CGI Enabled

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

AddType application/x-httpd-php53 .php
Action application/x-httpd-php53 /cgi-sys/php53.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 php53.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

Place a copy of php53.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/php53.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-php53 .php
    Action application/x-httpd-php53 /cgi-bin/php53.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 php53.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 illustrtes 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

Place a copy of php53.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/php53.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-php53 .php
    Action application/x-httpd-php53 /cgi-sys/php-cgiwrap/USERNAME/php53.cgi

Replace USERNAME with your pair Networks account username.

Shared Hosting Accounts Created AFTER June 1, 2011

Using FastCGI

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 php53_wrapper.sh script in your top level fcgi-bin directory, with the following script contents:
    #!/bin/sh
    exec /usr/www/cgi-bin/php53.cgi
  2. You’ll need to make the script executable with the following command:
    chmod 700 $HOME/public_html/fcgi-bin/php53_wrapper.sh
  3. Create a .htaccess file in the directory where your PHP files reside, and add these lines:
    AddType application/x-httpd-php53 .php
    Action application/x-httpd-php53 /fcgi-bin/php53_wrapper.sh