Execute root commands via PHP

I have a CentOS 5.7 linux server and use php5.3.x.

On a pfSense system, you can restart services-that required root permissions using a php web page.

I’m trying to do something similar, I have written some php code to execute shell commands. For example, to restart the sshd service:

<?php
exec('/sbin/service sshd restart');
?>

and I tried to execute that command via exec function, but it needs root permission, but we have a apache user authority.

I have come across a few solutions:

  1. “run apache with root user” really unsafe. I do not want to do that.
  2. “apache ALL=NOPASSWD:/sbin/service to /etc/sudoers” I tried but and still have a problem.

One thought on “Execute root commands via PHP

  • May 30, 2014 at 6:48 am
    Permalink

    “run apache with root user” really unsafe.
    “apache ALL=NOPASSWD:/sbin/service to /etc/sudoers”

Leave a Reply to eduguru Cancel reply