Skip to content

Instantly share code, notes, and snippets.

@tangoabcdelta
Created January 20, 2021 21:14
Show Gist options
  • Save tangoabcdelta/346eeca019e338db563bbb53b8a4ca4d to your computer and use it in GitHub Desktop.
Save tangoabcdelta/346eeca019e338db563bbb53b8a4ca4d to your computer and use it in GitHub Desktop.
How to kill apache2 service running on port 80 and how to stop apache2 from launching at start up - Linux and Mac

How to stop apache2 from autostarting during start up

How to stop apache2 from autostarting during start up - Linux
  • start - sudo service apache2 start
  • stop - sudo service apache2 stop
  • restart - sudo service apache2 restart
  • enable auto launch - sudo systemctl enable apache2
  • disable apache2 auto launch - sudo systemctl disable apache2

(works on ubuntu 16.04 or later which use systemd)

How to kill apache2 service running on port 80 - Linux
  • any process running on ports lower than 1024 needs sudo access

  • if you simply do lsof -i:80, you won't get the apache2 server's pid

  • you will have to use sudo

    sudo lsof -i:80
    [sudo] password for $USERNAME: 
    
    COMMAND     PID     USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
    apache2    1251     root    4u  IPv6   33732      0t0  TCP *:http (LISTEN)
    apache2   23440 www-data    4u  IPv6   33732      0t0  TCP *:http (LISTEN)
    apache2   23441 www-data    4u  IPv6   33732      0t0  TCP *:http (LISTEN)
    plugin_ho 23443     root   17u  IPv4 1491055      0t0  TCP $USERNAME-laptop:52790->45.55.41.223:http (CLOSE_WAIT)
    
  • the process carrying the USER as root is the main one

  • other processes carrying the USER as www-data are the child processes spawned from the root process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment