Tutorial

One of the drawbacks or issues with trying to increase various php settings with a php.ini file on most suphp configured servers is where to actually put the file.

The majority of the suphp based server configurations I have ever used required putting a php.ini file in each and every folder / directory that I wanted to change the values for. Generally it is not a big deal or problem, but it can be time-consuming and tedious to upload a php.ini file if you have a number of directories you want to use it in. On top of that if you decide to change a setting in the php.ini file you will need to go back and re-upload the file to all locations again. That is, if you can remember them all.

This simple tutorial will show you how to use only 1 php.ini file that will affect all folders / directories within your webspace on suphp servers.

All you need to do is create 1 php.ini file and add a few lines of code to your main .htaccess file for your site (http://www.yoursite.com/.htaccess).

Although this could be used on a number of different suphp server setups the example I will be using is based on cpanel hosting paths.

You will need a copy of your hosts php.ini file or you will need to make one yourself.

Important:
This also involves editing your main .htaccess file so be sure to download a backup before doing this. Htaccess files are extremely particular. Just 1 little character out of whack can make your entire website nonfunctional. So be careful and don't say I didn't warn you.


How to use 1 php.ini file in the main root directory with suphp


If your website or Dolphin is located in your root/main public_html directory (http://www.yoursite.com) open the main .htaccess file with your favorite text editor (http://www.yoursite.com/.htaccess) and add the following:

<IfModule mod_suphp.c>
suPHP_ConfigPath /home/your-cpanel-account/public_html
<Files php.ini>
order allow,deny
deny from all
</Files>
</IfModule>


Note:
Be sure to change (your-cpanel-account) in the example given above to your actual cpanel account name.

Save the changes back to your hosting account.

Your php.ini file should also be placed in public_html or http://www.yoursite.com/php.ini

The code simply says look for and use (/home/your-cpanel-account/public_html/php.ini) which is (http://www.yourdomain.com/php.ini) for all folders/directories.



How to use 1 php.ini file with an addon domain with suphp


If you have added a domain using cpanel's addon domain feature and Dolphin is installed there (/home/your-cpanel-account/public_html/domain2.com) add the following to domain2.com/.htaccess file:

<IfModule mod_suphp.c>
suPHP_ConfigPath /home/your-cpanel-account/public_html/domain2.com
<Files php.ini>
order allow,deny
deny from all
</Files>
</IfModule>

Note:
Be sure to change (your-cpanel-account) in the example given above to your actual cpanel account name once again, and be sure to replace domain2.com with your real domain name.

Save the changes back to your hosting account.

Your php.ini file would be placed in http://www.domain2.com/php.ini

The code simply says look for and use (/home/your-cpanel-account/public_html/domain2.com/php.ini) which is (http://www.domain2.com/php.ini) for all folders/directories.



This will make all folders/directories use the 1 php.ini file. This can be extremely helpful if you do not need different values for different folders/directories. From then on if you want to make changes to your php.ini file you only need to do it to the 1 file instead of all over the place.

The files php.ini order, allow...deny part of the code will prevent someone from trying to view the contents of you php.ini directly in a web browser.

You can test this out by adding the code to .htaccess and uploading your php.ini file if you haven't already. Then, login to your Dolphin 7 administration. Go to Tools->Host Tools-> Phpinfo

Scroll down and find something you would like to change. For example, memory limit. Let's say our memory limit is set to 64M and we would like to make it 128M.

If you correctly added the .htaccess code you should be able to simply add this line of code to the php.ini file for yoursite.com/php.ini:
memory_limit = 128M

After doing so, refresh your Dolphin 7 administration Phpinfo page and it should change from 64M to 128M. Which would mean that the 1 php.ini file is working as it is now reflected in your (/administration) directory. Meaning it is not only taking care of your main/root/public_html directory, but the Dolphin administration directory as well.

If it does not change, then you either do not have suphp, you added the code wrong, or forgot to change your-cpanel-account part of the code, etc. Review the code and instructions above again if it doesn't seem to work for you.

If your host is using suphp you usually see something like this in your Dolphin 7 Administration Phpinfo page:
Server API CGI

Server API CGI



If it says Apache, fgi/fastcgi you do not have a suphp server and this won't work for you.

You would also see something like this under the (Site optimization PHP) area in Dolphin administration -> Tools -> Host Tools -> Audit

PHP Setup cgi


Example Memory Limit at 64M

Memory Limit 64M



Example Memory Limit at 128M

Memory Limit 128M



Other:
If you wanted to keep php.ini even more private you could upload php.ini above your public_html directory so it is not even accessible by a web browser.

To do so you would upload php.ini to:
/home/your-cpanel-account-name/php.ini

Then, add to your main .htaccess (http://www.yoursite.com/.htaccess) file the following code:

<IfModule mod_suphp.c>
suPHP_ConfigPath /home/your-cpanel-account
<Files php.ini>
order allow,deny
deny from all
</Files>
</IfModule>


The File php.ini, order allow, deny line wouldn't really be needed in this case or scenario, but you can leave it there if you want.



If you do not want to use the deny from all part of the code simply add the following to your main .htaccess:

For main/root/public_html site:

<IfModule mod_suphp.c>
suPHP_ConfigPath /home/your-cpanel-account/public_html/php.ini
</IfModule>



For an addon domain:

<IfModule mod_suphp.c>
suPHP_ConfigPath /home/your-cpanel-account/public_html/domain2.com/php.ini
</IfModule>



There is no way to test this out on every suphp server setup out there. It is certainly possible that there are a few custom suphp setups that this may not work on.

The good news is it only takes a few moments to add and test it out. It works on a lot of suphp server configured hosts that I have used, and saves a lot of time associated with uploading and changing multiple php.ini files.

 
Written By
Tutorial by: Jeremy LeSarge (AKA Ray)

I am the owner and administrator of DialMe.com. I write Tutorials for Boonex Dolphin as well as tips and resources surrounding website programming and development. I enjoy working with WordPress, SEO, and Web Hosting / Servers. I also maintain a WordPress Blog here on this site where you will find a variety of technology and webmaster resources.

Actions
Sponsored Links
Recommend