Enable custom php.ini file for individual accounts in a cPanel based server with PHP CGI handler

Hello Guys,

Today I am going to let you know how to enable custom php.ini file for individual accounts in a cPanel based server. So, the first thing we should be doing is to find out the current working PHP handler in the server.

Step 1 : Login to the server as root user.
Step 2 : Execute the command;

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

It should give an output as below.

root@server [~]# /usr/local/cpanel/bin/rebuild_phpconf –current

Available handlers: suphp dso cgi none

DEFAULT PHP: 5

PHP4 SAPI: none

PHP5 SAPI: suphp

SUEXEC: enabled

RUID2: not installed

Step 3: Now, navigate to the cgi-bin folder of the account for which custom php.ini is to be enabled

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

Step 4: Copy the default php.ini file from the server to this location

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

Step 5: Lets check if this custom php works without any problem by changing any PHP variable from the default to value to any custom value. Here I’m changing the value of memory_limit.

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

and enter the following code

memory_limit = 128M

Step 6: Now create php.cgi file to load custom php.ini. For that edit the file as below

# root@server [~]# vi /home/user/public_html/cgi-bin/php.cgi

and enter the following code into this file:

#!/bin/sh

/usr/local/cpanel/cgi-sys/php5 -c /home/username/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/

Step 7: Now make the file executable by modifying its permissions as below.

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

Step 8: Correct the ownership of the files to the user

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

Step 8: Edit .htaccess to point to this php.cgi wrapper. To do that, put the following code into your .htaccess file in the public_html directory.

# root@server [/home/username/public_html]# vi .htaccess

and enter the following

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

Now your .htaccess file will look like as follows:

# root@server [/home/username/public_html]# cat .htaccess

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

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

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

Put the following code in it:
<?php phpinfo(); ?>

Step 10: Correct the ownership of the file to the user:

# root@server [/home/username/public_html]# chown username. 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/username/public_html/cgi-bin/php.ini”.

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.