The WordPress Warning: open_basedir restriction in effect is a security restriction to prevent a user on a webserver to access files and folders that belong to another user.
As part of our Server Management Services, we assist our customers with several WordPress queries.
Today, let us see how we can fix this warning.
WordPress Warning: open_basedir restriction in effect
Generally, we come across these errors while accessing the site:
open_basedir restriction in effect. File(/tmp) is not within the allowed path(s).
Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/home/some/path/here/) is not within the allowed path(s).
Warning: is_writable() [function.is-writable]: open_basedir restriction in effect. File(/) is not within the allowed path(s).
Basically, the intention of this warning is to restrict another user from using our webserver.
For example, suppose, a function, say, mkdir in a WordPress theme or plugin tries to access a file or folder outside its home directory. It will not be able to access it and in effect, the error.
The fix to this error is multiple.
We can either disable the restriction completely or selectively allow access to some files and folders outside the home directory for some users.
Another option is to debug the code of the WordPress theme and plugin so that it doesn’t need to access files and folders outside its root folder.
Fix open_basedir restriction Error in WordPress
Moving ahead, let us see how our Support Techs fix this error.
1. Initially, we open the web-config file via FTP and add:
Here, we replace domain.com with our own domain name.
2. We then bowse the server files either via FTP or Panel
Then in the wp-content folder, we create a new folder with a name.
In addition, we ensure to give the writing rights to the folder.
After that, we go to the WordPress admin panel > Settings > Media.
Here, we change the path of uploading files with the name of the new directory we created.
This should help to work. However, if not, we suggest another step:
3. We create a new .htaccess file and overwrite the new file with the old file.
This time, it should definitely work.
Disable the PHP open_basedir restriction
On the other hand, if we don’t have either Cpanel WHM or Plesk on the VPS or dedicated hosting, we edit the Apache configuration file to disable the restriction.
To do this, we open httpd.conf file, and find the line:
php_admin_value open_basedir some_value_here
Then we replace it with:
php_admin_value open_basedir none
We ensure to make this change under the virtual host for the domain user account on which we want to disable the open_basedir protection.
We can allow the PHP scripts in any user account to access specific directories outside their home directory, without disabling the restriction completely.
To do so, to the httpd.conf file we add the below code:
php_admin_value open_basedir “/home/user_account/:/usr/local/lib/php:/tmp:/new_directory”
We can add directories by separating them with a colon (:) on Unix and Linux server and with a semicolon (;) on Windows servers.
Restart the Apache server after making any change to the httpd.conf file.
A rule of /dir/incl will also match /dir/includes. To make sure it matches the particular directory, we add a trailing slash, like /dir/incl/.
[Stuck with the fix? We are here for you]
In short, we saw how our Support Techs fix the WordPress warning for our customers.