php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35186 getcwd() returns "/" when using with mod_rewrite
Submitted: 2005-11-10 22:46 UTC Modified: 2005-11-17 23:43 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: samm at os2 dot kiev dot ua Assigned:
Status: Closed Package: Apache2 related
PHP Version: 5CVS, 4CVS (2005-11-11) (snap) OS: FreeBSD 6
Private report: No CVE-ID: None
 [2005-11-10 22:46 UTC] samm at os2 dot kiev dot ua
Description:
------------
When i use getcwd() function in my script which work with mod_rewrite i got "/" instead of real path. Without mod_rewrite redirection all work just fine. I check this with STABLE-200511101949 snapshot. With php 4.4.0 all work as expected.

Reproduce code:
---------------
To reproduce this bug do:
1) Enable mod_rewrite in apache2 config file
2) make .htaccess file with content like:
RewriteEngine on                                                                
RewriteRule    ^test.html$ test.php [L]                                         
and place it in your virtual server root directory.
3) Create file "test.php" with content like 
<? echo getcwd() ?>
and then point your browser to the "yoursever/test.html".
Then try yoursever/test.php

Expected result:
----------------
real path, same in 2 examples, e.g.
/usr/home/samm/htdocs
/usr/home/samm/htdocs

Actual result:
--------------
/
/usr/home/samm/htdocs

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-10 22:51 UTC] samm at os2 dot kiev dot ua
I forgot to say that i use php as  shared Apache 2.0 module with apache 2.0.54
 [2005-11-10 22:53 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

Works fine for me.
 [2005-11-10 23:24 UTC] samm at os2 dot kiev dot ua
I check this with php5-200511102130 - the bug is still present.
 [2005-11-10 23:28 UTC] sniper@php.net
What was the configure line you used? What MPM is Apache using?

 [2005-11-10 23:37 UTC] samm at os2 dot kiev dot ua
PHP:
./configure --with-apxs2=/usr/local/sbin/apxs

Apache: 
-D APACHE_MPM_DIR="server/mpm/prefork"
 [2005-11-10 23:45 UTC] sniper@php.net
This must be some FreeBSD-only issue since this really works fine within Linux.
 [2005-11-10 23:50 UTC] samm at os2 dot kiev dot ua
May be. Anyway 4.4.0 work correctly, so this was broken in 4.4.1. I have no linux around, so currently i cant check this in linux. I found this bug on my 5.4 FreeBSD box, so that is not FreeBSD 6.0 related. I can make some tests if you need. I think that regression was on 4.4.0->4.4.1, may be this can help you.
 [2005-11-11 00:09 UTC] samm at os2 dot kiev dot ua
I tried to copy files from directory sapi/apache2handler of the php4.4.0 to the latest 4.4-stable and than i recompiled php. After this all path`s are displayed correctly, so problem is in the apache2handler changes. Tomorrow i`ll try to make more detailt experiments to find a change, which cause a regression.
 [2005-11-11 00:27 UTC] sniper@php.net
Ah, thank you! This will help us pinpoint the problem very easily now. I'll check what we changed between 4.4.0 / 4.4.1.

 [2005-11-11 00:32 UTC] sniper@php.net
The only file changed was sapi/apache2handler/sapi_apache2.c

 [2005-11-11 00:35 UTC] sniper@php.net
How have you enabled PHP in your httpd.conf?
(what loadmodule/etc. lines you added)

 [2005-11-11 00:44 UTC] sniper@php.net
And what is HAVE_BROKEN_GETCWD set to in the generated main/php_config.h file?


 [2005-11-11 06:27 UTC] samm at os2 dot kiev dot ua
HAVE_BROKEN_GETCWD is undefined
/* Define if system has broken getcwd */                                        
/* #undef HAVE_BROKEN_GETCWD */

And i used last LoadModule item for the php4_module in the httpd.conf:

LoadModule php4_module         /usr/home/samm/src/php4-STABLE-200511101949/libs/libphp4.so                                                

Also i have

AddType application/x-httpd-php .php .phtml

to enable parsing of php.
 [2005-11-11 08:04 UTC] samm at os2 dot kiev dot ua
I played with different version of the  sapi_apache2.c and found that last working version was 1.1.2.40 and first failed was 1.1.2.40.2.5 . I was unable to check versions between this, because they failed to work with mod_rewrite giving no output at all. I hope, this help you.
 [2005-11-14 20:51 UTC] adsh at univ dot kiev dot ua
I have blank reply in 5 attempts with instructions in the 1-st message.

telnet www.server.kiev.ua 80
Trying 193.xxx.xxx.xxx...
Connected to www.server.kiev.ua.
Escape character is '^]'.
GET http://www.server.kiev.ua/test/test.html HTTP/1.0

HTTP/1.0 200 OK
Date: Mon, 14 Nov 2005 19:42:58 GMT
Server: Apache/2.0.55 (FreeBSD)
X-Powered-By: PHP/4.4.2-dev
Content-Length: 0
Connection: close
Content-Type: text/html; charset=windows-1251

Connection closed by foreign host.

php4-STABLE-200511131945,  FreeBSD 4.11
 [2005-11-17 09:41 UTC] sniper@php.net
You're using the PHP 4 snapshot. Did you or did you not try the 5.1 snapshot I asked you?!
 [2005-11-17 10:59 UTC] samm at os2 dot kiev dot ua
Yes, i tried with latest PHP too.
See "I check this with php5-200511102130 - the bug is still present.".
 [2005-11-17 12:47 UTC] samm at os2 dot kiev dot ua
Just to make you absolutely sure i repeat this tests with latest php5 cvs snapshot (php5-200511170930). 
Configure string was "./configure --with-apxs2=/usr/local/sbin/apxs".
$ grep php httpd.conf
LoadModule php5_module /usr/home/samm/src/php/php5-200511170930/libs/libphp5.so
DirectoryIndex index.php index.html index.html.var
AddType application/x-httpd-php .php .phtml

test.php content:
<?
echo "getcwd() output='".getcwd()."'";
phpinfo();
?>

You can see result of this script, which i uploaded to my server:

test.php output when requested as test.html:
http://www.uba.ua/test/phptest/test.html.out.html
test.php output when requested as test.php:
http://www.uba.ua/test/phptest/test.php.out.html

I hope, this help you and you will not ask me again if i use latest php ;-)
 [2005-11-17 22:11 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

Hopefully fixed in CVS.
Please test it once again and confirm.
 [2005-11-17 23:19 UTC] samm at os2 dot kiev dot ua
Tested with php5-200511171930 - nothing changed, bug is still present :(
 [2005-11-17 23:30 UTC] tony2001@php.net
Download a snap in the morning, the fix didn't get into this snapshot (Ilia has committed it only 1.5 hours ago).
 [2005-11-17 23:39 UTC] adsh at univ dot kiev dot ua
I test php4-STABLE-200511172154/libs/libphp4.so.

Problem fixed. Thanks.
 [2005-11-17 23:43 UTC] tony2001@php.net
Great.
Fixed -> closed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 15:01:36 2024 UTC