Change PHP configuration without editing php.ini

5/5 - (1 vote)

This option can ve used if Your hosting company(especially shared hosting) doesn’t give you control of php.ini file.

This list includes the php.ini directives you can set to configure your PHP setup.

1. Use .htaccess file

This work only on Apache server!

For example if we want to change default values php.ini values You must use php_flag for the string type values (with On and Off) and php_value for the numbers values as:

php_value setting_name setting_value
php_flag setting_name setting_value
#change upload_max_filesize size
php_value upload_max_filesize  10M

#change display_errors to on
php_flag display_errors on

#increase memory_limit value
php_value memory_limit 32M

Using a .htaccess file has an immediate effect therefore is not required to restart the web server.

2. Use ini_set() php function

Also You can change certain php.ini values at runtime of your scripts through ini_set() php function.

  • The ini_set() configuration options will keep values during the script’s execution, and will be restored at the script’s ending.
  • Not all php.ini directives can be modified using ini_set().

    For example according to the list of php.ini directives the upload_max_filesize is changeable through PHP_INI_PERDIR (this means that entry can be set in php.ini, .htaccess or httpd.conf), so it is not possible to change this value with ini_set().

ini_set('error_reporting', E_ALL);
ini_set('display_errors', '1');

You should consider these alternatives only if you don’t have direct access to editing php configuration file, php.ini

Hello there!

I hope you find this post useful!

I'm Mihai, a programmer and online marketing specialist, very passionate about everything that means online marketing, focused on eCommerce.

If you have a collaboration proposal or need helps with your projects feel free to contact me. I will always be glad to help you!

subscribe youtube

Leave a Comment