Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Jun 2008
    Posts
    43

    Exclamation Restart httpd through php code ?

    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. #2
    Member
    Join Date
    Sep 2009
    Location
    United Kingdom
    Posts
    110
    cPanel/Enkompass Access Level

    DataCenter Provider

    Default

    What about:
    PHP Code:
    <?php
    $output
    =shell_exec('service httpd restart');
    echo 
    $output;
    exit;
    ?>
    ?

  3. #3
    Member
    Join Date
    Jun 2008
    Posts
    43

    Default

    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. #4
    cPanel Staff cPanelMatt's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Post

    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)
    Matt Dees
    Integration Developer
    cPanel, Inc.
    cPanel Integration Blog

  5. #5
    cPanel Staff cPanelMatt's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    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...-a-136449.html

    f.ex:

    PHP Code:
    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'); 
    Matt Dees
    Integration Developer
    cPanel, Inc.
    cPanel Integration Blog

Similar Threads & Tags
Similar threads

  1. Restart httpd through php code ?
    By map007 in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 12-25-2009, 06:07 PM
  2. Daily httpd restart changes AllowOverride None to All in httpd.conf
    By Lasers in forum cPanel and WHM Discussions
    Replies: 7
    Last Post: 02-26-2007, 12:17 PM
  3. Burst Of Connections Httpd (x) Malicious Code
    By danielbogo in forum New User Questions
    Replies: 0
    Last Post: 02-21-2007, 08:17 AM
  4. httpd dupmed code, can somebody help me
    By ncconquer in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 05-17-2005, 03:28 AM
  5. mod_gzip httpd.conf code
    By First Faze in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 04-10-2002, 02:36 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube