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

Due to the popularity of my previous post that guides how to increase upload_max_filesize on cPanel server I decided to create a more general article, that covers changing of other 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:

  1. Login to your cPanel account, open public_html directory and create blank php.ini file
  2. 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

  1. Save php.ini file

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

  1.  Edit .htaccess file and put there the path to your php.ini file. Replace “/home/whz/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 “whz” with your cPanel username

suPHP_ConfigPath /home/whz/public_html

  1. Save .htaccess file

Did this article help you? Leave your comment!