Solved

Unable to mkdir() in up level directory

Posted on 2006-11-23
8
399 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
  • 4
  • 3
8 Comments
 
LVL 13

Assisted Solution

by:rhickmott
rhickmott earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 48

Accepted Solution

by:
hernst42 earned 400 total points
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:iProgram
Comment Utility
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
Comment Utility
Hmmm open_basedir is normally a Safe Mode thing.
0
 
LVL 1

Author Comment

by:iProgram
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now