How to customize PHP per domain in cPanel on VM?

 

PHP is a scripting language which is commonly used to build websites and web applications. You can also customize the PHP native core to meet the better needs of your website or you can also choose it for Content Management System (CMS). By making this customization it helps you to full fill many goals like increasing the memory, changing security setting etc. And today there are thousands of possible combinations and also developers where you can find it a happy balance that allows websites to function without affecting each other.

 

So today if you are using a web hosting solution for your website and now if you are looking for information on how to customize PHP per domain in cPanel on VPS hosting there here is the complete solution on it. In your server CGI and FastCGI require the custom php.ini which helps to obtain a full PHP configuration, because in DSO and suPHP it contains only those parameters you wish to cancel. And today if you are looking to have better consistency and easier switching between the modes then you can use full PHP configuration file. And /usr/local/lib/php.ini will be the default location for the main php.ino file on your cPanel server.

 

linux vps price       VPS website hosting       Windows VPS Delhi

 

Not only that the DSO handler does not allow you to have more than one php.ini per Apache instance. But you can make minor adjustments in a  .htaccess file which is located in the public_html folder for the domain that you want to customize.

 

Follow the below steps to customize PHP per domain in cPanel on VPS hosting:

 

suPHP

 

suPHP is one of the most commonly used PHP handlers and it is available by default in cPanel. Since you want to change the PHP configuration values you no need to worry about it because it comes with per configured custom php.ini file. So this preference allows it to limit to affecting only the folder where the php.ini file resides. But if you want to affect the multiple folders or sub folders then you need to need to have multiple copies of this files so follow the below steps.

 

---->>> First you need to create a copy of full PHP configuration file inside the domain's public_html folder

 

/home/cpanlusr/public_html/

 

---->>> Now in the same folder you need to create or edit the .htaccessfile and place the below code at the top

 

<IfModule mod_suphp.c>

   suPHP_ConfigPath /home/<cPanel user>/public_html/php.ini

</IfModule>

<Files php.ini>

   order allow,deny

   deny from all

</Files>

 

---->>> Once after customizing the php.ini files now it will function for both the public_html/ folder and all the other files.

 

FCGI/CGI

 

---->>> In here you need to create a copy of full PHP configuration file (php.ini) inside your domain's public_html folder

 

/home/cpanlusr/public_html/

 

---->>> Now to update the second folder path to match where you want to create new php.ini file use the below command

 

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

 

---->>> Next you need to edit the cPanel PHP wrapper script which is located at /usr/local/cpanel/cgi-sys/php5. But before editing any server file you need to take backup of your existing data.

 

---->>> Now you need to run the below command-

 

cp -frp /usr/local/cpanel/cgi-sys/php5 /usr/local/cpanel/cgi-sys/php5.bk

 

---->>> Once after taking the backup you can edit the original file to meet your requirements. You can also use vi, vim, nano, or any other command line editor and enter the below command-

 

nano /usr/local/cpanel/cgi-sys/php5

 

---->>> Before you make any changes, the file should look like this:


#!/bin/sh

 

# If you customize the contents of this wrapper script, place

# a copy at /var/cpanel/conf/apache/wrappers/php5

# so that it will be reinstalled when Apache is updated or the

# PHP handler configuration is changed

 

exec /usr/bin/php

 

---->>> Next you need to add a new line just before the last one at the bottom [[ -f ~/public_html/php.ini ]] && exec /usr/bin/php -c ~/public_html/php.ini so that the file now looks like:

 

#!/bin/sh

 

# If you customize the contents of this wrapper script, place

# a copy at /var/cpanel/conf/apache/wrappers/php5

# so that it will be reinstalled when Apache is updated or the

# PHP handler configuration is changed

 

[[ -f ~/public_html/php.ini ]] && exec /usr/bin/php -c ~/public_html/php.ini

exec /usr/bin/php

 

---->>> Now to create your copy correctly use the below command-

 

mkdir -p /var/cpanel/conf/apache/wrappers

cp -frp /usr/local/cpanel/cgi-sys/php5 /var/cpanel/conf/apache/wrappers/php5

 

---->>> Once everything is done you need to restart your Apache so use the below command

 

service httpd restart