exec() won't write via browser

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
okherewego
Forum Newbie
Posts: 4
Joined: Mon Sep 13, 2010 6:16 pm

exec() won't write via browser

Post 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.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: exec() won't write via browser

Post 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.
okherewego
Forum Newbie
Posts: 4
Joined: Mon Sep 13, 2010 6:16 pm

Re: exec() won't write via browser

Post 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.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: exec() won't write via browser

Post 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
okherewego
Forum Newbie
Posts: 4
Joined: Mon Sep 13, 2010 6:16 pm

Re: exec() won't write via browser

Post 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.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: exec() won't write via browser

Post 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
okherewego
Forum Newbie
Posts: 4
Joined: Mon Sep 13, 2010 6:16 pm

Re: exec() won't write via browser

Post 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?
Post Reply