|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21044 getcwd() returns empty string (not always)
Submitted: 2002-12-16 08:04 UTC Modified: 2003-01-18 10:00 UTC
From: miki at ceti dot pl Assigned:
Status: Closed Package: Directory function related
PHP Version: 4.3.0RC3 OS: Linux, 2.2.22
Private report: No CVE-ID: None
 [2002-12-16 08:04 UTC] miki at ceti dot pl
getcwd() works only within pages in 'main' document root.
Pages under user directories (/~user/) and pages located in every virtual host directory doesn't get proper getcwd().

It results in include() and reqiure() using relative paths not working. Bug came out when I was trying to install fresh copy of postnuke.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-16 08:49 UTC]
Could you please show the parameters you've passed to PHP's configure script, they can be found inside config.nice.
 [2002-12-16 08:56 UTC] miki at ceti dot pl
According to phpinfo():
./configure --with-apxs=/usr/local/apache/bin/apxs --without-pear --with-zlib --with-dom --without-xml --with-expat-dir=/usr/local --with-iconv=/usr/local --with-curl --with-pgsql=/usr/local/pgsql --enable-ftp

Full phpinfo() output can be found at:

Now that site is running 4.3.0-pre1, but it behaves the same like 4.3.0rc3 I tested it on (with the same configure parameters).
 [2002-12-16 10:17 UTC]
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.

I've tries the latest 4.3.0 stable CVS and cannot replicate the bug. getcwd() on non-zts installs uses the native getcwd() provided by your libc, so the virtual host or simular things will have no affect on it.
 [2002-12-18 09:48 UTC] miki at ceti dot pl
I've got the solution! After hacking php sources for a few hours (ok, minutes...) I've found the solution:

I had to add '#define VIRTUAL_DIR 0' line just before '#ifdef VIRTUAL_DIR' condition in TSRM/tsrm_virtual_cwd.h file. 

To my surprise defined values (0 wether 1) has no effect. I just had to add that define. Now everything works.

Well, maybe it's my gcc fault. I'm using quite an old one:

Thanks for your time.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Sep 22 06:23:17 2021 UTC