Last updated 9 January 2009. Created on 3 August 2008.
Edited by gpk, Phillip Mc. Log in to edit this page.

Introduction

This explains how to make a copy of the default php.ini file, so you can create a custom php.ini file for your Drupal 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:

  • My shared host had register_globals switched on for some reason and was slow to respond to tech.support
  • I'm unable to access and edit the default php.ini for my sites
  • adding in switches in the .htaccess file didn't work for me (because PHP is running as CGI, not as an Apache module)
  • I am able to upload a custom php.ini file to the root folder of my Drupal installation (i.e. the folder containing Drupal's index.php), but, I don't know what else to put in it besides the register globals switch. In other words, when I upload a custom php.ini, it replaces the default php.ini..so it's missing all the other settings and breaks the site.

Step by step solution

This is what I did...(thanks to Dublin Drupaller for putting me straight on this)

  1. Make a copy of the default php.ini by creating a php file using the snippet below, editing it to suit your server paths (e.g. on some servers you might want to use /usr/local/lib/php.ini for the 1st path and /home/YOURUSERNAME/public_html/drupal/php.ini for the 2nd path) and uploading it to the root folder of your drupal site. Call it something like gettheini.php.
    <?php system("cp /usr/local/php5/lib/php.ini /home/YOURUSERNAME/php.ini"); ?>
    
    • If you are unsure where on the server your default php.ini is (there may be a number of different versions on your system, and it is important to get the right one), create a php file called phpinfo.php with the following in it <?php phpinfo(); ?>.

      Upload it to your root folder and in your browser, go to www.example.com/phpinfo.php. Scroll down a bit and it should indicate the exact path for where your default php.ini is located on the server.

  2. In your browser, go to www.example.com/gettheini.php (which should display a blank screen). All it does is create a copy of the default php.ini and puts in the folder you specified.
    • If you see a message like Warning: system() has been disabled for security reasons in /home/YOURUSERNAME/get_the_ini.php on line 1 then you may need to try an alternative command to PHP's system, such as exec, shell_exec or passthru, or ask your host for help.
  3. Now, when you go to the root folder of your Drupal site, using FTP, you should see a new php.ini file. That's a copy of the default php.ini. Open it in a text editor like PS PAD, search for the string register_globals and set it to off.
    • If you cannot see the new php.ini file then possibly the permissions on the directory which should contain it did not permit PHP to copy the file there. You may see an error message such as cp: cannot create regular file `/home/YOURUSERNAME/public_html/drupal/php.ini': Permission denied in your error log. You may need to temporarily change the permissions on the directory from 755 to 777 (don't forget to change them back later), or ask your host for help.
  4. Upload your new custom php.ini to the root folder of your Drupal site.
  5. Add the following lines to your .htaccess file to keep prying eyes from looking at your php.ini
    <Files php.ini>
    order allow,deny
    deny from all
    </Files>
    

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

joecanti’s picture

If you are using cPanel, you can use the PHP quick config icon to make the changes and turn register globals off

rahamatganz’s picture

in the .htaccess file after which line I should put this code
"
order allow,deny
deny from all
"

audster’s picture

If you are using cgi-wrap, you may need to put the newly created php.ini file you have just created in your cgi-bin folder (most likely in the root directory of your drupal install ie public_html)

If you are trying this solution (which worked for me!) and still getting the registers globals is enabled error, try putting your new php.ini file (with register globals set to Off) in your cgi-bin folder (or whatever folder your cgi-wrap is in...)