15 March 2013

How to: change php settings using php.ini and .htaccess


How to change PHP settings using php.ini and .htaccess files.

In this article we will change the following php settings:

  • memory_limit – maximum amount of physical memory that can be allocated to PHP script
  • max_post_size – maximum size of data that can be transferred via POST method
  • register_globals – this variable allows to enable or disable register_globals
  • file_uploads – enables or disables file_uploads

First we will create our custom php.ini file.



Login to your cPanel account, open public_html directory and create blank php.ini file
Put php settings that you would like to change into the file. I will put all php variables, but if you would like to leave default values for some of them you can exclude them from the list

[PHP]
; increase php memory_limit to 128M
memory_limit = 128M
; increase php max_post_size to 20M
max_post_size = 20M
; enable file uploads
file_uploads = On
;disable register_globals
register_globals = Off

Save the php.ini file
Next we will create a custom .htaccess file. This is the most important step!

 Edit .htaccess file and put there the path to your php.ini file.
Replace “/home/username/public_html” with path to your php.ini file.

If your php.ini file is located in public_html directory, you only need to replace “username” with your cPanel username

suPHP_ConfigPath /home/whz/public_html

Save the .htaccess file.