Categories: cPanel

Enable custom PHP in cPanel server with PHP CGI

Enable custom PHP in cPanel server with PHP CGI. Using any of the above mentioned methods you can confirm the PHP handler in your server. Now you can follow the steps mentioned below to know how to set up custom php.ini file in a server with PHP CGI handler.

1. Enter into the cgi-bin folder of the account for which you need to enable custom php.ini

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

2. Copy the default php.ini file from the server to this location.

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

To make sure the custom php works without any problem you can change any PHP variable from the default to value to any custom value. Here I’m changing the value of memory_limit.

# memory_limit = 64M

3. Create php.cgi file to load custom php.ini

# root@server [~]# 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/

Now the php.cgi file should look like as follows:

# root@server [/home/user/public_html/cgi-bin]# cat php.cgi
#!/bin/sh
/usr/local/cpanel/cgi-sys/php5 -c /home/user/public_html/cgi-bin/

4. Now make the file executable.

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

5. Correct the ownership of the files to the user

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

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

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

Now your .htaccess file will look like as follows:

# root@server [/home/user/public_html]# cat .htaccess 
Action application/x-httpd-php5 /cgi-bin/php.cgi

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

# root@server [/home/user/public_html]# vi phpinfo.php

Put the following code in it:

<?php phpinfo(); ?>

7. Correct the ownership of the file to the user:

# root@server [/home/user/public_html]# chown user. phpinfo.php

Now you can test the phpinfo file by browsing it as domain.com/phpinfo.php. Now check the “Loaded configuration file” in the phpinfo page. It should be like “/home/user/public_html/cgi-bin/php.ini”.

That’s it!!!


Vishwajit Kale
Vishwajit Kale blazed onto the digital marketing scene back in 2015 and is the digital marketing strategist of Hostripples, a company that aims to provide affordable web hosting solutions. Vishwajit is experienced in digital and content marketing along with SEO. He's fond of writing technology blogs, traveling and reading.

Recent Posts

The Ultimate Guide to DIY Website Builders for Entrepreneurs

Ah, the joys of building a website! Picture this: You're sitting there in your pajamas, coffee in hand, ready to…

1 week ago

Don’t Ignore These 11 Signs You Need a Hosting Upgrade

Are you feeling like your website is running in slow motion? It can be frustrating when your online presence doesn't…

2 weeks ago

PrestaShop vs OpenCart: Which Is Right for Your Business?

Are you ready to take your online store to the next level? Whether you're running a PrestaShop or OpenCart platform,…

3 weeks ago

Sitemaps: A Guide to Enhancing Online Visibility

Picture this: your website is like a fabulous party happening in the darkest corner of the internet, but nobody's showing…

4 weeks ago

Step-by-Step Guide to Implementing a CDN for WordPress

Picture this: Your WordPress site is like that one friend who's always fashionably late to everything. You know, the one…

1 month ago