7

I Can't stop apache2. I want to use nginx, therefore,I want to remove/stop apache2 but I can't. I've tried all the methods on this Link , but when I refresh http://127.0.0.1/ i still see the apache2 there.

4 Answers 4

10

What you're seeing is the index.html file that was installed by Apache. Do not trust solely the Index page being served as an indicator of the Web Server being used!

Just because you're seeing the Apache "default" page, doesn't mean that you're actually seeing Apache running, you're just seeing the 'default page' that was installed. Neither NGINX nor Apache will overwrite the index.html file in the default web root if it was already present (in an ideal situation), so whichever was present first is actually the one that installed the index.html file - it won't change just because you installed a different webserver.

You can confirm this by doing: sudo rm /var/www/html/index.html && echo "I am testing things!" | sudo tee /var/www/html/index.html and then refreshing your browser - you'll see that it's different content at this point.

If the nginx software at install time sees an index.html file already in the default webroot /var/www/html/, it is supposed to not overwrite it. This is normal, so users who use the default docroot for their websites don't lose their data.

What we need to do is confirm what Web Server is actually in use.
Always use actual command line tools to verify the web server software in use.

Leveraging sudo netstat -tulpn | grep :80 (an alternative command will be ss -tulpn | grep :80 if netstat isn't installed on your system) we can get an idea of what web server is in use:

$ sudo netstat -tulpn | grep :80
tcp6       0      0 :::80                   :::*                    LISTEN      1258/apache2

As you can see, this is an Apache2 web server listening on port 80.

Conversely, if the server is nginx you see something like this:

$ sudo netstat -tulpn | grep :80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2772/nginx: master  
tcp6       0      0 :::80                   :::*                    LISTEN      2772/nginx: master

You can also determine if it's Apache2 or NGINX running by checking the output of one of the following commands:

$ pidof apache2
$ pidof nginx

Depending on which of these provides output, you can determine which web server is actually in use.

9

If you want to stop the Apache2 web server then command is

sudo systemctl stop apache2 --- Stop the server

sudo systemctl restart apache2 ---- Restart the web server

You can remove(permanently) the Apache2 web server by command.

sudo apt-get purge -y apache2* --- Uninstall the Apache2 server

After uninstall you can check in browser by entering your localhost(127.0.0.1)

1

You can stop the apache2 service with:

sudo systemctl stop apache2

or

service apache2 stop

if your system was booted without systemd.

To remove it from your server, you can run:

sudo apt-get purge apache2 apache2-utils apache2-bin apache2.2-common

If for some reason this doesn't work, you can run the following command (requires net-tools):

netstat -tulpn | grep :80

and kill the process with:

sudo kill pid

Also make sure that the apache2 default webpage is not in /var/www/html/.

0

To remove apache and all associated files, you can run:

sudo apt-get purge -y apache2\*

Don't forget to escape the asterisk or you will get

sudo: No match
1
  • That comment above was me learning the system. I think however that the original question was how to stop apache not remove it. sudo service apache2 stop would be better. Jan 26, 2022 at 20:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .