php exec command from file without password
Asked Answered
C

1

6

I need to exec command from php to write into my vhosts.conf. I have one add_vhost.sh file :

cat /home/www/test/conf/vhosts.conf >> /etc/httpd/conf.d/vhosts.conf

this is php script:

 exec($path_to_add_vhost_sh_file, $output);

i want to set no password requirement for peter user to exec this file, so i did next thing in my /etc/sudoers

peter ALL=(ALL)NOPASSWD:/home/www/test/conf/add_vhost.sh but its still not working, even in console. fedora 15

Chops answered 22/4, 2013 at 13:56 Comment(2)
your webserver is running under the user "peter"? and you added sudo in front of the command in php?Rollet
oh, i see web server is running under www-data :/Chops
S
8

If your webserver runs as the www-data user user:

www-data ALL=(ALL:ALL) NOPASSWD: /path/to/your/script

If not, replace www-data by your web server's user name.

In php don't miss to prepend your command line with sudo:

exec('sudo /path/to/your/script');
Sidsida answered 22/4, 2013 at 13:59 Comment(2)
This applies of course only if you execute the script via web. (I assumed this). Does it work now?Sidsida
yea, and changed webserver user nopasswd in sudoersChops

© 2022 - 2024 — McMap. All rights reserved.