Php exec command from file without password

I need to execute the exec command from php to write to 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 a password requirement for user peter to execute this file, so I did the following in my /etc/sudoers

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

+4
source share
1 answer

If your web server is running as a www-data user:

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

If not, replace www-data with the web server username.

In php, don't miss adding a command line using sudo :

 exec('sudo /path/to/your/script'); 
+6
source

All Articles