Solved

Unable to mkdir() in up level directory

Posted on 2006-11-23
8
411 Views
Last Modified: 2008-02-01
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
Comment
Question by:iProgram
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 13

Assisted Solution

by:rhickmott
rhickmott earned 100 total points
ID: 18002191
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
 
LVL 1

Author Comment

by:iProgram
ID: 18002423
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
 
LVL 13

Expert Comment

by:rhickmott
ID: 18002457
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 48

Accepted Solution

by:
hernst42 earned 400 total points
ID: 18002475
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
 
LVL 1

Author Comment

by:iProgram
ID: 18002561
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
 
LVL 13

Expert Comment

by:rhickmott
ID: 18002614
Hmmm open_basedir is normally a Safe Mode thing.
0
 
LVL 1

Author Comment

by:iProgram
ID: 18002715
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
 
LVL 13

Expert Comment

by:rhickmott
ID: 18002728
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question