开发者

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

开发者 https://www.devze.com 2022-12-17 22:41 出处:网络
Assume if I want to change the value of php_value post_max_size 20M in .htaccess post_max_size 20M in php.ini

Assume if I want to change the value of

php_value post_max_size 20M in .htaccess

post_max_size 20M in php.ini

Both will do same operation. So what is the difference between php.ini and .h开发者_运维问答taccess?


The configuration in the php.ini is used for the whole server while the configuration in a .htaccess file is only used when a request goes to the directory or subdirectory the .htaccess file is located in.

So you can have a global or default configuration in your php.ini and specific configurations for individual directories in .htaccess files. Furthermore web hosting provider often do not allow access to the php.ini or server configuration but do only allow .htaccess files.

But notice the configuration modes every PHP configuration is bound to.


Configuration values put in PHP.ini is for the entire server, it gets applied to all the sites running on that server. Where as configuration values put in .htaccess is for individual sites.


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

If you run PHP as CGI, then you'll use a php.ini file, as anything in .htaccess woudln't affect your PHP.

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

This only refers to local overrides for a specific directory; regardless of how PHP is installed it reads your main php.ini file.


Not an answer to your question, but an interesting tidbit I didn't know myself, when using PHP on Windows, it is possible to set per-directory settings in the registry. From the manual:

Changing PHP configuration via the Windows registry

When running PHP on Windows, the configuration values can be modified on a per-directory basis 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 directory c:\inetpub\wwwroot would be stored in the key HKLM\SOFTWARE\PHP\Per Directory Values\c\inetpub\wwwroot. The settings for the directory would be active for any script running from this directory or any subdirectory of it. The values under the key should have the name of the PHP configuration directive and the string value. PHP constants in the values are not parsed. However, only configuration values changeable in PHP_INI_USER can be set this way, PHP_INI_PERDIR values can not.


Apache is the HTTP server. It is configured with a .htaccess file placed in the root of the website/Application means every application has its own .htaccess file.

php.ini is the fastest way to affect PHP's functionality.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号