How To Start / Stop / Restart Apache 2 Web Server Linux Ubuntu

How To Start / Stop / Restart Apache 2 Web Server Linux Ubuntu. In this tutorial, we walk you through how to start stop and restart the Apache web server on Ubuntu. For demonstration, we will use Ubuntu 22.04 which is the latest Ubuntu LTS release. This guide will still work for Ubuntu 18.04 and later releases.

So the article How To Start / Stop / Restart Apache 2 Web Server Linux Ubuntu is available for you to read through. 

What is a Web Server?

Firstly, a web server is an application or software that hosts or serves ( hence the term web server ) website files which are requested by client devices such as PCs and tablets. These website files include text, images, videos and other components which are rendered on a client’s web browser.

Secondly, web servers are installed on as bare metal or virtual servers in order to execute their tasks. In most cases, web servers come with tools and features which enhance their security and performance. In some cases, system administrators need to go a step further and make some tweaks in order to harden the servers and boost their performance.

How a Web Server Works

A web server uses the HTTP ( Hyper Text Transfer Protocol ) to respond to client requests made from a browser. 

At a high level, when a user opens a browser and visits a site, a HTTP request is sent to the web server hosting the website. Upon receiving the request, the web server looks for the requested webpage sends it back to the client. The webpage includes information such as text, images and videos and so on.

Image source:  www.developer.mozilla.org

If the server does not locate the requested webpage, it returns a 404 error instead. This is a standard HTTP code that indicates that the requested website or webpage was not located. Here is what a 404 error looks like on a Google Chrome browser.

Now that you know what a web server is and how it works, let us now shift our focus and explore the Apache Web Server.

What is Apache Web Server?

Image source:  www.apache.org

With Apache2 Web Server or simply Apache HTTP server is one of the earliest and most popular and widely used web servers. Developed in C programming language, Apache is free and opensource and is licensed under the Apache license 2.0. Also it is actively maintained and developed by an open source community of developers under the Apache Software Foundation. 

 Importantly, the web server is widely adopted  by programmers, developers and enterprises to host websites and other web applications. According to a survey conducted by Netcraft,  Apache accounts for nearly 21.40% of the web server market as of November 2022. It comes second to Nginx which sits at the top with 26.51% market share. 

Apache web server is fast, reliable and highly configurable thanks to its open source infrastructure. It can be customized to suit your needs including setting up virtual hosts , implementing TLS/SSL,  and handling heavy traffic to mention but a few. 

The web server provides a myriad of tools and modules which enhance the functionality of the web server. There are modules for a variety of us cases including  caching, security, URL rewriting, database connection, virtual hosts, password authentication and so on.

Key Features of Apache Web Server

At the time of writing this guide, the latest version of Apache is Apache HTTP 2.4.54.  Below are some of the salient features that Apache web server provides

  1. Support for HTTP/2.
  2. Support for both IPv4 and IPv6.
  3. Built-in PHP, Perl and Lua scripts.
  4. Loadable Dynamic Modules.
  5. Handling of static files and dynamic files.
  6. TLS / SSL Support with SNI and OCSP stapling support, via OpenSSL. 
  7. Fine grained authentication and authorization access control.
  8. Geolocation based on user IP address.
  9. User and session tracking.
  10. FTP and CGI support.
  11. Auto-indexing and content negotiation.
  12. gzip compression and decompression.

Apache Pros

The following are the advantages of using Apache as your web server of choice:

  1. It free and opensource. This implies that you install and use it for free. It’s open source nature makes it possible for developers to access and contribute to the code base.
  2. It is easy to install. Running a few commands on the terminal is all it take to install it.
  3. Apache is highly customizable. You tweak any component and add modules and features to enhance its performance and security.
  4. You can install it on Windows, Linux, macOS and other UNIX platforms such as FreeBSD and NetBSD.
  5. Apache is highly flexible, reliable and offers excellent performance.
  6. It’s actively maintained by an opensource community of vibrant developers.
  7. An Extensive and well detailed documentation.

Cons

Despite being a reliable and high performance web server, Apache is not without its drawbacks. Here are some of them.

  1. Performance issues when handling high traffic. Nginx is recommended as an alternative when handling traffic-heavy websites.
  2. High resource overhead. It consumes more RAM than Nginx.
  3. Apache spawns new processes for each request, thereby making things less efficient.

Now it is the main part of the article How To Start / Stop / Restart Apache 2 Web Server Linux Ubuntu. 

How to Install Apache Web Server on Ubuntu 22.04/20.04

In this section, we demonstrate how you can manage Apache web service by starting, stopping and restarting it on Ubuntu. Before we do so,  let’s first install the web server.

First, log into your Ubuntu instance and update the package lists as follows.

				
					$ sudo apt update
				
			

The Apache2 web server package is  hosted on Ubuntu‘s Official repository. Therefore, you can install it using the APT package manager as shown:

				
					$ sudo apt install apache2 -y
				
			

The command installs Apache2 package alongside other packages and dependencies. The installation takes anything between a few seconds and a minute.

Once installed, you check the version of Apache installed  as follows.

				
					$ apachectl -V
				
			

How to Start / Stop and Restart Apache Web Server

By default,  Apache starts upon installation. Therefore,  you don’t need to run any command to start it. To verify that Apache is running, run the command:

				
					$ sudo systemctl status apache2
				
			

From the output below, you can see that Apache is up and running.

By default, Apache listens to port 80. You can verify this using the ss command as follows.

				
					ss -pnltue | grep 80
				
			

Another way of verifying that Apache is running is by visiting your server’s IP address as follows:

				
					http://server-ip
				
			

You should be able to see the default Apache2 webpage.

How To Start Apache Web Server

If Apache is not running, for whatever reason,  you can start it using the following command:

				
					$ sudo systemctl start apache2
				
			

Again, you can verify if Apache is running  as follows:

				
					$ sudo systemctl status apache2
				
			

Alternatively, you can visit the server’s IP address as we demonstrated earlier on.

How to Stop Apache Web Server

To stop the Apache service, run the command:

				
					$ sudo systemctl stop apache2
				
			

To be sure that the Apache service is no longer running,  run the command:

				
					$ sudo systemctl status apache2
				
			

You should get some output showing that Apache is no longer running.

How to Restart Apache Web Server

In case you make a change in any of Apache’s configuration files, you can effect the change by restarting Apache service as follows.

				
					$ sudo systemctl restart apache2
				
			

Instead of restarting Apache which causes a momentary service disruption, you apply the changes immediately by reloading Apache service as shown:

				
					$ sudo systemctl reload apache2
				
			

How to Enable Apache Web Server

In addition to starting , stopping and restarting Apache, you might also consider enabling the Apache service to start upon every reboot. To achieve this , simply run the following command.

				
					$ sudo systemctl enable apache2
				
			

Thank you for reading How To Start / Stop / Restart Apache 2 Web Server Linux Ubuntu. We shall conclude.

How To Start / Stop / Restart Apache 2 Web Server Linux Ubuntu Conclusion

In this guide, we demonstrated how to install Apache web server. We futher went ahead and showed you how to manage Apache service by performing various tasks such as starting, stopping and restarting the web server. Your feedback on this guide is welcome. For more information about Apache, visit the official website.

To read more Apache content navigate to our blog here.

Avatar for James Kiarie
James Kiarie

Hello everyone! My name is James, a certified Linux Administrator, and a tech enthusiast with over 5 years of experience in penning down high-quality guides on Linux and Cloud technologies. Outside work hours I enjoy working out, swimming, listening to music, and reading fiction novels.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x