PHP as Apache module

December 18, 2007

We can use php.ini directives configuration settings such as error_reporting, display_errors, auto_prepend_file etc from apache configuration files (httd.conf or .htaccess file).

Lets we want to append a config file (ex. init.php) at the beginning of a script(index.php). So we need to add the following statement in our .htaccess file.


1. init.php sample file
<?
define("DOCUMENT_ROOT" , $_SERVER['DOCUMENT_ROOT']);
define("DISPLAY_ERROR" , 1);
?>


2. index.php sample file
<?
print_r(DOCUMENT_ROOT);
?>


3..htaccess file
#php_value name value
#Can be used only with PHP_INI_ALL and PHP_INI_PERDIR type directives.

php_value auto_prepend_file init.php

N.B. All the files needs to should be store in the same directory as we use htaccess which used as per directory level. So all the php scripts in that directory will prepend the init.php file.

Now we are ready to test the script.

There are lots of php ini directives that can be altered from apache module.

For more info please visit the php manual

Cheer$
$haymoL
eXplOrinG PHP