Restart apache using PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • black francis

    #1

    Restart apache using PHP

    hello all,

    i`m trying to restart apache from php but have failed completely.
    has anyone sucesfully done it?

    i'm currently able to execute other unix commands from php adding the
    proper permissions to the sudo file but apache refuses to restart.

    here's the pseudo-script:

    <?php
    ....
    $output = shell_exec("/usr/sbin/httpd -k restart");
    exit;
    ?>
    (i tried /etc/init.d/httpd too but got the same results)

    here's the sudo file

    ....
    apache ALL = NOPASSWD: /usr/bin/php, /usr/sbin/useradd,
    /usr/sbin/chpasswd, /httpd/scr, /usr/sbin/httpd
    ....

    i'm using RH-ES, PHP4, Apache2 & selinux turned off

    best regards,
    cristián.

  • Joe Estock

    #2
    Re: Restart apache using PHP

    black francis wrote:[color=blue]
    > hello all,
    >
    > i`m trying to restart apache from php but have failed completely.
    > has anyone sucesfully done it?
    >
    > i'm currently able to execute other unix commands from php adding the
    > proper permissions to the sudo file but apache refuses to restart.
    >
    > here's the pseudo-script:
    >
    > <?php
    > ...
    > $output = shell_exec("/usr/sbin/httpd -k restart");
    > exit;
    > ?>
    > (i tried /etc/init.d/httpd too but got the same results)
    >
    > here's the sudo file
    >
    > ...
    > apache ALL = NOPASSWD: /usr/bin/php, /usr/sbin/useradd,
    > /usr/sbin/chpasswd, /httpd/scr, /usr/sbin/httpd
    > ...
    >
    > i'm using RH-ES, PHP4, Apache2 & selinux turned off
    >
    > best regards,
    > cristián.
    >[/color]
    Have you tried apachectl?

    Comment

    • Julien Demoor

      #3
      Re: Restart apache using PHP

      Joe Estock wrote:[color=blue]
      > Have you tried apachectl?[/color]

      It's apache2ctl on my system.

      $ apache2ctl -k start|restart|g raceful|stop


      JD

      Comment

      • black francis

        #4
        Re: Restart apache using PHP

        the OS it's Red Hat, so apachectl = /usr/sbin/httpd

        Comment

        • Tim Roberts

          #5
          Re: Restart apache using PHP

          "black francis" <cristian.melen dez@gmail.com> wrote:[color=blue]
          >
          >i`m trying to restart apache from php but have failed completely.
          >has anyone sucesfully done it?
          >
          >i'm currently able to execute other unix commands from php adding the
          >proper permissions to the sudo file but apache refuses to restart.
          >
          >here's the pseudo-script:
          >
          ><?php
          >...
          >$output = shell_exec("/usr/sbin/httpd -k restart");
          >exit;
          >?>
          >(i tried /etc/init.d/httpd too but got the same results)
          >
          >here's the sudo file
          >
          >...
          >apache ALL = NOPASSWD: /usr/bin/php, /usr/sbin/useradd,
          >/usr/sbin/chpasswd, /httpd/scr, /usr/sbin/httpd
          >...[/color]

          Yes, but your shell_exec isn't calling sudo. Did you intend to?
          --
          - Tim Roberts, timr@probo.com
          Providenza & Boekelheide, Inc.

          Comment

          • black francis

            #6
            Re: Restart apache using PHP

            shame on me.

            thnx!

            Comment

            • ivo.rajmon@gmail.com

              #7
              Re: Restart apache using PHP

              a bit complicated solution is to use cron to get root access, and keep
              everything looking secure. the crontab script checks a file, and the
              webpage fills the file on request. (newbies, do not call that file
              directly)

              cheers.

              Comment

              Working...