You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Rui Hu <tc...@gmail.com> on 2011/12/07 11:54:08 UTC

questions about document_root

Hi,
I want to modify apache core to implement a function which can achieve
following expectations:

when I request 1000.xxx.com/test.php ( curl 1000.xxx.com/test.php),
originally apache will get absolute address as $document_root/test.php, but
I want apache to get "$document_root/1000/test.php". Namely, apache will
parse "1000" from the request URI to form absolute address. Then php-cgi
can get this php script to execute.

Previously, I just modified PHP zend to achieve this function. But
considering that other language support would be added to the system such
as Python, therefore, modifying Web Server (apache) is a more convenient
way.

But I'm worried that this modification will result in some unexpected
errors in some modules, and I don't know what's the best place I should
modify. Should I modify the $document_root or $request_uri ?

Really appreciate your help.


-- 
Best regards,

Rui Hu
----------------------------------------------------------------------------------------
State Key Laboratory of Networking & Switching Technology
Beijing University of Posts and Telecommunications(BUPT)
MSN: tchrbupt@gmail.com
-----------------------------------------------------------------------------------------

Re: questions about document_root

Posted by Mark Montague <ma...@catseye.org>.
On December 8, 2011 1:48 , Rui Hu <tc...@gmail.com> wrote:
> 2011/12/8 Rui Hu <tchrbupt@gmail.com <ma...@gmail.com>>
>
>     Is $DOCUMENT_ROOT in php-cgi determined by ap_add_common_vars() in
>     Apache? It seems not to me. I commented the line 237 assigning
>     DOCUMENT_ROOT and re-compiled apache. php-cgi still works fine. It
>     seems that $DUCUMENT_ROOT in php-cgi is not determined by this
>     function.
>

What you say is correct.  This is an Apache HTTP Server mailing list.  
You said, "in apache, I cannot find any code which assign this var." and 
I showed you where in Apache HTTP Server the DOCUMENT_ROOT environment 
variable is set when running CGIs.

What you are now asking should be sent to the PHP users mailing list, 
since it is a question about PHP.  But, see the function 
init_request_info() in the PHP source code, in the file 
sapi/cgi/cgi_main.c (lines 1123-1137)

http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3_8/sapi/cgi/cgi_main.c?revision=315335&view=markup

How PHP determines the value of $_SERVER[DOCUMENT_ROOT] depends on all 
of the following:

- The value for the PHP directive cgi.fix_pathinfo
- The value for the PHP directive doc_root
- The value of the environment variable DOCUMENT_ROOT (set by Apache 
HTTP Server)

--
   Mark Montague
   mark@catseye.org


Re: questions about document_root

Posted by Rui Hu <tc...@gmail.com>.
2011/12/8 Rui Hu <tc...@gmail.com>

> Is $DOCUMENT_ROOT in php-cgi determined by ap_add_common_vars() in Apache?
> It seems not to me. I commented the line 237 assigning DOCUMENT_ROOT and
> re-compiled apache. php-cgi still works fine. It seems that $DUCUMENT_ROOT
> in php-cgi is not determined by this function.
>
> I looked up php's code, php-cgi gets DOCUMENT_ROOT in following codes:
>
> /* DOCUMENT_ROOT */
> value = lstFset_get(rc->t->vars, "docroot");
> if (value != NULL)
>       php_register_variable("DOCUMENT_ROOT", value, track_vars_array
> TSRMLS_CC);
>
> It gets docroot from a k-v table and the key is "docroot". In above code,
> rc->t is a  variables of httpTtrans.
>
>
> 2011/12/8 Mark Montague <ma...@catseye.org>
>
>> On December 7, 2011 23:23 , Rui Hu <tc...@gmail.com> wrote:
>>
>>> I looked up the code of PHP and apache2, and found that PHP gets docroot
>>> from environment var "$DOCUMENT_ROOT". However in apache, I cannot find any
>>> code which assign this var.
>>>
>>> I googled but got nothing. Can you please show me the detailed process
>>> generating $DOCUMENT_ROOT in $_SERVER from apache to php. Thank you very
>>> much!
>>>
>>
>> If you invoke PHP as a CGI, then Apache HTTP Server sets DOCUMENT_ROOT in
>> the function ap_add_common_vars() which is in the file server/util_script.c
>>
>> See line 237,
>>
>> https://svn.apache.org/viewvc/**httpd/httpd/branches/2.2.x/**
>> server/util_script.c?revision=**1100216&view=markup<https://svn.apache.org/viewvc/httpd/httpd/branches/2.2.x/server/util_script.c?revision=1100216&view=markup>
>>
>>
>> --
>>  Mark Montague
>>  mark@catseye.org
>>
>>
>
>
> --
> Best regards,
>
> Rui Hu
>
> ----------------------------------------------------------------------------------------
> State Key Laboratory of Networking & Switching Technology
> Beijing University of Posts and Telecommunications(BUPT)
> MSN: tchrbupt@gmail.com
>
> -----------------------------------------------------------------------------------------
>
>
>


-- 
Best regards,

Rui Hu
----------------------------------------------------------------------------------------
State Key Laboratory of Networking & Switching Technology
Beijing University of Posts and Telecommunications(BUPT)
MSN: tchrbupt@gmail.com
-----------------------------------------------------------------------------------------

Re: questions about document_root

Posted by Mark Montague <ma...@catseye.org>.
On December 7, 2011 23:23 , Rui Hu <tc...@gmail.com> wrote:
> I looked up the code of PHP and apache2, and found that PHP gets 
> docroot from environment var "$DOCUMENT_ROOT". However in apache, I 
> cannot find any code which assign this var.
>
> I googled but got nothing. Can you please show me the detailed process 
> generating $DOCUMENT_ROOT in $_SERVER from apache to php. Thank you 
> very much!

If you invoke PHP as a CGI, then Apache HTTP Server sets DOCUMENT_ROOT 
in the function ap_add_common_vars() which is in the file 
server/util_script.c

See line 237,

https://svn.apache.org/viewvc/httpd/httpd/branches/2.2.x/server/util_script.c?revision=1100216&view=markup


--
   Mark Montague
   mark@catseye.org


Re: questions about document_root

Posted by Rui Hu <tc...@gmail.com>.
Thanks for you advice. I just started to learn Apache & PHP.

I looked up the code of PHP and apache2, and found that PHP gets docroot
from environment var "$DOCUMENT_ROOT". However in apache, I cannot find any
code which assign this var.

I googled but got nothing. Can you please show me the detailed process
generating $DOCUMENT_ROOT in $_SERVER from apache to php. Thank you very
much!



2011/12/7 Nick Kew <ni...@webthing.com>

>
> On 7 Dec 2011, at 10:54, Rui Hu wrote:
>
> > Hi,
> > I want to modify apache core to implement a function which can achieve
> following expectations:
>
> That's a simple task for a simple module.
>
> Since you talk of modifying the core, I infer you're not familiar with the
> modular structure.
> If I might indulge in a bit of self-promotion, a startingpoint for this is
> ISBN: 0-13-240967-4
> (also http://www.apachetutor.org/ )
>
> --
> Nick Kew




-- 
Best regards,

Rui Hu
----------------------------------------------------------------------------------------
State Key Laboratory of Networking & Switching Technology
Beijing University of Posts and Telecommunications(BUPT)
MSN: tchrbupt@gmail.com
-----------------------------------------------------------------------------------------

Re: questions about document_root

Posted by Nick Kew <ni...@webthing.com>.
On 7 Dec 2011, at 10:54, Rui Hu wrote:

> Hi, 
> I want to modify apache core to implement a function which can achieve following expectations:

That's a simple task for a simple module.

Since you talk of modifying the core, I infer you're not familiar with the modular structure.
If I might indulge in a bit of self-promotion, a startingpoint for this is ISBN: 0-13-240967-4
(also http://www.apachetutor.org/ )

-- 
Nick Kew