Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 4 drives in my (yes, physically in the box, sata connected) Ubuntu 10.10 system with xampp installed at the /opt/lampp/ dir on the OS drive. The OS drive (ssd, lets call it drive1 for sanity) has the correct file permissions to allow for PHP (user www-data) to read/write to any of my htdocs and vhosts folder(s).

Here is my fstab file:

UUID=552A7C6B05CEAAD2 /media/v1tb ntfs-3g defaults,uid=1000 0 0
UUID=DE58539158536775 /media/v1.5tb ntfs-3g defaults,uid=1000 0 0
UUID=3D80C54D5D100280 /media/v2.0tb ntfs-3g defaults,uid=1000 0 0

Also, I tried to use the following and it copies just fine:

sudo -u www-data cp '/media/v2.0tb/path/to/file' '/media/v2.0tb/path/to/newfile'

What I failed to notice all this time is that the string I was passing to my copy/rename function had a space in it and wasn't encapsulated in " as it should have been due to loose type casting of php.

Thanks for all of the help!

share|improve this question
Ubuntu question? Are you doing this with move_uploaded_file()? Are you in PHP safe_mode? Is error_reporting(E_ALL) and ini_set("display_errors", 1) so you can see the problem? Have you supplied a value for open_basedir? Can you copy and then delete? How about rename() - does that work (the "move" function is rename()). – user8290 Dec 9 '11 at 19:05
Read the change log for rename: – user8290 Dec 9 '11 at 19:09
Might want to look at exec() if all else seems to be failing or mount the drive with the www-data UID as s4ms3milia suggests. – user8290 Dec 9 '11 at 19:15
Chris: Sorry I didn't see your posts earlier. 1) not using move_uploaded_file, the files have been put into my ntfs drives and I'm trying to organize them. Its hard to organize when you can't copy or rename. 2) Not in safe mode, unless that is the default install for xampp. I'll look into that further. 3) Display errors was at E_ALL and it said 'permission denied...'. 3) tried both copy(), rename() and passthru('cp "from" "to") all with full paths from the root of that drive /media/v2.0tb/ encapsulated in double quotes. The passthru command I wrote in the command line & then put it into php. – Vance Dec 9 '11 at 20:21
Ok. I added my best guess. :) – user8290 Dec 9 '11 at 20:46
up vote 0 down vote accepted

First of all: you don't have to reformat anything.

I'd suggest the following setup for your fstab entries:

UUID=X /media/<path> ntfs-3g uid=<your username>,gid=<a group containing www-data>,umask=007 0 0

umask=007 sets the permissions to rwx (read, write, execute) for both group(www-data) and user (you).

share|improve this answer
I'll try that now. I didn't figure I would have to reformat but I could move it to ext3 or ext4 if needed. Its just a local media server and I could always get a red5 instance or something similar running to output the videos. It will just be a pain to move all the data back and forth. – Vance Dec 9 '11 at 19:02
Also, I did have it as /dev/sdxx but I found that to sometimes be inconsistent in figuring out which drive is being mounted. And as its very important for my code to read/write to the correct drives, I found it best to stick with the UUID's. Let me know if I'm incorrect. I'm a good web developer but I've not delved into permissions in ubuntu much. I just prefer linux over pc for a dev environment for php. – Vance Dec 9 '11 at 19:05
Yeah stick with UUID, that is more convenient. – imbaer Dec 9 '11 at 19:08
Also, is there a way to add the ability for these drives to be shared across my local network again. Previously I had allowed them to be shared and accessible on any machine on my network. Which, since I have a 32 char password on wpa2, I felt pretty secure about that. Also, physically nobody else has access to my router. – Vance Dec 9 '11 at 19:57
Sadly now for whatever reason the suggestions you made for my fstab doesn't allow me to read the files on disk with my www-data user. Here is my fstab: UUID=3D80C54D5D100280 /media/v2.0tb ntfs-3g uid=1000,gid=33,umask=007 0 0 where the uid is for my typical username of that box, and the gid is of my www-data user/group (same id for both). I found their id's via the 'id' command – Vance Dec 9 '11 at 20:10

If you are all alone on this server, no other users to take advantage of it... let www-data run some commands without a password for sudo.

sudo visudo

Add to the end of the file...

www-data ALL= NOPASSWD: /bin/mv

Then use PHP shell_exec():

$source = '/media/v2.0tb/path/to/file';
$destination = '/media/v2.0tb/path/to/newfile';
$command = 'sudo mv ' . $source . ' ' . $destination;
$result = shell_exec($command);
echo $result;

Or use suEXEC, if you do not mind spending a little time learning it. It is most likely the way to go.

share|improve this answer
And that would allow the user www-data (php/apache user) to move files without a password? It would only allow them to move files though? Or obviously other commands I put into that. I am somewhat concerned because this is internet connected and I do understand there are possibilities for security breaches. But I don't have anything on this machine that really matters. No online banking, etc, its just a media server. – Vance Dec 9 '11 at 20:58
@Vance Yes: sudo operations with no password, and you can add more. You can use basic authentication (htpasswd) or a simple php authentication function to limit access to your web sevrer if people can reach it from the outside. – user8290 Dec 9 '11 at 21:01
Ok good to know. I may have to resort to that here soon just because I seem to be going backwards. This isn't really a time critical thing but frustrating none the less. I already have an auth system in place via php/mysql. Thanks again! – Vance Dec 9 '11 at 21:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.