What is the difference between php.ini and .htaccess?

Suppose I want to change a value

php_value post_max_size 20M in .htaccess post_max_size 20M in php.ini 

Both will perform the same operation. So what is the difference between php.ini and .htaccess ?

+6
php
source share
4 answers

The configuration in php.ini is used for the entire server, while the configuration in the .htaccess file is used only when the request is sent to the directory or subdirectory where the .htaccess file is located.

This way you can have a global or standard configuration in your php.ini and specific configurations for individual directories in .htaccess files. In addition, the web hosting provider often does not allow access to the php.ini or server configuration, but only permits .htaccess files.

But pay attention to the configuration modes that each PHP configuration is associated with.

+11
source share

The configuration values ​​entered in PHP.ini for the entire server apply to all sites running on this server. If configuration values ​​are placed in .htaccess for individual sites.

+2
source share

It depends on how PHP is installed on your server; if it is installed as an apache module, then you will use .htaccess files to issue PHP directives, since .htacess is read and executed by Apache.

If you run PHP as CGI, then you will use the php.ini file, since anything in .htaccess will not affect your PHP.

You can check how PHP is installed by creating a php file with phpinfo (); it's in.

This applies only to local overrides for a specific directory; no matter how php is installed, it reads your main php.ini file.

+1
source share

Not the answer to your question, but an interesting tidbit, which I did not know myself, when using PHP in Windows, you can set the settings for each directory in the registry. From manually :

Changing PHP configuration through the Windows registry

When running PHP on Windows, the configuration values ​​can be changed for each directory using the Windows registry. The configuration values ​​are stored in the registry key HKLM \ SOFTWARE \ PHP \ Per Directory Values ​​in the sub-keys corresponding to the path names. For example, configuration values ​​for the c: \ inetpub \ wwwroot directory will be stored in the HKLM \ SOFTWARE \ PHP \ Per Directory Values ​​\ c \ inetpub \ wwwroot key. The settings for the directory will be active for any script launched from this directory or any subdirectory of it. Turnkey values ​​must have the name of the PHP configuration directive and string values. PHP constants in values ​​are not parsed. However, only configuration values ​​that are modified in PHP_INI_USER can be set in this way; PHP_INI_PERDIR values ​​cannot.

+1
source share

All Articles