How to stop an apache server on ubuntu

11,331

Solution 1

I've always done it with

sudo apachectl stop

However that won't stop it from starting again at boot time. Also there may be some sort of supervisor script that will re-launch the service if it notices that it's been stopped.

Solution 2

There are a couple things you should look at. First find out what is actually running on port 80 using a command like this.

lsof -i -P | grep :80

Whatever is running on port 80 will come back with a PID looking like this

httpd  1046  apache2 10u  IPv4  5203  0t0  TCP  xxx.xxx.xxx.xxx:80 (LISTEN)

That is what you want to kill.

Lastly if all else fails you can try to send a Kill TERM sig to the Parent by using the pidFile approach as follows.

kill -TERM `cat /usr/local/apache2/logs/httpd.pid`

This will kill off all children and then the Parent will exit. If you kill off child httpd processes you will see new httpd processes come back because the parent is still active.

Solution 3

sudo service apache2 stop

Please also refer this link for more Thanks

Share:
11,331
user1592380
Author by

user1592380

Updated on June 10, 2022

Comments

  • user1592380
    user1592380 about 2 years

    I'm trying to set up my django project to use nginx as its webserver on an EC2 Ubuntu instance following http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html. As part of this I need to install/test if nginx is active with:

    sudo apt-get install nginx
    sudo /etc/init.d/nginx start    # start nginx
    

    then surfing to it my amazon dns at port 80.

    When I do this and cause an error I see:

    mod_wsgi.listener_port      
    
    '80'    
    
    mod_wsgi.listener_host      
    
    ''    
    
    CONTEXT_DOCUMENT_ROOT       
    
    '/var/www/html'    
    
    SERVER_SOFTWARE       
    
    'Apache/2.4.7 (Ubuntu)'    
    
    SCRIPT_NAME       
    
    u''    
    
    mod_wsgi.enable_sendfile      
    
    '0'    
    
    mod_wsgi.handler_script       
    
    ''    
    
    SERVER_SIGNATURE      
    
    '<address>Apache/2.4.7 (Ubuntu) Server at ec2-**-**.us-west-2.compute.amazonaws.com Port 80</address>\n'    
    
    REQUEST_METHOD      
    
    'GET'    
    
    PATH_INFO       
    
    u'/index'    
    
    SERVER_PROTOCOL       
    
    'HTTP/1.1'    
    
    QUERY_STRING      
    
    ''    
    
    HTTP_USER_AGENT       
    
    'Mozilla/5.0 (Windows NT 6.1; rv:35.0) Gecko/20100101 Firefox/35.0'    
    
    HTTP_CONNECTION       
    
    'keep-alive'    
    
    SERVER_NAME       
    
    'ec2-**-**.us-west-2.compute.amazonaws.com'    
    
    REMOTE_ADDR       
    
    '107.0.193.131'    
    
    mod_wsgi.request_handler      
    
    'wsgi-script'    
    
    wsgi.url_scheme       
    
    'http'    
    
    PATH_TRANSLATED       
    
    '/home/ubuntu/tproxy/tp/tp/wsgi.py/index'    
    
    SERVER_PORT       
    
    '80'    
    
    wsgi.multiprocess       
    
    True    
    
    mod_wsgi.input_chunked      
    
    '0'    
    
    SERVER_ADDR       
    
    '172.31.28.196'    
    
    DOCUMENT_ROOT       
    
    '/var/www/html'    
    
    mod_wsgi.process_group      
    
    ''    
    
    SCRIPT_FILENAME       
    
    '/home/ubuntu/tproxy/tp/tp/wsgi.py'    
    
    SERVER_ADMIN      
    
    'webmaster@localhost'    
    
    wsgi.input      
    
    <mod_wsgi.Input object at 0x7fdd5e046af0>    
    
    HTTP_HOST       
    
    'ec2-**-**.us-west-2.compute.amazonaws.com'
    

    So obviously a running apache 2 server. following http://httpd.apache.org/docs/2.2/stopping.html, I tried:

    (env1)ubuntu@ip-172-31-28-196:~/tproxy/tp$ apachectl -k stop
    httpd (pid 1132?) not running
    

    This did not work. How can I shut off the apache server?