Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 415
  • Last Modified:

Unable to mkdir() in up level directory

Hello, I'm running Plesk/Apache/PHP4 server. A website in the following directory:

/var/www/vhosts/mysite.com/httpdocs <- this is the root directory of mysite.com. I uploaded the following php script to the site:

<?
//var/www/vhosts/mysite.com/httpdocs/mkdir.php

if(mkdir('/var/www/vhosts/mysite.com/test/abc'))
echo "TRUE";
else
echo "FALSE";
?>

And then access it from mysite.com/mkdir.php. But it doesn't work. I got FALSE! The abc directory was not created.

1. The mode of /var/www/vhosts/mysite.com/test directory is 777
2. The user running PHP is "apache"
3. The PHP safe_mode = false
4. I tried to change user of /var/www/vhosts/mysite.com/test directory into apache or even nobody, still doesn't work.
5. There is no problem if I create directory under httpdocs directory. For example, I create a directory named "inside" via FTP: /var/www/vhosts/mysite.com/httpdocs/inside and than set its mode into 777. When I use mkdir('/var/www/vhosts/mysite.com/httpdocs/inside/abc') to create directory, it works.

Why it just doesn't work outside the httpdocs directory?

0
iProgram
Asked:
iProgram
  • 4
  • 3
2 Solutions
 
rhickmottCommented:
Process of Elimination?

if (is_dir('/var/www/vhosts/mysite.com/test/')) {
     echo("Directory Exists!<br/>");
     
     if (is_writable('/var/www/vhosts/mysite.com/test/') {
          echo("Directory can be written to!<br />");
              if(mkdir('/var/www/vhosts/mysite.com/test/abc/')) {
                    echo("Folder Created");
              } else {
                    echo("Folder <b>not</b> Created");
              }
     } else {
           echo("Directory <b>cannot</b> be written to!");
     }
} else {
    echo("Directory <b>does not</b> exist!");
}
0
 
iProgramAuthor Commented:
is_dir('/var/www/vhosts/mysite.com/test/') == FALSE. I created this directory via SSH. I also tried to change user name of test directory into apache but it's still FALSE.

By the way is_dir('/var/www/vhosts/mysite.com/httpdocs/') == TRUE.

It's really strange!
0
 
rhickmottCommented:
This is where you have to be careful Apache can be extremely funny about which directory's it allows PHP Scripts ( And itself ) to access.

If you wrote a script to copy /etc/passwd the chances are it would tell you to go to hell. If you wrote an Alias to /etc/ it would merrily let you do it.

If I recall rightly you normally cant access files on the file-system NOT referenced in httpd.conf.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
hernst42Commented:
try enabing a more detailed error-message with

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);

if(mkdir('/var/www/vhosts/mysite.com/test/abc'))
echo "TRUE";
else
echo "FALSE";

What do you get as output ?
0
 
iProgramAuthor Commented:
I got this:

Warning: mkdir(): open_basedir restriction in effect. File(/var/www/vhosts/mysite.com/test/abc) is not within the allowed path(s):
(/var/www/vhosts/mysite.com/httpdocs:/tmp) in /var/www/vhosts/mysite.com/httpdocs/mkdir.php.php on line 5

This is a new plesk server and I'm just trying to move a site from a Cpanel server to it. The same script works fine on the Cpanel server. Is there a way to fix this issue?
0
 
rhickmottCommented:
Hmmm open_basedir is normally a Safe Mode thing.
0
 
iProgramAuthor Commented:
Ok I found the answer and open_basedir is not only a safe mode param. Plesk defined the open_basedir for me and I have to write a new conf file for it.
0
 
rhickmottCommented:
ah ok well thats ok then :)

I said *normally* fortunately Plesk is not a standard thing for most PHP set-ups so a lot of the time its due to a safe mode restriction.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now