# Overriding $DOCUMENT_ROOT in an Apache Module

- Thread: https://externals.io/message/4571
- Original archive: https://news-web.php.net/php.internals/4571
- Started by Mark Morley on 2003-09-25T01:07:29+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

---

## #4571 — Mark Morley — 2003-09-25T01:07:29+00:00

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

I'm working on a custom mass hoting Apache module.

I need to be able to set the $DOCUMENT_ROOT value on a per
request basis.  That is, I'd like to be able to set it in my module before
the clients' scripts run (similar to how I use zend_alter_ini_entry to
alter ini values).

I've tried using Apache's ap_table_set call to define the environment
variable, but PHP seems to clobber that and replace it.

Any thoughts?

Mark

---

## #4572 — Rasmus Lerdorf — 2003-09-25T01:16:26+00:00

URL: https://externals.io/message/4571#4572 · In reply to: #4571

> I'm working on a custom mass hoting Apache module.
> 
> I need to be able to set the $DOCUMENT_ROOT value on a per
> request basis.  That is, I'd like to be able to set it in my module before
> the clients' scripts run (similar to how I use zend_alter_ini_entry to
> alter ini values).
> 
> I've tried using Apache's ap_table_set call to define the environment
> variable, but PHP seems to clobber that and replace it.
> 
> Any thoughts?

This doesn't really have anything to do with PHP.  You are writing an 
Apache module.  You simply have to change the doc_root before Apache gets 
to the content handling phase of the request_rec.  And to change the 
doc_root I think you'd just fiddle with conf->ap_document_root and it 
should all fall into place.  But again, this has nothing to do with PHP.

-Rasmus
