2

I'm currently getting an open_basedir restriction error on my CakePHP application running on Media Temple. (site number and domain changed for purpose of question).

I've read the docs here: https://kb.mediatemple.net/questions/514/How+do+I+set+the+path+for+open_basedir%3F#gs for how to fix this problem.

I've tried the following in my php.ini file:

open_basedir = /home/00000/domains

But still get the same error. Which is as follows:

Warning (2): file_exists(): open_basedir restriction in effect. File(/home/00000/domains/test.com/html/app/webroot/index.php/img/cameron.jpg) is not within the allowed path(s): (/home/00000/domains) [APP/Plugin/Timthumb/Vendor/timthumb.php, line 896]

Any ideas?

The change is definitely being applied as the error path is updated to what I have specified above, but I still get the open_basedir restriction. And doing phpinfo() shows the change as well:

enter image description here

Update: Media Temple doesn't offer support for this, but has been courtesy enough to provide some help and said that I need to do the following:

open_basedir = "/home/00000/data/tmp:/home/00000/domains"

However this STILL does not work! And they are unable to provide further info.

Update 2: Mod_rewrite is enabled, and I'm using this Plugin: https://github.com/vishal-logiciel/TimthumbPlugin/

Cameron
  • 27,963
  • 100
  • 281
  • 483
  • Are you running without mod rewrite (please confirm by editing the question)? You look to have an application error, `File/(...index.php/attachments...` - the file `Plugin/Timthumb/Vendor/timthumb.php` is attempting to check if the _path_ `index.php/etc` exists in the webroot - it's not pointing at a writable path at all. – AD7six Mar 06 '14 at 11:12
  • Mod_rewrite is enabled. And it's using CakePHP, and it does routing through that index.php as far as I know. – Cameron Mar 06 '14 at 11:15
  • I've just been looking through all the code, and it looks like the Plugin itself is fine. But the Vendor Timthumb is struggling with the Front Controller in CakePHP. Do you know why? – Cameron Mar 06 '14 at 13:05
  • I wrote my reply as an answer - know/recognise that it's just a normal PHP problem. You might be using CakePHP but there's no evidence that's a relevant factor to "the problem". – AD7six Mar 06 '14 at 23:28

2 Answers2

2

You should leave the final trailing '/' off of your open_basedir. Per the docs:

When you want to restrict access to only the specified directory, end with a slash. For example: open_basedir = /dir/incl/

So your entry only applies to /home/00000/domains, not any sub directories.

oxtub
  • 199
  • 3
  • Are you sure the remote open_basedir is being set? If you run phpinfo(), do you see the value for open_basedir you are specifying? – oxtub Mar 04 '14 at 00:53
  • I just noticed your path: html/app/webroot/index.php/img/cameron.jpg ... Is /index.php/img/ actually a directory? – oxtub Mar 04 '14 at 01:10
  • Checked the phpinfo and the value has definitely being changed (although it looks like the master was correct in the first place). But still getting the error. Is the value incorrect? – Cameron Mar 04 '14 at 13:18
  • The restriction specified with open_basedir is a directory name since PHP 5.2.16 and 5.3.4. Previous versions used it as a prefix. – Shiji.J Oct 05 '16 at 15:52
2

The problem doesn't look like it has anything to do with the framework you're using - the vendor class raising the error doesn't depend on any (relevant) external configuration.

There's a configuration or application error

But it's not the open_basedir settting. (which so long as it includes /home/00000/domains/test.com/html/ should be no problem).

The file raising the error is attempting to access a path that is (correctly) causing problems:

Warning (2): file_exists(): open_basedir restriction in effect. 

File(/home/00000/domains/test.com/html/app/webroot/index.php/attachments/view/5)
                                                   ^^^^^^^^^

is not within the allowed path(s): (/home/00000/domains) 
[APP/Plugin/Timthumb/Vendor/timthumb.php, line 896

The path collides with a file, it's not possible to be a read/writable path even if open base dir were to permit it.

Identify the reason

The base path used is derived from server variables - does it contain index.php? :

protected function calcDocRoot(){
    $docRoot = @$_SERVER['DOCUMENT_ROOT'];
    if (defined('LOCAL_FILE_BASE_DIRECTORY')) {
        $docRoot = LOCAL_FILE_BASE_DIRECTORY;   
    }   
    if(!isset($docRoot)){ 
        $this->debug(3, "DOCUMENT_ROOT is not set. This is probably windows. Starting search 1.");
        if(isset($_SERVER['SCRIPT_FILENAME'])){
            $docRoot = str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])));
            $this->debug(3, "Generated docRoot using SCRIPT_FILENAME and PHP_SELF as: $docRoot");
        }   
    }   
    if(!isset($docRoot)){ 
        $this->debug(3, "DOCUMENT_ROOT still is not set. Starting search 2.");
        if(isset($_SERVER['PATH_TRANSLATED'])){
            $docRoot = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));
            $this->debug(3, "Generated docRoot using PATH_TRANSLATED and PHP_SELF as: $docRoot");
        }   
    }   
    if($docRoot && $_SERVER['DOCUMENT_ROOT'] != '/'){ $docRoot = preg_replace('/\/$/', '', $docRoot); }
    $this->debug(3, "Doc root is: " . $docRoot);
    $this->docRoot = $docRoot;
}

If index.php doesn't come from the docRoot value - it's in the passed argument $src. Identify why or how $src contains an invalid path and correct the application code appropriately.

AD7six
  • 63,116
  • 12
  • 91
  • 123
  • If I define it like so: http://pastebin.com/115qQq4W and do a debug and exit at the bottom. $docRoot is `'/home/00000/domains/test.com/html'`. So it's adding that index.php somewhere else outside of this function as this is the last part of the code. – Cameron Mar 06 '14 at 23:54
  • Also I **can't** point to the webroot explicitly as the image might not live there... It only needs to go there for routing purposes. – Cameron Mar 06 '14 at 23:56
  • If I do this: `$docRoot = $docRoot . '/app/webroot/';` I no longer get the open_basedir error. But I get `Could not find the internal image you specified.` error still. So it's still confused about how to get the image. – Cameron Mar 06 '14 at 23:59
  • The image isn't inside `/app/webroot` but ALL routes go via the front controller in there. – Cameron Mar 07 '14 at 00:04
  • In any case adding that line above, may remove the error, but it doesn't find the image, so I'd say it's not the right direction. – Cameron Mar 07 '14 at 00:05