Page 1 of 1
exec() won't write via browser
Posted: Mon Sep 13, 2010 6:19 pm
by okherewego
When I run my php file:
<?php
exec("touch file.txt");
?>
via the command line, it will create the file. When I run via a web browser, it will not write.
This would be writing to a non-root folder, too. What is wrong? Surely something to do with permissions, but I don't understand it.
Re: exec() won't write via browser
Posted: Mon Sep 13, 2010 6:22 pm
by Eran
Are you running this on a linux server? the user that you are using on the command line (root?) probably has different permissions / group than the apache process that runs the script.
Re: exec() won't write via browser
Posted: Mon Sep 13, 2010 6:24 pm
by okherewego
pytrin wrote:Are you running this on a linux server? the user that you are using on the command line (root?) probably has different permissions / group than the apache process that runs the script.
Yes, on a linux server.
User on the command line is not root. As I say, it's writing to a non-root folder as well.
Re: exec() won't write via browser
Posted: Mon Sep 13, 2010 6:29 pm
by Eran
root was just an example. In any case, it probably has different permissions than the apache process. chmod and chown the folder to allow access by the user/group that apache runs under
Re: exec() won't write via browser
Posted: Mon Sep 13, 2010 6:35 pm
by okherewego
pytrin wrote:root was just an example. In any case, it probably has different permissions than the apache process. chmod and chown the folder to allow access by the user/group that apache runs under
How do I know what user/group apache runs under? I tried changing permissions to my home user, but that didn't work.
Re: exec() won't write via browser
Posted: Mon Sep 13, 2010 6:40 pm
by Eran
run 'top' in the command line. You can see both user and group there for each process (apache should be running as the httpd daemon). If you don't see one of those, click 'f' to add more columns into the view
Re: exec() won't write via browser
Posted: Tue Sep 14, 2010 3:51 am
by okherewego
pytrin wrote:run 'top' in the command line. You can see both user and group there for each process (apache should be running as the httpd daemon). If you don't see one of those, click 'f' to add more columns into the view
I hate to be a pain, but I don't see any httpd process. I've tested and localhost is working... so.... uhhh. I'm on Ubuntu with apache2.
Edit: According to
http://ubuntuforums.org/showthread.php?t=268262 ... the group is www-data.
I changed it, and it allows access. Thank you.
However, I need to do more than write a file. I need to use the ImageMagick command, import, to take a snapshot. And it doesn't work. Surely that would mean giving www-data access to a whole bunch of programs., including X? Would that be too complicated?