109

I'm getting this error on an avatar upload on my site. I've never gotten it before and nothing was changed recently for me to begin getting this error...

Warning: is_writable() [function.is-writable]: 
open_basedir restriction in effect. 
File(/) is not within the allowed path(s):
markus
  • 40,136
  • 23
  • 97
  • 142
Ben
  • 60,438
  • 111
  • 314
  • 488
  • 1
    somebody please clarify if the currently accepted answer is the working one. and then @sjas, please edit or delete your comment. It's confusing. :| – Yogesh Oct 07 '21 at 11:36
  • @Yogesh it works fine. Of course, I'm using Plesk. I believe sjas was in error, although that might have been because he/she was using something other than plesk. I'm willing to assume by Ben accepting the answer that he's using Plesk, too. – JBH Apr 26 '22 at 02:09

20 Answers20

144

Modify the open_basedir settings in your hosting account and set them to none. Find the open_basedir setting given under 'PHP Settings' area of your Plesk/cPanel. Set it to 'none' from the dropdown given there. I have shown them in the Plesk panel picture.

enter image description here enter image description here

yogihosting
  • 5,494
  • 8
  • 47
  • 80
  • 2
    @yogihosting after doing this i got error - Unable to locate the model you have specified: Home_model – Heemanshu Bhalla Apr 28 '16 at 11:31
  • 1
    Bit late to this, but is there a way to do that for all plesk sites? I have it set to none in the global php.ini for the version the sites are using: https://gyazo.com/dfffbe7f9b3a20ede97da72f1ddfc777 But they still get the error. – Matt Cowley Jul 24 '16 at 09:47
  • @MattCowley you have to do this for each and every site hosted in plesk panel. – yogihosting Jul 27 '16 at 19:31
  • even I also also followed this answer and started getting error – Saurabh Mar 06 '23 at 14:50
40

To resolve this error, you must edit the file httpd.conf. Way before it can be seen in phpinfo in apache2handler section directive Server Root. For example, in my case this way - / etc / httpd / httpd.conf. Open the file httpd.conf, find the mention of the parameter open_basedir. And set it to none. (php_admin_value open_basedir none)

Andrei
  • 1,125
  • 2
  • 15
  • 29
13

If you're running this with php file.php. You need to edit php.ini Find this file:

: locate php.ini
/etc/php/php.ini

And append file's path to open_basedir property:

open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/:/run/media/andrew/ext4/protected

deathangel908
  • 8,601
  • 8
  • 47
  • 81
  • 4
    This is the only solution that points to multiple specific paths instead of just skipping security altogether. – mvreijn Dec 03 '19 at 09:14
7

Laravel

If you have this problem when using Laravel.

Only go to folder bootstrap/cache and rename config.php to anything you want and reload site.

Mahdi Bashirpour
  • 17,147
  • 12
  • 117
  • 144
5

For me the problem was bad/missing config values for the Plesk server running the whole thing. I just followed the directions here: http://davidseah.com/blog/2007/04/separate-php-error-logs-for-multiple-domains-with-plesk/

You can configure PHP to have a separate error log file for each VirtualHost definition. The trick is knowing exactly how to set it up, because you can’t touch the configuration directly without breaking Plesk. Every domain name on your (dv) has its own directory in /var/www/vhosts. A typical directory has the following top level directories:

cgi-bin/
conf/
error_docs/
httpdocs/
httpsdocs/
...and so on

You’ll want to create a vhost.conf file in the domain directory’s conf/ folder with the following lines:

php_value error_log /path/to/error_log
php_flag display_errors off
php_value error_reporting 6143
php_flag log_errors on

Change the first value to match your actual installation (I used /tmp/phperrors.log). After you’re done editing the vhost.conf file, test the configuration from the console with:

apachectl configtest
…or if you don’t have apachectl (as Plesk 8.6 doesn’t seem to)…

/etc/init.d/httpd configtest

And finally tell Plesk that you’ve made this change.

/usr/local/psa/admin/bin/websrvmng -a
James Williams
  • 4,221
  • 1
  • 19
  • 35
Josh P
  • 1,325
  • 14
  • 12
3

If used ispconfig3:

Go to Website section -> Options -> PHP open_basedir:

enter image description here

  • In this field has described allowed paths and each path is separated with ":"

/var/www/clients/client2/web3/image:/var/www/clients/client2/web3/web:/var/www/... and so on

  • So here must put the path that you want to have access, in my case is:

/var/www/clients/client2/web3/image:

  • The problem appears because:

When a script tries to access the filesystem, for example using include, or fopen(), the location of the file is checked. When the file is outside the specified directory-tree, PHP will refuse to access it.

Pavel Kenarov
  • 944
  • 1
  • 9
  • 21
3

For Plesk, you can change or set the openbase dir settings via the panel

https://support.plesk.com/hc/en-us/articles/360006170513-How-to-add-custom-or-additional-path-to-the-open-basedir-option-for-Plesk-domain-

enter image description here

Arun Prasad E S
  • 9,489
  • 8
  • 74
  • 87
2

The path you're refering to is incorect, and not withing the directoryRoot of your workspace. Try building an absolute path the the file you want to access, where you are now probably using a relative path...

NDM
  • 6,731
  • 3
  • 39
  • 52
2

I had this problem @ one of my wordpress sites after updating and/or moving.

Check in database table 'wp_options' the 'upload_path' and edit it properly...

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Bartuzz
  • 829
  • 6
  • 7
2

Edit the php.ini or .user.ini that is located within the main directory

open_basedir = none
Chaturanga
  • 78
  • 5
2

I had this kind of problem with ispconfig3 and got an error like this

open_basedir restriction in effect. File(/var/www/clients/client7/web15) is not within the allowed path(s):.........

To solve it in my case, I just set PHP to SuPHP in the Website's panel of ispconfig3

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Qlimax
  • 5,241
  • 4
  • 28
  • 31
0

If you are running a PHP IIS stack and have this error, it is usually a quick permission fix.

If you administer the windows server yourself and have access, try this FIRST:

Navigate to the folder that is giving you grief on writing to and right click it > open properties > security.

See what users have access to the folder, which ones have read only and which have full. Do you have a group that is blocking write?

The fix will be specific to your IIS setup, are you using Anonymous Authentication with specific user IUSR or with the Application Pool identity?

At any rate, you are going to end up adding a new full write permission for one of IUSR, IIS_IUSRS, or your application pool identity - like I said, this is going to vary depending on your setup and how you want to do it, you can go down the google rabbit hole on this one (one such post - IIS_IUSRS and IUSR permissions in IIS8) For me, i use anon with my app pool identity so i can get away with MACHINE_NAME\IIS_IUSRS with full read/write on any temp or upload folders.

I do not need to add anything extra to my open_basedir = in the php.ini.

RobDigital
  • 515
  • 1
  • 7
  • 19
0

In addition to @yogihosting's answer, if you are using DirectAdmin, then follow these steps:

  1. Go to the DirectAdmin's login page. Usually, its port is 2222.
  2. Login as administrator. Its username is admin by default.
  3. From the "Access Level" on the right panel, make sure you are on "Admin Level". If not, change to it.
  4. From the "Extra Features" section, click on "Custom HTTPD Configurations".
  5. Choose the domain you want to change.
  6. Enter the configurations you want to change in the textarea at the top of the page. You should consider the existing configuration file and modify values based on it. For example, if you see that open_basedir is set inside a <Directory>, maybe you should surround your change in the related <Directory> tag:

    <Directory "/path/to/directory">
        php_admin_value open_basedir none
    </Directory>
    
  7. After making necessary changes, click on the "Save" button.

  8. You should now see your changes saved to the configuration file if they were valid.

There is another way of editing the configuration file, however:

Caution: Be careful, and use the following steps at your own risk, as you may run into errors, or it may lead to downtime. The recommended way is the previous one, as it prevents you from modifying configuration file improperly and show you the error.

  1. Login to your server as root.
  2. Go to /usr/local/directadmin/data/users. From the listed users, go to one related to the domain you want to change.
  3. Here, there is an httpd.conf file. Make a backup from it:

    cp httpd.conf httpd.conf.back
    
  4. Now edit the configuration file with your editor of choice. For example, edit existing open_basedir to none. Do not try to remove things, or you may experience downtime. Save the file after editing.

  5. Restart the Apache web server using one of the following ways (use sudo if needed):

    httpd -k graceful
    apachectl -k graceful
    apache2 -k graceful
    
  6. If your encounter any errors, then replace the main configuration file with the backed-up file, and restart the web server.

Again, the first solution is the preferred one, and you should not try the second method at the first time. As it is noted in the caution, the advantage of the first way is that it prevents saving your bad-configured stuff.

Hope it helps!

MAChitgarha
  • 3,728
  • 2
  • 33
  • 40
0

I am using an Apache vhost-File to run PHP with application-specific ini-options on my windows-server. Therefore I use the -d option of the php-command.

I am setting the open_basedir for every application as one of these options.

I needed to set multiple urls as open_basedir, including an UNC-Path, and the syntax for this case was a bit hard to find. You have to seperate the paths with semicolons and if your first path starts with a driveletter you might have to start the list with a semicolon too. At least that's what works for me.

Example:

php.exe -d open_basedir=;d:/www/applicationRoot;//internal.unc.path/ressource/
Fanax
  • 127
  • 3
  • 8
0

I uploaded my codeigniter project on Directadmin panel. I was getting same error. error

Then I change in php settings.

open_basedir = session.save_path = ./temp/

Then it worked for me.

infomasud
  • 2,263
  • 1
  • 18
  • 12
0

As most do not find a solution, the solutions are broad for WordPress most even don't know fully why things are they are.

I've found out you will have to enable IP for your server in especially when using Cerber in some cases it can think you are not uploading .png instead you are uploading .js files.

The server IP needs to be whitelisted. Even the uploaders in some rare cases.

A great to know is to have a tmp folder 755 in your base directory, you actually do not need a folder called tmp.: "Also remember / properly inedited as below:

open_basedir = "/home/user/site.com/:/tmp"
upload_tmp_dir = /home/user/site.com/tmp

The best option for quick setup is in Cpanel where you use the MultiPHP INI Editor you can actually save and both .htaccess and php.ini will be updated as well as settings being initiated at the same time on site.

It's NOT recommended to have basedir as "none" since you are enabling root files that can be edited with just a single file editor in WordPress. If that truly is possible.

Dealazer
  • 59
  • 4
0

For me it is because I gave the wrong path in the tmp directory of php.

Hope this helps

Jom Apps
  • 1
  • 1
-1

Check \httpdocs\bootstrap\cache\config.php file in plesk to see if there are some unwanted paths.

-3

Just search

open_basedir =

in php.ini and disable it. That's the simplest solution to solve this issue.

Before Changes open_basedir =

After Changes ;open_basedir =

P.s - After changes don't forget to restart your server.

Enjoy ;)

Lalit Giriya
  • 312
  • 1
  • 9
  • 4
    don't do this... security is, believe it or not, *important.* :) Time to read docs on your tools: http://php.net/manual/en/ini.core.php#ini.open-basedir – Adam Lenda Dec 17 '18 at 15:49
-29

Modify the open_basedir settings in your PHP configuration (See Runtime Configuration).

The open_basedir setting is primarily used to prevent PHP scripts for a particular user from accessing files in another user's account. So usually, any files in your own account should be readable by your own scripts.

Example settings via .htaccess if PHP runs as Apache module on a Linux system:

<DirectoryMatch "/home/sites/site81/">
    php_admin_value open_basedir "/home/sites/site81/:/tmp/:/"
</DirectoryMatch>
hakre
  • 193,403
  • 52
  • 435
  • 836
Nikesh
  • 359
  • 3
  • 3
  • This was useful for me when I copied some files from a centos server to my local development osx machine. – Aspelund Jan 12 '12 at 02:16
  • 3
    @Nikesh This gave me a 500 error after I dropped it into my .htaccces and changed the paths to: `/my/cutsom/dir/`. Not sure why thought. – hitautodestruct Jan 24 '13 at 17:06
  • 83
    Cool, 12 upvotes so far for an incorrect answer. [You cannot use `php_admin_value` in `.htaccess` files](http://php.net/manual/en/configuration.changes.php). [You cannot use DirectoryMatch in .htaccess files](http://httpd.apache.org/docs/2.4/en/mod/core.html#directorymatch). (What kind of security measure would `open_basedir` be if it could just be disabled?) – Álvaro González Apr 24 '13 at 15:05
  • @ÁlvaroG.Vicario Do you have a solution, in that case? – eoinoc Jun 17 '13 at 09:53
  • 1
    @eoinoc - Scroll down and see e.g. Andrei's answer. Or edit global php.ini file. – Álvaro González Jun 17 '13 at 11:06
  • 21
    YOU DO NOT PUT THIS INTO YOUR HTACCESS! BUT RATHER INTO YOUR APACHE CONFIG FILE. – tfont Aug 23 '13 at 20:00
  • 10
    Including the root directory in open_basedir defeats the purpose of open_basedir entirely. This solution only "works" in the sense that it essentially disables the restriction. – Martin Oct 16 '13 at 21:20
  • the `:/` is important – Patrioticcow May 01 '14 at 17:02
  • This Just Doesn't work. adding above code to .htaccess gives 500 error. – Chakri Jun 26 '14 at 17:17
  • @ÁlvaroG.Vicario That depends on how the web server is configured. On some servers you can. – RobinJ Aug 25 '14 at 18:49
  • I have sample problem with Yii 2 Framewor, that error http://prntscr.com/gcu17k . so how can i fix it. – dungphanxuan Aug 25 '17 at 09:13
  • allow root dir it is a worst idea ever! – Urgotto Oct 26 '18 at 11:56
  • 2
    Downvoting an answer that shows working config file syntax while upvoting a shared hosters web gui screenshot. Only true php developers could do this. – ohcibi Oct 31 '18 at 09:39