Bug #17535
closedindex.php assumes current working directory to be PATH_site
0%
Description
After a recent PHP upgrade from 5.1.2-r3 to 5.2.4_pre200708051230-r2 on Gentoo Linux, the Typo3 frontend suddenly stopped working. After some investigation it turned out that the current working directory used in index.php is no longer the link source directory "PATH_site/", but the link target "/path/to/typo3_src/". Therefore, the relative paths used to include libraries via TS, like in my case templavoila, were no longer found.
Attached patch changes the current working directory to PATH_site at the very beginning of index.php. Thus, the assumptions about the CWD are fulfilled again.
It might be that this is a Gentoo specific PHP issue. After all, they seem to use a pre-release. However, clarifying the made assumptions about the CWD does not harm either.
Maybe someone with a test server can check PHP's beavhiour regarding the CWD of linked files in different versions. Consider the following test setup:
$ mkdir $HTDOCS/bar/
$ echo ' print getcwd(); ?>' > $HTDOCS/bar/foo.php
$ ln -s $HTDOCS/bar/foo.php $HTDOCS/foo.php
It seems that the expected and old output of http://host/foo.php is "$HTDOCS". In my setup however, the output is "$HTDOCS/bar".
Setup: Apache 2.2.4-r11 with mod_fcgid and PHP 5.2.4_pre200708051230-r2 (FastCGI) on Gentoo Linux.
(issue imported from #M6158)
Files
Updated by Christian Hoffmann about 17 years ago
Peter, Thanks for the extensive bug description and the patch. I just hit that problem as well and tracked it down further. It's not a Gentoo-specific problem (we just got hit by it first as we are packaging this snapshot).
It was this commit: http://cvs.php.net/viewcvs.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.267.2.15.2.42&r2=1.267.2.15.2.43&pathrev=PHP_5_2 (Fixed bug #40419 (Trailing Slash in CGI request don't work)).
I think this is a pretty important behaviour change and may have been unintended. Please report such changes/bugs to our bugzilla (http://bugs.gentoo.org) if you are not sure whether it is Gentoo-specific and in any other cases to http://bugs.php.net/
Thanks.
Also, I just sent a mail to Dmitry (who made that commit), CCing Ilia (5.2 RM) to make sure this is really intended. If it is, your patch should probably applied as a lot of installations are likely to break otherwise.
Updated by Christian Hoffmann about 17 years ago
Current status is that this bug will probably not fixed for 5.2.4, but in a later version...
Including Peter's patch into the official Typo3 source would probably be a good idea since it will be a long time to 5.2.5, I guess.
Updated by Oliver Hader about 17 years ago
The link to the PHP bug:
http://bugs.php.net/bug.php?id=40419
The C-patch shows that it only happens if cgi.fix_pathinfo in php.ini is enabled.
From http://www.php.net/manual/en/ini.core.php:
<b>cgi.fix_pathinfo boolean</b>
Provides real PATH_INFO/PATH_TRANSLATED support for CGI. PHP's previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting this to 1 will cause PHP CGI to fix it's paths to conform to the spec. A setting of zero causes PHP to behave as before. Default is zero. You should fix your scripts to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
Updated by Michael Stucki about 17 years ago
Thanks to Peter for providing a workaround. However, I'm not sure if this could have any side effects. And even if not, it's clearly a PHP bug which will hopefully get fixed quite soon.
I suggest to leave this patch out of TYPO3core and patch affected installations manually until PHP has fixed the issue.
Updated by Michael Stucki about 17 years ago
Reopening this bug to make it possible to add more comments on this.
Updated by Ingmar Schlecht about 17 years ago
What about only doing the chdir(PATH_site) only for the specific PHP versions affected:
Pseudo code:
if(php version > 5.2 && cgi.fix_pathinfo) {
chdir(PATH_site);
}
Updated by Michael Stucki about 17 years ago
Agreed. Who's gonna update the patch?
Updated by Christian Hoffmann about 17 years ago
Dmitry (Zend) asked me to open a php bug, so I filed http://bugs.php.net/bug.php?id=42587
Until now I didn't manage to get Typo3 working without patching PHP (i.e. above patch doesn't work for me). I'll try to track it down further.
Updated by Christian Hoffmann about 17 years ago
Really too lazy to dig through the whole Typo3/TS/TemplaVoila code, I'm now using the simplest workaround: Don't use a index.php symlink, just copy the file from typo3_src/. Shouldn't cause too many problems with updates as this file doesn't look like it's subject to heavy changes.
Updated by Bjrn Kraus about 17 years ago
Here is the code:
if (version_compare(PHP_VERSION, '5.2', '>') && ini_get('cgi.fix_pathinfo') == '1')
chdir(PATH_site);
@Michael:
If you agree with this I will post a patch file for it.
Updated by Michael Stucki about 17 years ago
So Chrstian says that you can work around the issue while Björn prefers the fix. What should we do?
Updated by Bjrn Kraus about 17 years ago
As I posted on the list, the php.ini setting doesn't work for me running php as fastcgi. The fix seems to be the only solution that works for all configurations.
Updated by Bjrn Kraus about 17 years ago
The php bug has been fixed in svn (see http://bugs.php.net/bug.php?id=40419 ). Perhaps someone can give it a try.
Updated by Christian Hoffmann about 17 years ago
The fix from php-cvs works for me. Anybody who hits the problem should just apply http://cvs.php.net/viewcvs.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.267.2.15.2.48&r2=1.267.2.15.2.49&pathrev=PHP_5_2 and recompile...
For Gentoo, we are going to include this patch in our next revision (php-5.2.4-r1).
Updated by Bjrn Kraus almost 17 years ago
I'm currently testing the new PHP version. The bug seems to be fixed in PHP 5.2.5. There is no patching of index.php needed anymore.
Updated by Oliver Hader almost 17 years ago
I can confirm this on PHP 5.2.4-2+b1/Debian with fcgid.
Updated by Oliver Hader almost 17 years ago
Summary: This PHP bug was introduced in 5.2.4 and fixed in 5.2.5.
However, Debian delivers 5.2.4-2+b1 which still contains this bug.
The behaviour only occours if cgi.fix_pathinfo is set (thus CGI mode only), as it can be seen in sapi/cgi/cgi_main.c.
The attached patch checks the PHP versions, the PHP setting and if the current directory is different to PATH_site. If these conditions are met, the chdir(PATH_site) is executed.
Updated by Oliver Hader almost 17 years ago
Had logical bug in first patch. New version attached.
Updated by Oliver Hader almost 17 years ago
Debian/Testing has now "PHP 5.2.5-2" which doesn't have the PHP bug anymore.
Since there is not much feedback concerning this issue anymore, I tend to drop the RFC in the Core List. But whoever it needs the patch is still here in the bugtracker.
Updated by Maldonado over 16 years ago
I can confirm this issue with the php5-cgi (5.2.4-2ubuntu5) version, that is delivered with Ubuntu 8.04 Hardy Heron.
Setting cgi.fix_pathinfo = 0 in the php.ini file fixes it.
Updated by Michael Stucki over 16 years ago
I think that this is closely related to bug #14692 and although it's not exactly the same problem, it could likely be solved with the same change.
I never liked the way of chdir()'ing into PATH_site, I rather think that non-absolute paths are wrong and need to be fixed.
Please check if the patch in #14692 solves your problem as well.
Updated by Oliver Hader over 15 years ago
This issue is dropped since it was a work-around for a PHP misbehaviour.