# on-the-fly changes to php.ini values?

- Thread: https://externals.io/message/19129
- Original archive: https://news-web.php.net/php.internals/19129
- Started by Todd D. Esposito on 2005-09-22T16:14:21+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #19129 — Todd D. Esposito — 2005-09-22T16:14:21+00:00

URL: https://externals.io/message/19129#19129

Hello!

I'm working on an Apache2 module which pulls vhost info from LDAP, and
I've got it all knocked out save one really important feature:  I need to
be able to change the open_basedir on a per-vhost basis, but obviously,
NOT via php_admin_value in the configuration file(s), since each vhost is
loaded dynamically from LDAP data.

I dug around a bit and found the zend_alter_ini_entry function, the
prototype of which, at least, looked really promising.  However, it always
returns FAILURE for me. I've tried every combination of mod_type.

I went and copied the source for zend_alter_ini_entry directly into my
module, which let me determine that the call to zend_find_hash() is what's
failing.  So this leads me to believe zend_alter_ini_entry isn't really
what I need to do this.

I also poked around in the per-dir configuration handler
(sapi/apache2handler/apache_config.c:merge_php_config), but that hasn't
shed enough light on the problem for me to just jump in and start hacking
away at the php module config data block.

So, my question is: is there a programmatic way, via some function call or
procedure, to alter PHP's runtime configuration as I describe above?

Thanks and further details forthcoming to anyone who can lend a hand.

Todd D. Esposito

---

## #19223 — Todd D. Esposito — 2005-09-28T03:27:31+00:00

URL: https://externals.io/message/19129#19223

Tom,

Thanks for the reply.  As it happens, I went ahead and hacked around in
the internal a bit more, and came up with a working solution bypassing
zend_alter_ini_entry, instead getting the php per-server config block, and
updating the configuration has via zend_hash_update calls.

It works (though there is a case where corruption of the php config block
can occur, so care is warranted), but leaves me still wondering if there
is any "official" way to do this, or at least one recommended over
another.  In other words, is _alter_ini_ a better tactic than
_hash_update?

Any opinion?

On Mon, September 26, 2005 20:42, Tom Rogers said:
> Hi Todd,
>
> A small typo in one line corrected
>
> ***************************************
>
> I have done a similar thing for apache 1.3 and did the following:
>
> added headers
>
> #ifdef HAVE_MOD_PHP_SUPPORT
> #include <zend.h>
> #include <zend_qsort.h>
> #include <zend_API.h>
> #include <zend_ini.h>
> #include <zend_alloc.h>
> #include <zend_operators.h>
> #endif
>
> and the following code
> (doc_root is set to /usr/local/apache/domains/domain.com)
>
> // It all comes down to this lot
> //all virt domains get an include directory above document root
> var = ap_pstrcat(r->pool, doc_root, "/include", NULL);
> //build a new include path adding in the default
> include_path =
> ap_pstrcat(r->pool,"./;",var,";",zend_ini_string("include_path",13,1),NULL);
> //update zend
> zend_alter_ini_entry("include_path", 13, include_path,
> strlen(include_path), 4, 16);
>
> //set some env vars
> ap_table_setn(r->subprocess_env, "PHPINCDIR", var);
> ap_table_setn(r->subprocess_env, "DOMAIN_ROOT", doc_root);
> //correct the documennt root (all html is in doc_root/www)
> conf->ap_document_root = ap_pstrcat(r->pool, doc_root, "/www",NULL);
> //add openbase dir to the one set in httpd.conf
> obasedir_path = ap_pstrcat(r->pool, aliases->OpenBaseDir, ";", doc_root,
> NULL);
> //update zend
> zend_alter_ini_entry("open_basedir", 13, obasedir_path,
> strlen(obasedir_path), 4, 16);
>
> You will have to use different ap_xxx commands but it should work
> --
> regards,
> Tom
>
>


Todd D. Esposito
www.ToddEsposito.com
Todd@ToddEsposito.com
630-362-6868
