Sunday, July 17, 2011

How to set PHP configuration(php.ini) values from .htaccess file

Hello Friends,
There might be situation where you need to change php configuration values when you work on server. In local apache server, you can easily change the php configuration values using php.ini file from directory. But what will you do as php.ini is not visible on server ? The solution is.htaccess which is visible on server(.htaccess invisible ?). Using .htaccess you can change the php configuration values.


About php.ini file : The configuration file (php.ini) is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started.

AllowOverride Options

AllowOverride All

Look at below syntax for changing PHP Configuration values of php.ini using .htaccess.


php_value name value

Sets the value of the specified directive. Can be used only with PHP_INI_ALL and PHP_INI_PERDIR type directives. To clear a previously set value use none as the value.

php_flag name on|off

Used to set a boolean configuration directive. Can be used only with PHP_INI_ALL and PHP_INI_PERDIR type directives.


php_flag is used when you need to set boolean values. Other than booloean values, if you need to set php configuration value than usephp_value.


For E.g.


Look at below examples how to set/change upload_max_filesize , post_max_size and memory_limit using php_value in .htaccess.


php_value upload_max_filesize 10M

php_value post_max_size 8M

php_value memory_limit 32M


If you want to increase the uploading maximum size of file than use upload_max_filesize and set to the value as per your neees.

If you want to increase maximum post size of html form than use post_max_size and set value as per your needs.

If you want to increase memory limit than use memory_limit and set value as per your needs.


Look at below examples how to set/change display_errors , log_errors and magic_quotes_gpc using php_flag in .htaccess. For this you need to change values on/off which is boolean.


php_flag display_errors Off

php_flag log_errors On

php_flag magic_quotes_gpc off


You can enable/disable errors using display_errors. Set value to Off to make it disable.Set value to On to make it enable.

You can enable/disable Log errors using log_errors. Set value to Off to make it disable.Set value to On to make it enable.

You can enable/disable magic quotes using magic_quotes_gpc. Set value to Off to make it disable.Set value to On to make it enable.

Still Problems ? make me know by comments !

0 comments:

Post a Comment

Any Questions or Suggestions ?

About

Professional & Experienced Freelance Developer From India, Technologist, Software Engineer, internet marketer and Open Sources Developer with experience in Finance, Telecoms and the Media. Contact Me for freelancing projects.

Enter your email address:

Delivered by FeedBurner