NEW SUPPORT LINE (South Africa only): SMS your support request (FIRST WORD MUST BE SUPPORT) to 072 532 1530

Create your own php.ini to tweak settings for your website

Posted in php.ini / .htaccess on 2012-08-03

You may at times have a custom requirement for the php.ini file, however, the global php.ini file cannot be changed at will as it affects everyone on the server. You are able to create your own php.ini file so that you can override settings as needed.

For instance, Drupal (from about version 5.x) requires MBString to be turned off. However, MBString is a requirement for displaying foreign language characters, like Chinese.

 

The solution is an extremely simple 2 step process:

 

Step 1: Create your php.ini file

Create a file called php.ini (lower case) in the public_html directory of your account. Enter any info you need here. So, for instance, in our Drupal example, we'd have a file called php.ini with the following:

 

Add the following line to it:

 

php_flag mbstring.encoding_translation Off

 

That's it for the php.ini file, BUT there is a problem. This php.ini file applies only to the public_html directory. You will need to copy this file to every directory (folder) on your site. 

 

Fortunately, we can use .htaccess so that we DO NOT have to copy this file to all folders. Using .htaccess we can tell the entire website to use our php.ini file from public_html.

 

Step 2: Create your .htaccess file

In the same folder as your php.ini file, create a file called .htaccess (note the dot in front of the file name). In .htaccess, add the following code:

 

<IfModule mod_suphp.c>
     suPHP_ConfigPath /home/username/public_html
         <Files php.ini>
            order allow,deny
            deny from all
         </Files>
</IfModule>

 

NOTE: the username part. That needs to be changed to the username of your account. You can see this in cpanel in the left nav under the heading: Home Directory.

 

The above code tells the server to use the php.ini file found in public_html. The deny from all line tells php to use this file, but not let anyone download it.

 

That's it, your php should now work as you want it to!

 

Please post any questions in the comments section below.

Comments

Add your comment

Display Name:
Web Address:
Email Address: (not displayed)

Comment

SSL Certificate Authority Paypal Verified We accept PayPal

 
 
  © Free, easy content management system
HOME | WEB DEVELOPMENT | WEB HOSTING | SOFTWARE | RESELLERS | SEO | GENERAL | AFFILIATES | RESELLER 50GB | RESELLER 100GB | RESELLER 150GB | RESELLER 200GB | VPS
 
Some policy info