Page 1 of 1
mkdir cannot create a directory (linux Fedora Core 5)
Posted: Mon May 08, 2006 3:29 am
by lawrence_chtan
Dear All the Guru on board
Recently i had switched my OS Platform from the IIS to apache server(Linux Fedora core 5).
And I m having trouble to convert those case sensitive wording to make the PHP work as IIS
but now i has faced this. the mkdir is not working. wonder anyone can tell me anything i need to take care of
mkdir(".\foldername",0777)
it is in the location of
\var\www\html\
apparently when i browse to that folder. i do not see any "foldername" created.
it is functioning well in the IIS environment.
Anyone could enlighten me please.By the way, this is my second day in Fedora..quite a culture shock for me from windos to linux platform.
Sorry for the trouble
Lawrence
Posted: Mon May 08, 2006 6:14 am
by someberry
What does this script output?
Code: Select all
<?PHP
$path = '\\var\\www\\html\\'; // Change this value as you wish
$dir = 'foldername'; // Change this value as you wish
echo('<h1>I am trying to locate the directory <tt>' . $dir . '</tt> located at <tt>' . $path . '</tt></h1>');
if(file_exists($path . $dir))
{ // Directory exists
echo('The directory exists.<br />');
if(is_readable($path . $dir))
{ // Directory is readable
echo('The directory is readable.<br />');
if(is_writable($path . $dir))
{ // Directory is writable
echo('The directory is writable.<br />');
}
else
{
echo('<span style="color: #F00;">Directory is not writable.</span>');
}
}
else
{
echo('<span style="color: #F00;">Directory is not readable.</span>');
}
else
{
echo('<span style="color: #F00;">Directory does not exist.</span>');
}
?>
I haven't tested this.
Also, I was under the impression it was standard to set directories in the public_html (/home/<your_name>/public_html/).
It is not writable. Mean?
Posted: Tue May 09, 2006 4:11 am
by lawrence_chtan
Hi Guru on the board.
with using your coding. i notice. I m having an issue that. i could not write to that folder
is that like windows (setting permission for the folder itself) ?
Posted: Tue May 09, 2006 5:11 am
by someberry
Yes, similar to Windows, you will need to permit access to write to it. To make it writable, you could chmod it.
Posted: Tue May 09, 2006 5:40 am
by dibyendrah
Please note that 0 at the start like "0755" doesn't work with windows . So decimal value like "755" will do the trick. I found while browsing chmod function
http://php.net/manual/en/function.chmod.php .
Cheers,
Dibyendra
Posted: Tue May 09, 2006 12:38 pm
by vincenzobar
Also you may not be able to do it from PHP. it depnds on the privileges you have set for your user. usually the server admin needs to do it or you have to do it from SSH or a admin panel.
When i write a file the owner is usually www:username when it should be username:username and it is usually chmod'd to 666 unless when i mkdir i also chmod at the same time. But that only sets permissions on new file created. you can't do anything unless the main folder all this is happening in is already set to 777.
Also i think i may be totally confused. are you running on a linux box or windows? I'm guessing windows since all your directories use \
Re: mkdir cannot create a directory (linux Fedora Core 5)
Posted: Tue May 09, 2006 1:17 pm
by RobertGonzalez
lawrence_chtan wrote:Recently i had switched my OS Platform from the IIS to apache server(Linux Fedora core 5).
So you are now working in a Linux environment instead of a Windows environment and you are using the Apache (httpd) server instead of IIS, correct?
lawrence_chtan wrote:And I m having trouble to convert those case sensitive wording to make the PHP work as IIS but now i has faced this. the mkdir is not working. wonder anyone can tell me anything i need to take care of
mkdir(".\foldername",0777)
This might have to do with the ownership of the folder. A recent app that I was using required the owner of the folder be apache in order to do some of the file system things that were going on. Of course this was because I want my default folder settings to be 0700 so no one can access them directly (except the server), but in my case it is a preference toward Security, not usability.
MKDIR is not working
Posted: Thu May 11, 2006 2:50 am
by lawrence_chtan
Hi Guru on the board
thanks for your advice. After a few round of testing.
1. I had asked my Linux guru to ensure that particular folder is free of permission.
2. use the simple code to test
3. PHP version 5.1.2
Code: Select all
<php>
$path="/home/test/";
mkdir ("$path",0777);
</php>
but i still cannot see the folder "test" created under the "home"
even if i tried this
Code: Select all
<php>
$path="/home/test/";
if (mkdir ("$path",0777))
echo "folder creation successfully";
else
echo "folder creation unsuccessfully";
</php>
Why it work in Windows IIS not in Linux Apache... felt so stupid to see this command again and again under google..
Posted: Thu May 11, 2006 3:02 am
by RobertGonzalez
I think it has to do with administrative rights. On Linux, there is a focus on Security. So the OS won't even little tasks be accomplished outside the realm of the owner's own folder unless the person initiating the command has rights to that command at that location.
What this means is that if you log in as a user, say to home/username/, the you will be able to mkdir all you want in that folder. But unless you are an administrator you won't be able to mkdir outside of that folder. I am not Linux guru, but I think you might be running into this problem with your PHP script. I would be willing to bet that the folder would be able to be created within the domains root server folder. But probably not anywhere else on the server.
Posted: Thu May 11, 2006 3:34 am
by Benjamin
Every folder in the path needs to have proper permissions. If the path is not in the default apache document root, you will need to disable or configure selinux. Your issue is one of those two.
Will create a folder in the current directory. IE if your script is in /var/www/public_html/, that is where foldername will be created. If you need to create the directory in /var/www/html/, then use the full path.
Linux also uses / by the way, not \
why still similar result
Posted: Wed May 24, 2006 3:02 am
by lawrence_chtan
Dear guru on the board.
this code is totally haunting me forever. even i had change the ownership for the folder to 777 via chmod
attach with my code
Code: Select all
<html>
<body>
<?php
$path = "/var/www/html";
$dir = "/abc/";
echo "<h1>locate the directory <tt> $dir </tt> <br>
located at <tt> $path </tt></h1>";
$fullpath=$path.$dir;
echo "<b>$fullpath</b><br>";
mkdir("$fullpath",0777);
if (file_exists($path.$dir))
{
echo "This file exist<br>";
if (is_readable($path.$dir))
{
echo "is readable<br>";
if (is_writable($path.$dir))
echo "writable<br>";
else
echo "not writable<br>";
}
else
echo "no readable<br>";
}
else
echo "not exist<br>";
?>
</body>
</html>
seems like all the book are saying i need to take care of permission. which i had done with my lab lecturer.

technically The folder
/var/www/html permission had changed to 777 full access in fedora.
will it because is fedora ... maybe i should try out unix. ???
WHY
/var/www/html/abc this folder is still not appear
sorry for asking the same old question again.

Posted: Wed May 24, 2006 3:11 am
by Benjamin
/var/www/html
Every folder in the path needs to have execute (traverse) and read permissions. The html folder will need write permissions as well.
Check the permissions on var, www and html. You may also need to disable selinux.