]> granicus.if.org Git - php/commitdiff
This patch implements a new Apache2 directive called PHPINIDir that
authorAaron Bannert <aaron@php.net>
Thu, 18 Apr 2002 22:10:57 +0000 (22:10 +0000)
committerAaron Bannert <aaron@php.net>
Thu, 18 Apr 2002 22:10:57 +0000 (22:10 +0000)
allows the specification of the php.ini directory from within the Apache
configuration. If left unset, the default is to defer to the hard-coded
php paths. When set, the supplied path is made relative to Apache's
internal ServerRoot setting.

Example:
PHPINIDir "conf"
# PHP will now look in the ServerRoot/conf directory for the php.ini file

sapi/apache2filter/apache_config.c
sapi/apache2filter/php_apache.h
sapi/apache2filter/sapi_apache2.c

index 178253d8251ad702d150b1244a9d4a4273b5dddf..6f9003bb6209444062eb7bf87c3e14ad99b2029f 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "php.h"
 #include "php_ini.h"
+#include "php_apache.h"
 
 #include "apr_strings.h"
 #include "ap_config.h"
@@ -82,6 +83,16 @@ static const char *php_apache_admin_value_handler(cmd_parms *cmd, void *dummy, c
        return real_value_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM);
 }
 
+static const char *php_apache_phpini_set(cmd_parms *cmd, void *mconfig, const char *arg)
+{
+       if (apache2_php_ini_path_override) {
+               return "PHPINIPath is not yet supported in vhost configurations";
+       }
+       apache2_php_ini_path_override = ap_server_root_relative(cmd->pool, arg);
+       return NULL;
+}
+
+
 void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
 {
        php_conf_rec *d = base_conf, *e = new_conf;
@@ -130,6 +141,8 @@ const command_rec php_dir_cmds[] =
                   "PHP Value Modifier"),
        AP_INIT_TAKE2("php_admin_value", php_apache_admin_value_handler, NULL, OR_NONE,
                   "PHP Value Modifier"),
+       AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF,
+                  "Directory containing the php.ini file"),
    {NULL}
 };
 
index 8cac0a0e37fa24a7322de7fbd62b6d01196a3771..e96fd404f1e5f0eefcbf1d254ca418103bef7e25 100644 (file)
 #ifndef PHP_APACHE_H
 #define PHP_APACHE_H
 
+#include "httpd.h"
+#include "http_config.h"
+#include "http_core.h"
+
+/* Declare this so we can get to it from outside the sapi_apache2.c file */
+extern module AP_MODULE_DECLARE_DATA php4_module;
+
+/* A way to specify the location of the php.ini dir in an apache directive */
+extern char *apache2_php_ini_path_override;
+
+/* The server_context used by PHP */
 typedef struct php_struct {
        int state;
        request_rec *r;
index decc641570e7b91cce6243d67bb50867df2ff7df..30bff734dcd1e8b4beca3a5a83a3fe9b1b9e7c89 100644 (file)
@@ -42,6 +42,9 @@
 #include "http_core.h"                         
 
 #include "php_apache.h"
+/* A way to specify the location of the php.ini dir in an apache directive */
+char *apache2_php_ini_path_override = NULL;
 
 static int
 php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
@@ -248,15 +251,14 @@ static sapi_module_struct apache2_sapi_module = {
        php_apache_sapi_register_variables,
        php_apache_sapi_log_message,                    /* Log message */
 
+    NULL,                                                                      /* php_ini_path_override */
+
        NULL,                                                                   /* Block interruptions */
        NULL,                                                                   /* Unblock interruptions */
 
        STANDARD_SAPI_MODULE_PROPERTIES
 };
 
-
-AP_MODULE_DECLARE_DATA module php4_module;
-
 static int php_input_filter(ap_filter_t *f, apr_bucket_brigade *bb, 
                ap_input_mode_t mode, apr_read_type_e block, apr_off_t readbytes)
 {
@@ -433,10 +435,23 @@ static void php_apache_add_version(apr_pool_t *p)
        }
 }
 
+static int php_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
+{
+    /* When this is NULL, apache won't override the hard-coded default
+     * php.ini path setting. */
+    apache2_php_ini_path_override = NULL;
+    return OK;
+}
+
 static int
 php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog,
                           apr_pool_t *ptemp, server_rec *s)
 {
+       /* Set up our overridden path. */
+       if (apache2_php_ini_path_override) {
+               apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override;
+       }
+
        tsrm_startup(1, 1, 0, NULL);
        sapi_startup(&apache2_sapi_module);
        apache2_sapi_module.startup(&apache2_sapi_module);
@@ -510,6 +525,7 @@ static int php_post_read_request(request_rec *r)
 
 static void php_register_hook(apr_pool_t *p)
 {
+       ap_hook_pre_config(php_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
        ap_hook_post_config(php_apache_server_startup, NULL, NULL, APR_HOOK_MIDDLE);
        ap_hook_insert_filter(php_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
        ap_hook_post_read_request(php_post_read_request, NULL, NULL, APR_HOOK_MIDDLE);