GICT knowledge base
Enable Custom PHP in cPanel Server with PHP CGI Handler
Published
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:
#!/bin/sh
/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
#!/bin/sh
/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.
Related guides
How to Install and Uninstall JetBackup for cPanel
How to Install JetBackup for cPanel. JetBackup is one of the leading backup solutions for cPanel & WHM that offers a user-friendly GUI. It provides
WHMSetup SendGrid on your cPanel VPS/Server
Setup SendGrid on your cPanel VPS/Server. SendGrid provides a cloud-based service for reliable transactional and marketing email.
WHMChange cPanel Nameserver Software to PowerDNS Carefully
Review WHM nameserver selection, resolver dependencies, cluster compatibility and DNSSEC requirements before a planned PowerDNS service change.
WHMTroubleshooting Jailed Shell on OpenVZ
cPanel/WHM providing Jailed shell environment for users, this feature giving high-level security for users when doing ssh access to their server.
