If no value is declared for open_basedir in php.ini, PHP uses the default:

/var/www/vhosts/mydomain.com/httpdocs:/tmp

If I add

open_basedir=myadditionalpath/

to an ini file inside php.d directory, will that value override the defaults?
Or will it merely add another directory to the defaults?

    Easiest answer would be: try it and do a phpinfo() to find out.

      I did. The good news is that PHP just adds the directory to the defaults.
      phpinfo() reports:

      open_basedir = /var/www/vhosts/ourdomain.com/lib:
      /temp:
      /var/www/vhosts/ourdomain.com/httpdocs

      The bad news is that I cannot access that lib directory from inside web root.

      include_once('lib_test.php');
      include_once('../lib/lib_test.php');
      include_once('/var/www/vhosts/ourdomain.com/lib/lib_test.php');

      All of these fail, even though open_basedir is set to that directory.
      Any ideas?

        What's the exact PHP error message you get when you try those include()'s?

          These are the errors for each include call.

          include_once(lib_test.php)
          Error: No such file or directory. open_basedir restriction in effect. File(../lib/lib_test.php) is not within the allowed path(s).

          include_once(../lib/lib_test.php)
          Error: Operation not permitted. open_basedir restriction in effect. File(/var/www/vhosts/ourdomain.com/lib/lib_test.php) is not within the allowed path(s).

          include_once(/var/www/vhosts/ourdomain.com/lib/lib_test.php)
          Error: Operation not permitted

          However, once again, phpinfo() specifically lists /var/www/vhosts/ourdomain.com/lib/ within the allowed paths.

            That's... interesting. First of all, note that changing the open_basedir directive doesn't effect where PHP looks for files, so you still have to use a valid path to include this file (which is why the first error message said there was "no such file.")

            I'm still a bit puzzled as to why the second two wouldn't work. Have you tried restarting your webserver?

            Try using nothing but the third include example you posted above, and also insert the following code just after it:

            echo "-- open_basedir: " . ini_get('open_basedir') . " --";

            and paste what it outputs.

            EDIT: I also note that you're editing the paths to remove your domain name; double (and triple) check that both the include path as well as the open_basedir path you added are typed correctly - I've had a simple typo be the bane of my existence more than a couple of times in a similar situation. :p

              bradgrafelman;10915785 wrote:

              Have you tried restarting your webserver?

              Well, I restarted Apache.

              double (and triple) check that both the include path as well as the open_basedir path you added are typed correctly - I've had a simple typo be the bane of my existence more than a couple of times in a similar situation. :p

              I know what you mean. Thanks. I did triple check.

              Try using nothing but the third include example you posted above, and also insert the following code just after it:

              echo "-- open_basedir: " . ini_get('open_basedir') . " --";

              and paste what it outputs.

              Here is what it gave me:
              Warning: include_once() [function.include-once]: open_basedir restriction in effect. File(/var/www/vhosts/ourdomain.com/lib/lib_test.php) is not within the allowed path(s): (/var/www/vhosts/ourdomain.com/httpdocs:/tmp) in /var/www/vhosts/ourdomain.com/httpdocs/index.php on line 14

              Warning: include_once(/var/www/vhosts/ourdomain.com/lib/lib_test.php) [function.include-once]: failed to open stream: Operation not permitted in /var/www/vhosts/ourdomain.com/httpdocs/index.php on line 14

              Warning: include_once() [function.include]: Failed opening '/var/www/vhosts/ourdomain.com/lib/lib_test.php' for inclusion (include_path='.:') in /var/www/vhosts/ourdomain.com/httpdocs/index.php on line 14
              -- open_basedir: /var/www/vhosts/ourdomain.com/httpdocs:/tmp --

              I just confirmed this line in /etc/php.ini:
              open_basedir = /var/www/vhosts/ourdomain.com/httpdocs:/var/www/vhosts/ourdomain.com/lib:/tmp

              I just now ran phpinfo() again, just to be sure, and it reports:
              open_basedir
              local value
              /var/www/vhosts/ourdomain.com/httpdocs:/tmp
              master value
              /var/www/vhosts/ourdomain.com/lib

              So... I remain puzzled.

                Aha, you didn't paste the exact phpinfo() output before. Note that the local vs. master values don't both apply - only the "local value" is going to be applied to your scripts. As you can see, something is altering this PHP directive from the "master" (or default php.ini-supplied) value.

                Is there perhaps an .htaccess file (or another php.ini) somewhere in the directory hierarchy (e.g. start at your home folder and work your way down to this specific folder) that is altering this PHP directive (e.g. via php_value)?

                  It was a Plesk thing.

                  Our installation of the Plesk CP (9.2.1) does not initialize PHP with the usual php.ini or even in /php.d/. Instead, you must
                  (1) declare your settings in /yourdomain/conf/vhost.conf
                  (2) reset admin/sbin/websrvmng
                  (3) restart apache

                  Convoluted, but now everything works. Your suggestions to drop in a ini_get('open_basedir') and to look for interference from another directory paid off. Thanks.

                    Write a Reply...