Search Our Database

How to solve the WordPress open_basedir restriction error

Last updated on |

Introduction

The “open_basedir restriction” error in WordPress occurs when the server restricts PHP from accessing certain directories outside the specified paths. This error is significant because it can prevent WordPress from functioning correctly, especially in file management and uploads. This guide explains how to fix the open_basedir restriction error in WordPress by adjusting server settings or configuration files. It is ideal for site administrators and developers facing file access issues.

The error you may encounter will be like:

  • 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.

 

Prerequisite

  • SSH access to server with root privileges
  • Knowledge on Linux/Unix command
  • Knowledge on PHP configuration
  • Knowledge on server configuration
  • Knowledge on website structure

 

Step-by-step guide

Method 1: Disable open_basedir in PHP

  • If you were using control panel like DirectAdmin or cPanel or having multiple websites in the server, you may skip this and proceed to Method 2. Because this method will be applied globally and will affecting to other users or websites.

 

  • SSH into your server and gain root privileges.
    sudo su -

 

  • Locate your PHP configuration file, look for the file shows after Loaded Configuration File =>.
    php -i | grep ini

 

  • Edit the PHP configuration file from the last step and look for open_basedir directive.
    vi /etc/php.ini

     

  • If you see there is ; in front, means that the open_basedir was disabled by default. Else, you may disable it by adding ; in front and its text color turns blue. Press i enter edit mode and press ESC and :wq to save.

 

  • Alternatively, you may define your new website root directory.
    For example – open_basedir = /var/www/html/:/tmp/:/var/www/html/wordpress/uploads/
    Details breakdown:

    • /var/www/: This directory is typically where web server files are stored. By including this directory in open_basedir, you allow PHP scripts to access any file within the /var/www/ directory and its subdirectories. This usually includes your WordPress files.
    • /tmp/: The /tmp/ directory is used for temporary files. Including this in open_basedir allows PHP to read and write temporary files, which are often needed during operations such as uploading files, caching, and session handling.
    • /var/www/wordpress/uploads/: This is a placeholder for a specific directory, likely representing the uploads directory of your WordPress site (typically /var/www/html/wp-content/uploads/). Including this ensures that WordPress and any plugins can access this directory to handle file uploads, such as images or documents.

 

  • Then restart your PHP service to apply the new configuration.

 

  • If this method is not resolved the error, revert the changes you made and continue on Method 2 or Method 3.

 

Method 2: Disable open_basedir in .htaccess

  • SSH into your server and gain root privileges.
    sudo su -

    If you were using control panel like DirectAdmin or cPanel and didn’t have root privileges, you may switch to your control panel username.

    sudo su <username>

 

  • Navigate to your website root directory. Verify if the .htaccess file existed. If not exist, you may need to create new .htaccess.
    ls -la | grep htaccess

    To create .htaccess file.

    touch .htaccess
    chown <username>:<username> .htaccess
    chmod 644 .htaccess

     

  • Edit .htaccess file.
    vi .htaccess

     

  • Add the line below in it. Press i enter edit mode and press ESC and :wq to save.
    php_value open_basedir none

 

  • If this method is not resolved the error, revert the changes you made and you may continue on Method 3.

 

Method 3: Redefined upload path in wp-config.php

  • SSH into your server and gain root privileges.
    sudo su -

    If you were using control panel like DirectAdmin or cPanel and didn’t have root privileges, you may switch to your control panel username.

    sudo su <username>

 

  • Navigate to your website root directory and edit wp-config.php.
    vi wp.config.php

 

  • Add the line below in wp-config.php under /* Add any custom values between this line and the “stop editing” line. */. Press i enter edit mode and press ESC and :wq to save.
    define('UPLOADS', '/wp-content/uploads');

 

  • If none of the methods resolved the error, we would suggest you seeking the help from your web developer or your server hosting company.

 

Conclusion

By going through this guidance, you should be able to fix the open_basedir restriction error, enabling WordPress to access necessary directories and function without interruptions.

 

For additional assistance or if you encounter any issues, please contact our support team at support@ipserverone.com.

 

Article posted on 22 February 2020 by Louis