Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php exec command from file without password

Tags:

php

sudoers

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

like image 852
Petro Popelyshko Avatar asked Apr 22 '13 13:04

Petro Popelyshko


1 Answers

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');
like image 73
hek2mgl Avatar answered Sep 22 '22 14:09

hek2mgl