Can you use sudoers to run PHP in shell?

Can you use sudoers to run PHP in shell?

But it isn’t working. When I run the command in shell with sudo it works. I am pretty sure that there is nothing wrong with the rest of the code, when I replace shell_exec with echo, I get the correct command printed. I have also verified that my php is being run as www-data user. Have I just got the sudoers entry wrong? How can I troubleshoot?

How can I run a sudo command without a password?

Scroll down to the end of the file and add the following line that will allow the user “linuxize” to run any command with sudo without being asked for a password: Do not forget to change “linuxize” with the username you want to grant access to.

How to grant Sudo access to a user?

Usually, to grant sudo access to a user you need to add the user to the sudo group defined in the sudoers file . On Debian, Ubuntu and their derivatives, members of the group sudo are granted with sudo privileges while on RedHat based distributions like CentOS and Fedora, the name of the sudo group is wheel.

Is it bad to add Apache user to sudoers?

Yes, I think that it’s a really bad idea to add the apache user www-data to the list of sudoers, especially because you include a variable $num inside your code that could seriously harm your server if wrongly injected (especially if used by a sudoer user).

Which is correct sudoers or www-data?

Your sudoers line is correct in that it only allows www-data to execute the one command as root.

How to allow PHP to run command-Unix?

I would suggest instead to create a new group, to add www-data to that group and to assign /home/xbian/433Utils/RPi_utils/codesend to the group. Then, give permissions to codesend to be executed by all members of that group; you should not be asked for any password and your system will be secure.

How to allow a user to run a sudo command?

First, you’ll need to use the visudo utility… This command safely opens up the /etc/sudoers file for you in your default editor. Let’s say you want to allow a user named “joe” to run a given command. You just need to add a line like this below (customize for your needs)

Do you need root to run Sudo visudo?

Not sure you need root to execute your script, but given you mention sudo it is likely. Run sudo visudo command then set -%sudo ALL= (ALL:ALL) to %sudo ALL= (ALL:ALL) NOPASSWD: ALL it will work. I had a similar situation trying to exec () a backend command and also getting no tty present and no askpass program specified in the web server error log.

Do you need a password to call Sudo on Bash?

You should limit this power to the specific commands you need. This will allow that particular user to call sudo on that particular script without being prompted for a password.

How can I use sudo without a password?

This will allow that particular user to call sudo on that particular script without being prompted for a password. The best secure method is to use the crontab. ie Save all your commands in a database say, mysql table and create a cronjob to read these mysql entreis and execute via shell_exec ().

Which is the best way to execute PHP exec ( )?

Also, be sure to apply the appropriate quoting/escaping rules on my_command portion. The best secure method is to use the crontab. ie Save all your commands in a database say, mysql table and create a cronjob to read these mysql entreis and execute via exec () or shell_exec ().