2

EDIT: This is not a duplicate of open_basedir restriction in effect. File(/) is not within the allowed path(s):. This issue has nothing to do with the PHP settings, as I have several websites working under the same map structure and the same PHP settings. Please read the entire question before labelling it as a duplicate, as I have explained this in the final 4 paragraphs of this question. In addition, the answers in that other question are geared toward Apache, whereas I'm using Nginx, which does not use CPanel or httpd.conf.

I've manually moved my Wordpress sites to a new server. For the last one, I'm getting this error:

  Warning: is_dir(): open_basedir restriction in effect. File(/) is not
  within the allowed path(s):
    (/var/hpwsites/u_bcsautoborg:/usr/share/pear/) in 
    /var/hpwsites/u_bcsautoborg/website/html/webroot/wp-includes/functions.php on
 line 1585

I had a similar error with the site before, but that was due to the upload folder not being linked to correctly from the Wordpress settings. Thus, the error showed a different line number.

Line 1585 is:

while ( '.' != $target_parent && ! is_dir( $target_parent ) ) {

and is part of the larger block:

/*
     * Safe mode fails with a trailing slash under certain PHP versions.
     * Use rtrim() instead of untrailingslashit to avoid formatting.php dependency.
     */
$target = rtrim($target, '/');
if ( empty($target) )
    $target = '/';

if ( file_exists( $target ) )
    return @is_dir( $target );

// We need to find the permissions of the parent folder that exists


and inherit that.
    $target_parent = dirname( $target );
    while ( '.' != $target_parent && ! is_dir( $target_parent ) ) {
        $target_parent = dirname( $target_parent );
}

This is from a Wordpress functions file. Going from the code, I'd assume the issue is with $target_parent, but I don't know what that refers to, as I'm not very good with PHP.

Now I know an open_basedir restriction error generally means the PHP.ini file has incorrect security settings, which do not allow the PHP function to access the required folder. However, I'm certain that isn't the case here.

This was a working website, built around the same structure as all my other sites. All were hosted on an Apache server, and I'm moving to an Nginx server, and all have a directory of their own, with their own MySQL database, and all directories contain the same files and folders (apart from the website-specific folders of course). All other websites work perfectly in the same setup as this, and as such I can't imagine this being a php.ini issue.

In the previous case, where the issue was with the 'uploads' folder, I was still able to get into wp-admin and change the uploads folder location through the Wordpress settings. However, I'm unable to get into any page now, as I only get the above error, which duplicates to infinity.

I've disabled all plugins through PHPmyAdmin, but to no avail. Obviously, I've looked for a solution on SO, wordpress forums, Google and DuckDuckGo. I've found many similar issues, but none of the solutions I found worked for me.

Does anybody have any idea where the cause might be?

Community
  • 1
  • 1
Tijmen
  • 542
  • 1
  • 6
  • 29
  • 1
    I don't know where $target comes from, but it seems it was empty or equal to '/' instead of a string representing a path to an allowed file. Can't say much without the whole source code but i understand you can't post the Wordpress source here :) – Derek Jun 26 '16 at 14:55
  • 1
    Where is `$target` coming from? It makes sense that it's throwing an error because you surely don't want the app to have access to your root directory. – Jonathan Jun 26 '16 at 14:55
  • 1
    Found the source here: https://github.com/WordPress/WordPress/blob/master/wp-includes/functions.php but need the backtrace to know what is going on... – Derek Jun 26 '16 at 14:58
  • @Derek thanks for your replies so far. I'm unsure what you mean by 'backtrace'. Is this something I can retrieve, and if so, how? – Tijmen Jun 28 '16 at 17:12
  • @Derek @Jonathan I've looked at the source linked by Derek, but I notice that source is different from my `functions.php` file. Noticably; the line which produced the error on my website was 1585, but in the linked source, the content of line 1585 can be found on line 1609, whereas line 1585 in the linked source has a completely different content. It seems there might be something missing in my `functions.php`, could this be caused by an error during copying/pasting the files between servers? – Tijmen Jun 28 '16 at 17:17
  • @Tijmen maybe the source is different just because you have a different Wordpress version. To get the backtrace of the error you can install the xdebug extension for your PHP development environment. It will show all the methods called in the context of the error. – Derek Jun 28 '16 at 21:46
  • Sorry all for my delayed response, I have been away on holiday. I'm still not entirely sure what caused this issue, but I've resolved it by removing my website files and database from the server, and re-uploading everything. – Tijmen Jul 11 '16 at 09:14

2 Answers2

6

I had the same issue and came across this via a Google search. @hicham's comment above got me on the right track, here's how I was able to fix it in case others are looking. I edited the database via phpMyAdmin as follows:

  1. Click on the wp_options table
  2. Click Search, and enter "upload_path" in the "option_name" field
  3. This should return one row with your old host's path as the "option_value". Double-click the value to edit, and change it to the path of the "uploads" folder at your new host (you should be able to figure it out via FTP or your host's control panel).
Linn
  • 423
  • 5
  • 4
  • 1
    Thank you for this addition. For people who are unable to access the Wordpress dashboard, that might be a better solution than re-uploading everything like I did. – Tijmen Jun 28 '17 at 13:11
4

Warning: is_dir() [function.is-dir]: open_basedir restriction in effect. File(/) is not within the allowed path(s):

If you're receiving the above error message on a Wordpress blog, the likely cause is that you've had your site transferred to us from a previous hosting provider, and the paths to your home directory are now different. Fortunately, the fix is very simple.

Login to your Wordpress dashboard, click on 'Settings', then 'Miscellaneous' and ensure that the "Store uploads in this folder" option is set to:

wp-content/uploads

If it's already set to 'wp-content/uploads' (without quotes), simply hit the 'Save' button and Wordpress will recalculate your home directory path. The errors should now be gone and your site should work normally.

hicham
  • 41
  • 2
  • Thanks for trying to answer the question, but as outlined in the question, I had already done that for a different website, but for this website I wasn't able to even log in to the dashboard. – Tijmen Mar 06 '17 at 12:46
  • it works for wordpress. I forgot to switch off plugins , theme before transfer. Now I got what I deserved. Thanks for help tho. Peace! – Jarosław Cichoń Oct 16 '20 at 20:23