wkitty42
8th of August 2004 (Sun), 11:31
as asked by another member in another thread, i've started this new thread on the topic of using .htaccess to set/adjust settings for php. normally, your php settings are in php.ini but in some cases, you need things just a bit different for some php scripts than you do for others. by using .htaccess files, you can set/adjust some settings but not all... here's an example from a working site...
<IfModule mod_php4.c>
php_value post_max_size 2M
php_value upload_max_filesize 2M
php_value display_errors Off
php_value display_startup_errors On
php_value log_errors Off
php_value max_execution_time 600
php_value max_input_time 600
php_value mysql.allow_persistent On
php_value default_socket_timeout 240
php_value mysql.connect_timeout 240
php_value session.cookie_domain www.wpusa.dynip.com (http://www.wpusa.dynip.com)
</IfModule>
the above is only a small portion of the .htaccess file it was taken from... there are times that you may want to allow files larger than 2Meg to be uploaded or that you may want to allow more time for a script to execute... you can set those settings and have them take effect immediately rather than having to edit your php.ini and restart the server process or reboot the machine. This is only if your php is running as a module "within" your server.
if you are running php in a cgi type environment, then this does not apply to you because php.ini is read on each invocation of php rather than only during the server startup when mod_php4 is loaded. since i run php within the context of my apache server on OS/2 as a module, this is the way i handle this.
here is what the php manual has to say about this...
PHP ManualThe configuration file
The configuration file (called php3.ini in PHP 3.0, and simply php.ini as of PHP 4.0) is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started. For the CGI version, it happens on every invocation.
Example 3-1. php.ini example
; any text on a line after an unquoted semicolon (;) is ignored
[php] ; section markers (text within square brackets) are also ignored
; Boolean values can be set to either:
; true, on, yes
; or false, off, no, none
register_globals = off
magic_quotes_gpc = yes
; you can enclose strings in double-quotes
include_path = ".:/usr/local/lib/php"
; backslashes are treated the same as any other character
include_path = ".;c:\php\lib"
When using PHP as an Apache module, you can also change the configuration settings using directives in Apache configuration files and .htaccess files (You will need "AllowOverride Options" or "AllowOverride All" privileges)
With PHP 3.0, there are Apache directives that correspond to each configuration setting in the php3.ini name, except the name is prefixed by "php3_".
With PHP 4.0, there are several Apache directives that allow you to change the PHP configuration from within the Apache configuration file itself.
php_value name value
This sets the value of the specified variable.
php_flag name on|off
This is used to set a Boolean configuration option.
php_admin_value name value
This sets the value of the specified variable. "Admin" configuration settings can only be set from within the main Apache configuration files, and not from .htaccess files.
php_admin_flag name on|off
This is used to set a Boolean configuration option.
i have a couple of "digital" copies of the php manual that i got from the php web site... the pdf version says that it is almost 1900 pages so you can see why i've not printed it out. you can purchase the php manual from most good bookstores that have computer related sections in them. IIRC, one is looking at paying about $40US or so.
<IfModule mod_php4.c>
php_value post_max_size 2M
php_value upload_max_filesize 2M
php_value display_errors Off
php_value display_startup_errors On
php_value log_errors Off
php_value max_execution_time 600
php_value max_input_time 600
php_value mysql.allow_persistent On
php_value default_socket_timeout 240
php_value mysql.connect_timeout 240
php_value session.cookie_domain www.wpusa.dynip.com (http://www.wpusa.dynip.com)
</IfModule>
the above is only a small portion of the .htaccess file it was taken from... there are times that you may want to allow files larger than 2Meg to be uploaded or that you may want to allow more time for a script to execute... you can set those settings and have them take effect immediately rather than having to edit your php.ini and restart the server process or reboot the machine. This is only if your php is running as a module "within" your server.
if you are running php in a cgi type environment, then this does not apply to you because php.ini is read on each invocation of php rather than only during the server startup when mod_php4 is loaded. since i run php within the context of my apache server on OS/2 as a module, this is the way i handle this.
here is what the php manual has to say about this...
PHP ManualThe configuration file
The configuration file (called php3.ini in PHP 3.0, and simply php.ini as of PHP 4.0) is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started. For the CGI version, it happens on every invocation.
Example 3-1. php.ini example
; any text on a line after an unquoted semicolon (;) is ignored
[php] ; section markers (text within square brackets) are also ignored
; Boolean values can be set to either:
; true, on, yes
; or false, off, no, none
register_globals = off
magic_quotes_gpc = yes
; you can enclose strings in double-quotes
include_path = ".:/usr/local/lib/php"
; backslashes are treated the same as any other character
include_path = ".;c:\php\lib"
When using PHP as an Apache module, you can also change the configuration settings using directives in Apache configuration files and .htaccess files (You will need "AllowOverride Options" or "AllowOverride All" privileges)
With PHP 3.0, there are Apache directives that correspond to each configuration setting in the php3.ini name, except the name is prefixed by "php3_".
With PHP 4.0, there are several Apache directives that allow you to change the PHP configuration from within the Apache configuration file itself.
php_value name value
This sets the value of the specified variable.
php_flag name on|off
This is used to set a Boolean configuration option.
php_admin_value name value
This sets the value of the specified variable. "Admin" configuration settings can only be set from within the main Apache configuration files, and not from .htaccess files.
php_admin_flag name on|off
This is used to set a Boolean configuration option.
i have a couple of "digital" copies of the php manual that i got from the php web site... the pdf version says that it is almost 1900 pages so you can see why i've not printed it out. you can purchase the php manual from most good bookstores that have computer related sections in them. IIRC, one is looking at paying about $40US or so.