The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Restart httpd through php code ?

Discussion in 'cPanel Developers' started by map007, Dec 25, 2009.

  1. map007

    map007 Active Member

    Joined:
    Jun 5, 2008
    Messages:
    43
    Likes Received:
    0
    Trophy Points:
    6
    Hi,

    I want to create a php program to restart httpd and mysql services....

    <?php
    $output=shell_exec('/etc/init.d/httpd restart');
    echo $output;
    exit;
    ?>

    when i run this program i m getting below 3 errors :-

    /etc/init.d/httpd: line 15: ulimit: open files: cannot modify limit: Operation not permitted
    /etc/init.d/httpd: line 16: ulimit: open files: cannot modify limit: Operation not permitted
    httpd: Could not open configuration file /usr/local/apache/conf/httpd.conf: Permission denied
    ================================================
    (13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
    no listening sockets available, shutting down
    Unable to open logs
    /etc/init.d/httpd: line 13: ulimit: open files: cannot modify limit: Operation not permitted
    ================================================
    Syntax error on line 884 of /usr/local/apache/conf/httpd.conf:
    SSLCertificateKeyFile: file '/etc/ssl/private/domain.com.key' does not exist or is empty
    ================================================

    Can any one guide me how to solve this problem ?


    Thank you.
     
  2. Reado

    Reado Well-Known Member

    Joined:
    Sep 8, 2009
    Messages:
    161
    Likes Received:
    4
    Trophy Points:
    18
    Location:
    United Kingdom
    cPanel Access Level:
    DataCenter Provider
    What about:
    PHP:
    <?php
    $output
    =shell_exec('service httpd restart');
    echo 
    $output;
    exit;
    ?>
    ?
     
  3. map007

    map007 Active Member

    Joined:
    Jun 5, 2008
    Messages:
    43
    Likes Received:
    0
    Trophy Points:
    6
    Hi,

    Thanks for reply but now i m getting below error :-

    Stopping httpd: [FAILED] Starting httpd: [FAILED]

    tail -f logs/error_log

    rm: cannot remove `/var/run/httpd/httpd.pid': Permission denied
    rm: cannot remove `/var/lock/subsys/httpd': Permission denied
    rm: cannot remove `/var/run/httpd/httpd.pid': Permission denied
    (13)Permission denied: make_sock: could not bind to address [::]:80
    (13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
    no listening sockets available, shutting down
    Unable to open logs

    Thanks.
     
  4. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    For this to work need to execute the code as the root user. This is not possible without some heavy modifications to apache that will also break your server. Instead you will want to use the xmlapi's restartsrv call to do this. It should be noted that restarting apache from php will cause the page to halt loading, giving the appearance that apache crashed (as php generally runs as part of the apachw process, cgi may behave differently)
     
  5. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Sorry for the brevity of my last post - that was made from my phone. Anyways, if you want to do this via PHP you can use the XML API PHP class to do this:

    http://forums.cpanel.net/f42/xml-api-php-class-version-1-0-a-136449.html

    f.ex:

    PHP:
    include("xmlapi.php");

    $ip "127.0.0.1";
    $root_pass "somepass";

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root",$root_pass);

    $xmlapi->set_debug(1);

    print 
    $xmlapi->restartsrv('httpd');
     
Loading...
Similar Threads - Restart httpd through
  1. Goran.Siriev
    Replies:
    1
    Views:
    460

Share This Page