Creating a php.ini from the server default

think tank December 11, 2011 0 Comments

This explains how to make a copy of the default php.ini file, so you can create a custom php.ini file for your site and make changes, such as increase memory limit, disable register_globals, switch off safe mode, increase max file upload size etc. The reason I created a custom php.ini file for my site was because shared hosts like Hostgator may have the previously mentioned settings not configured to your specific needs by default. Most qaulity shared hosts allow for you to create your own however it’s always more useful to have a starting point versus grabbing one off the internet that may not jive with your hosting provider. Step by step solution First we need to find the path of your default php.ini file your host has configured your account with. To do this, create a new PHP file (doesn’t matter what the file is called) and enter the following code and then upload it. After uploaded, simply navigate to it via your browser.

Once loaded, look for a section called “Loaded Configuration File” and you will see the path next to it. In this example it is “/usr/local/php5/lib/php.ini”. The second step is to create a copy of it directly into your account. This is very much like the first step and we need to upload another php file with a single line of code. Replace “/usr/local/php5/lib/php.ini” with the path from step one and change the “ACCOUNTUSERNAME” with your login.

When you navigate to this file via your browser, it will execute a copy to your accounts root directory. You can change the path by adding more sub directories after the “ACCOUNTUSERNAME/”. Third step is optional however highly recommended for security and only takes a minute. It basically adds the ability to keep prying eyes from lookig at your custom php.ini file. Simply add the following lines to your .htaccess file to keep prying eyes from looking at your php.ini

Now if you have a host such as Hostgator, they will be using what is called SuPHP. This requires you to add a few more lines to your .htaccess file to tell the server to use your new custom php.ini file. You will need to change “ACCOUNTUSERNAME” again and of course you can add any subdirectory afterwards to change the lcoation.