{"id":712,"date":"2016-06-28T12:38:12","date_gmt":"2016-06-28T16:38:12","guid":{"rendered":"https:\/\/www.pair.com\/support\/kb\/?p=712"},"modified":"2025-08-04T09:45:05","modified_gmt":"2025-08-04T13:45:05","slug":"php-as-cgi","status":"publish","type":"ht_kb","link":"https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/","title":{"rendered":"How to Run PHP as CGI"},"content":{"rendered":"\n<p><span class=\"s1\"><a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/shared-hosting\/\"><p style=\"background-color:#1a3d6e !important;color:#fff;padding:6px; display:inline-block!important;font-size:12px;font-weight:bold; border-radius:3px;\">Shared<\/p><\/a> <a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/vps\/\"><p style=\"background-color:#1a3d6e !important;color:#fff;padding:6px; display:inline-block!important;font-size:12px;font-weight:bold; border-radius:3px;\">VPS<\/p><\/a> <a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/qs-dedicated\/\"><p style=\"background-color:#1a3d6e !important;color:#fff;padding:6px; display:inline-block!important;font-size:12px; font-weight:bold; border-radius:3px;\">Dedicated<\/p><\/a><\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Running PHP as a CGI<\/h3>\n\n\n\n<p>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 8.0, but may work for other versions as well.<\/p>\n\n\n\n<p><strong>If you have a Shared hosting account, VPS account, or Dedicated servers with FastCGI:<\/strong><\/p>\n\n\n\n<ul>\n<li><a href=\"#4\">Using FastCGI<\/a><\/li>\n<\/ul>\n\n\n\n<p><strong>If <strong>you have a Shared hosting account created BEFORE June 1, 2011, a&nbsp;VPS Account, or a Dedicated server:<\/strong><\/strong><\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">Most VPS and Dedicated accounts fall into this category. However, your account has FastCGI, skip to the next section.<\/p>\n\n\n\n<ul>\n<li><a href=\"#1\">With System CGI Enabled<\/a><\/li>\n\n\n\n<li><a href=\"#2\">Without System CGI Enabled<\/a><\/li>\n\n\n\n<li><a href=\"#3\">Using PHP-CGIWrap<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">Don't know which one you are? Contact our support team and they'll be able to tell you.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"using-fastcgi\"><strong>Using FastCGI<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-alert\">For Shared hosting accounts created AFTER June 1, 2011.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-danger\">The&nbsp;<strong>fcgi-bin<\/strong>&nbsp;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.&nbsp;<\/p>\n\n\n\n<ol>\n<li>Create a \"php#_wrapper.sh\" script in your top level&nbsp;<strong>fcgi-bin<\/strong>&nbsp;directory. <br><br>Replace the <kbd>#<\/kbd> in the <kbd>php#_wrapper.sh<\/kbd> filename with your<em> <\/em>PHP version number.<\/li>\n\n\n\n<li> Add the the following line in your new script:<br><br><pre><code>#!\/bin\/sh <br> exec \/usr\/www\/cgi-bin\/php#.cgi<\/code><\/pre>Replace the <kbd>#<\/kbd> in <kbd>php#.cgi<\/kbd> with the PHP version number. For example, <kbd>php8.cgi<\/kbd> or <kbd>php7.cgi<\/kbd>.<\/li>\n\n\n\n<li>You'll need to make the script executable with the following command:<br><br><pre><code>chmod 700 $HOME\/public_html\/fcgi-bin\/php#_wrapper.sh<\/code><\/pre><br>The <kbd>php#_wrapper.sh<\/kbd> in this command should match the name of the <kbd>php#_wrapper.sh <\/kbd>file you created in Step 1.<br><\/li>\n\n\n\n<li>Create an \".htaccess\" file in the directory where your PHP files reside, and add these lines:<br><br><pre><code>AddType application\/x-httpd-php# .php <br>Action application\/x-httpd-php# \/fcgi-bin\/php#_wrapper.sh<\/code><\/pre><br>Replace the <kbd>#<\/kbd> with your PHP version number. <br><br>Make sure the <kbd>php#_wrapper.sh<\/kbd> matches the name of the file you created in Step 1. <br><br>Examples: <br><br><pre><code>AddType application\/x-httpd-php8 .php<br> Action application\/x-httpd-php8 \/fcgi-bin\/php8_wrapper.sh<\/code><\/pre> <pre><code>AddType application\/x-httpd-php7 .php<br> Action application\/x-httpd-php7 \/fcgi-bin\/php7_wrapper.sh<\/code><\/pre><\/li>\n<\/ol>\n\n\n\n<p><br><a name=\"1\"><\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>With System CGI Enabled<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-alert\">For Shared hosting accounts created BEFORE June 1, 2011, VPS Accounts, and Dedicated servers.<\/p>\n\n\n\n<p>Add the following lines to your web directory's .htaccess file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AddType application\/x-httpd-php8 .php\nAction application\/x-httpd-php8 \/cgi-sys\/php8.cgi<\/code><\/pre>\n\n\n\n<p>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 php8.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:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th><strong>.htaccess Syntax<\/strong><\/th><th><strong>php.ini Syntax<\/strong><\/th><\/tr><tr><td>php_value memory_limit 64M<\/td><td>memory_limit = 64M<\/td><\/tr><tr><td>php_flag allow_url_fopen on<\/td><td>allow_url_fopen = on<\/td><\/tr><tr><td>php_value upload_max_filesize 64M<\/td><td>upload_max_filesize = 64M<\/td><\/tr><tr><td>php_value post_max_size 64M<\/td><td>post_max_size = 64M<\/td><\/tr><tr><td>php_flag register_globals off<\/td><td>register_globals = off<\/td><\/tr><tr><td>php_flag magic_quotes_gpc 0<\/td><td>magic_quotes_gpc = off<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><a name=\"2\"><\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Without System CGI<\/strong><\/h4>\n\n\n    \t\t<div class=\"hts-messages hts-messages--alert   hts-messages--withicon \"   >\r\n    \t\t\t    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\tFor Shared hosting accounts created AFTER June 1, 2011, VPS Accounts, and Dedicated servers.    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n\n\n\n<p>Place a copy of php8.cgi in your domain's <strong>cgi-bin<\/strong>&nbsp;directory:<\/p>\n\n\n\n<ol>\n<li>Connect to your account via SSH and copy the CGI version of PHP into your own <strong>cgi-bin<\/strong>&nbsp;directory with the following command:\n<pre class=\"prettyprint\"><code>cp \/usr\/www\/cgi-bin\/php8.cgi ~\/public_html\/cgi-bin\/<\/code><\/pre>\n<p>(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.)<\/p>\n<\/li>\n\n\n\n<li>Create a .htaccess file in the directory where your PHP files reside, and add these lines:\n<pre class=\"prettyprint\"><code>AddType application\/x-httpd-php8 .php\nAction application\/x-httpd-php8 \/cgi-bin\/php8.cgi<\/code><\/pre>\n<\/li>\n<\/ol>\n\n\n\n<p>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 php8.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:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th><strong>.htaccess Syntax<\/strong><\/th><th><strong>php.ini Syntax<\/strong><\/th><\/tr><tr><td>php_value memory_limit 64M<\/td><td>memory_limit = 64M<\/td><\/tr><tr><td>php_flag allow_url_fopen on<\/td><td>allow_url_fopen = on<\/td><\/tr><tr><td>php_value upload_max_filesize 64M<\/td><td>upload_max_filesize = 64M<\/td><\/tr><tr><td>php_value post_max_size 64M<\/td><td>post_max_size = 64M<\/td><\/tr><tr><td>php_flag register_globals off<\/td><td>register_globals = off<\/td><\/tr><tr><td>php_value magic_quotes_gpc 0<\/td><td>magic_quotes_gpc = off<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><a name=\"3\"><\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Using PHP-CGIWrap<\/strong><\/h4>\n\n\n    \t\t<div class=\"hts-messages hts-messages--alert   hts-messages--withicon \"   >\r\n    \t\t\t    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\tFor Shared Hosting Accounts Created BEFORE June 1, 2011, VPS Accounts, and Dedicated Servers    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n\n\n\n<p>Place a copy of php8.cgi in your top-level <strong>cgi-bin<\/strong>&nbsp;directory:<\/p>\n\n\n\n<ol>\n<li>Connect to your account via SSH and copy the CGI version of PHP into your own <strong>cgi-bin<\/strong>&nbsp;directory with the following command:\n<pre class=\"prettyprint\"><code>cp \/usr\/www\/cgi-bin\/php8.cgi ~\/public_html\/cgi-bin\/<\/code><\/pre>\n<\/li>\n\n\n\n<li>Create a .htaccess file in the directory where your PHP files reside, and add these lines:\n<pre class=\"prettyprint\"><code>AddType application\/x-httpd-php8 .php\nAction application\/x-httpd-php8 \/cgi-sys\/php-cgiwrap\/<em>USERNAME<\/em>\/php8.cgi<\/code><\/pre>\n<\/li>\n<\/ol>\n\n\n\n<p>Replace <em>USERNAME<\/em> with your Pair Networks account username.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":12,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":[],"ht-kb-category":[175],"ht-kb-tag":[178,176,177],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Run PHP as CGI - Knowledge Base - Pair Networks<\/title>\n<meta name=\"description\" content=\"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.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Run PHP as CGI - Knowledge Base - Pair Networks\" \/>\n<meta property=\"og:description\" content=\"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.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/\" \/>\n<meta property=\"og:site_name\" content=\"Knowledge Base - Pair Networks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/pairnetworks\/\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-04T13:45:05+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@pairNetworks\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/\",\"name\":\"How to Run PHP as CGI - Knowledge Base - Pair Networks\",\"isPartOf\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#website\"},\"datePublished\":\"2016-06-28T16:38:12+00:00\",\"dateModified\":\"2025-08-04T13:45:05+00:00\",\"description\":\"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.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pair.com\/support\/kb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Run PHP as CGI\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#website\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/\",\"name\":\"Knowledge Base - Pair Networks\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pair.com\/support\/kb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#organization\",\"name\":\"Pair Networks\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg\",\"contentUrl\":\"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg\",\"width\":360,\"height\":360,\"caption\":\"Pair Networks\"},\"image\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/pairnetworks\/\",\"https:\/\/twitter.com\/pairNetworks\",\"https:\/\/www.instagram.com\/pairnetworks\/\",\"https:\/\/www.linkedin.com\/company\/2269676\/\",\"https:\/\/www.pinterest.com\/pairnetworksinc\/pins\/\",\"https:\/\/www.youtube.com\/user\/pairnetworks\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Run PHP as CGI - Knowledge Base - Pair Networks","description":"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.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/","og_locale":"en_US","og_type":"article","og_title":"How to Run PHP as CGI - Knowledge Base - Pair Networks","og_description":"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.","og_url":"https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/","og_site_name":"Knowledge Base - Pair Networks","article_publisher":"https:\/\/www.facebook.com\/pairnetworks\/","article_modified_time":"2025-08-04T13:45:05+00:00","twitter_card":"summary_large_image","twitter_site":"@pairNetworks","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/","url":"https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/","name":"How to Run PHP as CGI - Knowledge Base - Pair Networks","isPartOf":{"@id":"https:\/\/www.pair.com\/support\/kb\/#website"},"datePublished":"2016-06-28T16:38:12+00:00","dateModified":"2025-08-04T13:45:05+00:00","description":"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.","breadcrumb":{"@id":"https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pair.com\/support\/kb\/php-as-cgi\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pair.com\/support\/kb\/"},{"@type":"ListItem","position":2,"name":"How to Run PHP as CGI"}]},{"@type":"WebSite","@id":"https:\/\/www.pair.com\/support\/kb\/#website","url":"https:\/\/www.pair.com\/support\/kb\/","name":"Knowledge Base - Pair Networks","description":"","publisher":{"@id":"https:\/\/www.pair.com\/support\/kb\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pair.com\/support\/kb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pair.com\/support\/kb\/#organization","name":"Pair Networks","url":"https:\/\/www.pair.com\/support\/kb\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/","url":"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg","contentUrl":"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg","width":360,"height":360,"caption":"Pair Networks"},"image":{"@id":"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/pairnetworks\/","https:\/\/twitter.com\/pairNetworks","https:\/\/www.instagram.com\/pairnetworks\/","https:\/\/www.linkedin.com\/company\/2269676\/","https:\/\/www.pinterest.com\/pairnetworksinc\/pins\/","https:\/\/www.youtube.com\/user\/pairnetworks"]}]}},"_links":{"self":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/712"}],"collection":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/comments?post=712"}],"version-history":[{"count":26,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/712\/revisions"}],"predecessor-version":[{"id":10264,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/712\/revisions\/10264"}],"wp:attachment":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/media?parent=712"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb-category?post=712"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb-tag?post=712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}