Forum Moderators: coopster

Message Too Old, No Replies

Making Directories

         

ahmedtheking

8:14 pm on Jan 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd like PHP to make directories on a different hard drive than the one it's running on. This is the set up, I've got 3 disks, one that's the default one (that has PHP running on it) and 2 storage disks. I've made a script that checks the space left on each storage disk and creates a folder on there. But PHP doesn't. I'm thinking it's because PHP may not have group privs to make it. Even if I make it via exec(), I'll still needed PHP to be able to create, edit and delete files from there so it's imperitive that PHP can work with that disk.

Any ideas?

eelixduppy

9:20 pm on Jan 1, 2007 (gmt 0)




Even if I make it via exec(), I'll still needed PHP to be able to create, edit and delete files from there so it's imperative that PHP can work with that disk.

You either have to give your server access to those drives, which is something I wouldn't recommend, or you have to use a function such as exec(). You can still manipulate files using exec() just as you can create directories. It may come to the point where you have to make temporary files on the working hard drive, and then use exec() to move them to the other drives.

I'm sure you can think of something :)

ahmedtheking

10:09 am on Jan 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm fair enough! Thanks for the help anyway!

ahmedtheking

9:24 am on Jan 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, I've been using exec() now but still nothing! It won't allow me to create the directories! Really lame! How can I allow PHP perms to these storage drives?

jezra

10:18 pm on Jan 3, 2007 (gmt 0)

10+ Year Member



How are you executing the php script that is supposed to create the folder?
If you are using a web browser to access the script, then the script is being executed by the http server software as a highly restricted user and it is this user that needs read/write access to the other disks.

ahmedtheking

1:10 pm on Jan 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So how'd you suggest I give the script perms? I'm working in OS X through SSH so not much GUI to play with! Is there a way I could give perms to apache or indeed php to access those drives?

alfaguru

3:08 pm on Jan 4, 2007 (gmt 0)

10+ Year Member



I'd create a directory under the root of each drive that gives full access rights to the web server PHP user. The root directory should remain restricted. I don't think there's any more sophisticated solution than this that would have any advantages at all.

alfaguru

3:14 pm on Jan 4, 2007 (gmt 0)

10+ Year Member



Is there a way I could give perms to apache or indeed php to access those drives?

You need to know what user PHP is executing as. The quickest way might be to create a folder, make it universally accessible (chmod +777 thefoldername) then get your script to create a file inside it. You can then ls -l thefilename to see what the owner and group is. Create the folders as above and give the group all rights to them. (I'm more familiar with Linux than OS X, so I can't tell you the best way to do that).

ahmedtheking

3:16 pm on Jan 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why not the root dir? they're just storage drives, no apps or anything are on there.

jezra

5:54 pm on Jan 4, 2007 (gmt 0)

10+ Year Member



If you are using OSX and accessing the machine with SSH, then you will need to give write access to whomever you are signing into the machine as. For example, if, on the machine there is an account for a user named "ahmed" and you sign in from a different machine using SSH, then "ahmed" needs to have write access to the drives.

ahmedtheking

6:04 pm on Jan 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah I know that. HTTPD and Apache run under WWW, took me a while to figure out. I've chown'd the drives to allow the user (or group) www to access it! It all works now, just wondering how it could be a security threat?

alfaguru

5:27 pm on Jan 5, 2007 (gmt 0)

10+ Year Member



Ahmed, the reason I suggested using a directory under the root was that it leaves you an option open should you want at some future date to use space on the drive for some other purpose. Not a security issue so much as thinking ahead.

ahmedtheking

5:58 pm on Jan 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah yes, any idea how to un'chown?