kukymbr
kukymbr

Reputation: 185

PHP ini_set open_basedir has no effect

I've got this problem on my Ubuntu + PHP 7.0.18 + Apache2: In my php.ini is set the open_basedir = /var/www:/tmp. It works fine. But in one web app I need to use another dirs to work with. I am trying to set it through ini_set:

ini_set(
    'open_basedir',
    implode(
        PATH_SEPARATOR,
        array(
            __DIR__,
            '/media/hdd/backup/db'
        )
    )
);

But it has no any effect:

echo ini_get('open_basedir'); // shows /var/www:/tmp

If value of open_basedir in php.ini is empty, this code works fine. Is it an expected behaviour or I'm doing something wrong?

Upvotes: 1

Views: 6503

Answers (1)

Alex Howansky
Alex Howansky

Reputation: 53646

open_basedir can't be set arbitrarily at runtime via ini_set(), it can only be tightened to a lower dir:

As of PHP 5.3.0 open_basedir can be tightened at run-time. This means that if open_basedir is set to /www/ in php.ini a script can tighten the configuration to /www/tmp/ at run-time with ini_set(). When listing several directories, you can use the PATH_SEPARATOR constant as a separator regardless of the operating system.

Your call to ini_set() should be returning false to indicate that it has failed.

Upvotes: 4

Related Questions