How to Stop Apache Server on Ubuntu (The Right Way)

stop apache server on ubuntu

Apache is the backbone of many websites and applications running on Ubuntu. But what if you need to stop it? Maybe you’re troubleshooting, updating configurations, or just saving system resources. Whatever the reason, knowing how to manage Apache properly is essential.

In this guide, I’ll walk you through how to stop, start, and restart Apache on Ubuntu using simple, foolproof commands. By the end, you’ll have complete control over your Apache server like a pro.

Why Would You Need to Stop Apache?

Stopping Apache isn’t something you do every day, but there are valid reasons to shut it down:

System Maintenance – If you’re updating software, you might need to stop Apache temporarily.
Performance Optimization – Running Apache when it’s not needed consumes resources. Stopping it frees up CPU and memory.
Troubleshooting Issues – If Apache is misbehaving, stopping and restarting it can help fix errors.
Security Concerns – If there’s a vulnerability, shutting down Apache can prevent attacks.

Now, let’s dive into how to check Apache’s status before stopping it.

How to Check If Apache is Running on Ubuntu

Before stopping Apache, it’s a good idea to check whether it’s running. Run this command:

bashCopyEditsudo systemctl status apache2

If Apache is active (running), you’ll see an output like this:

yamlCopyEdit● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2025-03-10 12:34:56 UTC; 2h 15min ago

If it’s inactive (stopped), that means Apache is already off.

How to Stop Apache Server on Ubuntu

So, you’re ready to stop Apache? Here are two ways to do it:

Method 1: Stop Apache Using systemctl (Recommended)

This is the best way to stop Apache:

bashCopyEditsudo systemctl stop apache2

This command shuts down Apache immediately without affecting your system.

Method 2: Stop Apache Using the Service Command

Another way to stop Apache is:

bashCopyEditsudo service apache2 stop

Both methods work, but systemctl is preferred on newer Ubuntu versions.

How to Restart Apache on Ubuntu

Sometimes, instead of stopping Apache, you may just need to restart it.

Method 1: Restart Apache Using systemctl

bashCopyEditsudo systemctl restart apache2

This completely stops and starts Apache.

Method 2: Restart Apache Using the Service Command

bashCopyEditsudo service apache2 restart

Bonus: Graceful Restart (No Downtime)

If you don’t want to disrupt active connections, use:

bashCopyEditsudo apachectl graceful

This method reloads Apache without cutting off users.

How to Start Apache Server in Linux

If Apache is stopped and you need to start it again, just run:

bashCopyEditsudo systemctl start apache2

or

bashCopyEditsudo service apache2 start

Want Apache to start automatically on boot? Enable it with:

bashCopyEditsudo systemctl enable apache2

Now, every time your system reboots, Apache will start automatically.

How to Stop Apache Server in Ubuntu Permanently

If you no longer need Apache, you can disable or uninstall it.

Disable Apache on Boot

bashCopyEditsudo systemctl disable apache2

Apache will no longer start when your system boots.

Uninstall Apache Completely

Want to remove Apache from Ubuntu? Run:

bashCopyEditsudo apt remove apache2 -y
sudo apt autoremove -y

This removes Apache and all unnecessary dependencies.

Troubleshooting Common Apache Issues

1. Apache Won’t Stop?

If sudo systemctl stop apache2 doesn’t work, force-stop it:

bashCopyEditsudo killall apache2

This terminates all running Apache processes.

2. Apache is Running on a Different Port?

If Apache won’t start, another service might be using port 80. Check:


sudo netstat -tulnp | grep :80

If you see another process using port 80, either stop that process or change Apache’s port in /etc/apache2/ports.conf.

FAQs

1. How can I stop Apache on Ubuntu temporarily?
Use sudo systemctl stop apache2. This stops Apache until you manually start it again.

2. What’s the safest way to restart Apache?
Use sudo apachectl graceful. This restarts Apache without disconnecting users.

3. How do I check if Apache has stopped?
Run sudo systemctl status apache2. If it says inactive (dead), Apache is stopped.

4. What happens if I force-stop Apache?
Force-stopping (kill -9 <PID>) immediately kills all Apache processes, which might interrupt active users. Only do this if necessary.

How do I uninstall Apache completely?
Run sudo apt remove apache2 -y && sudo apt autoremove -y to delete Apache and its related packages.

Conclusion

Managing Apache on Ubuntu is easy when you know the right commands. Whether you need to stop, start, or restart Apache, you now have everything you need to do it safely.