Stopping the Apache Service on Ubuntu
Stopping the Apache service on an Ubuntu system is a common task required for maintenance, troubleshooting, or transitioning to a different web server. This article provides a straightforward guide to achieve this using command-line tools.
Prerequisites
Ensure you have administrative privileges on the Ubuntu system. You can perform the steps using the sudo command or by logging in as the root user.
Stopping the Apache Service
Using the systemctl Command
The systemctl command is the recommended method to manage services in modern Ubuntu systems.
- Open a terminal window.
- Run the following command to stop the Apache service:
sudo systemctl stop apache2
This command immediately stops the Apache service. The service will no longer accept new connections, but existing connections will be completed.
Using the service Command
Alternatively, you can use the service command if it is available on your system.
- Open a terminal window.
- Run the following command to stop the Apache service:
sudo service apache2 stop
The behavior is similar to using systemctl, but systemctl is preferred for its broader functionality and compatibility.
Verifying the Service Status
After stopping the service, it is good practice to verify that Apache is indeed no longer running.
- Run the following command to check the status:
sudo systemctl status apache2
The output should indicate that the service is inactive (stopped).
Disabling the Apache Service (Optional)
If you do not plan to restart Apache, you can disable it to prevent it from starting automatically on boot.
- Run the following command:
sudo systemctl disable apache2
This command modifies the service configuration to prevent it from loading on system startup.
Starting the Apache Service Again
If you need to restart Apache later, use the following command:
- Open a terminal window.
- Run the following command to start the service:
sudo systemctl start apache2
You can also re-enable it to start automatically on boot:
sudo systemctl enable apache2