PHP – Running scripts as root

Very simple situation and very simple fix.

<?php

echo shell_exec("sudo /usr/local/bin/my_command.sh");

Whether you are using apache of php-fpm, you need to grant your web server with sudo privilege. This can be done by adding the following line to /etc/sudoers file:

apache ALL=NOPASSWD: /usr/local/bin/my_command.sh

Done !

Majd Arbash

Leave a Reply