I am getting "open_basedir" error in the PHP script. How do I fix this error?

Article ID: 432 
Last Review: Oct,6 2008
Author: APPLIES TO:
  • Plesk for Linux/Unix

Cause

This error means that PHP script tries to access a folder that is not allowed for access. For security reasons PHP options for hosted domains in Plesk allow access to /tmp and http(s)docs folders only by default. The restrictions are limited by open_basedir PHP variable for each virtual host separately.


Resolution

If you need to allow access for PHP scripts of specific virtual host to additional folder(s), 'open_basedir' option for the virtual host should be re-defined with new path value, several folder names are splitted by a colon. It can be done by user with root privileges only in domain's vhost.conf or vhost_ssl.conf (for SSL virtual host) files, see 'Including Directives into Web Server Configuration File' article in Plesk documentation for details.

 

Once the changes are made you need to rebuild Apache configuration files and restart Apache service using the following command in the shell, if vhost(_ssl).conf file is found, it will automatically be added to domain's httpd.include file:

# /usr/local/psa/admin/sbin/websrvmng -v -a

Examples:

 

NOTE: HTTPD_VHOSTS_D should be replaced with a real path to domain homes which may vary depending on Plesk version and OS, the current value can be known from /etc/psa/psa.conf file. ADD_PATH should be replaced with a real path to folder you need to allow access to.

 

Create HTTPD_VHOSTS_D/domain.com/conf/vhost.conf:

<Directory HTTPD_VHOSTS_D/domain.com/httpdocs>
php_admin_value open_basedir "HTTPD_VHOSTS_D/domain.com/httpdocs:/tmp:/ADD_PATH"
</Directory>

 

Create HTTPD_VHOSTS_D/domain.com/conf/vhost_ssl.conf:

<Directory HTTPD_VHOSTS_D/domain.com/httpsdocs>
php_admin_value open_basedir "HTTPD_VHOSTS_D/domain.com/httpsdocs:/tmp:/ADD_PATH"
</Directory>

 

For subdomains create HTTPD_VHOSTS_D/domain.tld/subdomains/subdomain/conf/vhost.conf file accordingly:

<Directory HTTPD_VHOSTS_D/domain.com/subdomains/subdomain/httpdocs>
php_admin_value open_basedir "HTTPD_VHOSTS_D/domain.com/subdomains/subdomain/httpdocs:/tmp:/ADD_PATH"
</Directory>

 

Also, you can set global 'open_basedir' for some needed location in /etc/php.ini, for example:

open_basedir = "/tmp"


Restart Apache after php.ini changing.
Subscription for this article changesSubscription for this article changes

Please provide feedback on this article

Did this article help you solve your issue?
Yes
No
Partially
I do not know yet
 
Strongly Agree   Strongly Disagree
  9 8 7 6 5 4 3 2 1
The article is easy to understand
The article is accurate
Additional Comments:
*Please provide us with your email address in case we need to contact you.
captcha *Please type the code you can see.
* - required fields