Enable Custom PHP in cPanel Server with PHP CGI Handler

By on November 19th, 2018


PHP is built as a CLI and CGI program so that it can be used for CGI processing. If a web server that is running PHP has module support for, you should generally go for that solution for performance reasons. Anyhow, the CGI version enables users to run different PHP-enabled pages under a different user on the server.


Find out the current working handler in your server

SSH to the server as root user. Then type the below command.

# /usr/local/cpanel/bin/rebuild_phpconf –current


You will get an output like this.

DEFAULT PHP: ea-php56
ea-php54 SAPI: suphp
ea-php55 SAPI: suphp
ea-php56 SAPI: suphp
ea-php70 SAPI: suphp

From the above command, we can confirm that which PHP handler is in your server.


Enable Custom PHP with PHP CGI Handler

To setup, the custom php.ini file in a server with PHP CGI handler, enter the below command into the cgi-bin folder of the account for which you need to enable custom php.ini.

# cd /home/user/public_html/cgi-bin

Copy the default php.ini file from the server to corresponding locations.

# cp /usr/local/lib/php.ini /home/user/public_html/cgi-bin/

Please confirm that the custom php works without any problem. You can change any PHP variable from the default value to any custom value. Here I’m changing the value of memory_limit.

# memory_limit = 64M

Create php.cgi file to load custom php.ini

vi /home/user/public_html/cgi-bin/php.cgi

Now paste the following code into this file:


/usr/local/cpanel/cgi-sys/php5 -c /home/user/public_html/cgi-bin/

After this, the php.cgi file should look like as follows:

cat php.cgi


/usr/local/cpanel/cgi-sys/php5 -c /home/user/public_html/cgi-bin/

Now make the file executable.

# chmod +x /home/user/public_html/cgi-bin/php.cgi

Correct the ownership of the cgi-bin files to the user

# chown -R user:user /home/user/public_html/cgi-bin/

Edit .htaccess to point to this php.cgi wrapper. Paste the following code into your .htaccess file in the public_html folder of the account.

# Action application/x-httpd-php5 /cgi-bin/php.cgi

As of now your .htaccess file will look like as follows:

cat .htaccess

Action application/x-httpd-php5 /cgi-bin/php.cgi

Here you can check whether the custom php.ini file is working using a test php info page:

vi phpinfo.php

Put the following code in it:

<?php phpinfo(); ?>

Correct the ownership of the phpinfo.php file to the user:

chown user. phpinfo.php

Now you can test the phpinfo file by browsing it as yourdomain.com/phpinfo.php.


If you need any further help please do reach our support department.


Leave a Reply