Install Apache2 Web Server on Ubuntu and CentOS – Step-by-Step Guide
☰ In this chapter, you will learn
- How to install Apache2 on Ubuntu and CentOS?
- How to Start/Stop/Restart/Reload/Status Apache services.
Apache2 is a widely used, open-source, and reliable web server for Linux, which is free of charge. You will find a large community for Apache2 support, making it easier to configure.
If you are planning to set up an HTTP web server on your Ubuntu or CentOS Linux VPS server, this tutorial will guide you through the installation and configuration of Apache2 step by step.
Installing Apache2
Ubuntu:
Login to your Ubuntu VPS server and execute the following command to install it.
sudo apt update
sudo apt install apache2
apache2 --version
[Sat Apr 27 16:10:59.172485 2024] [core:warn] [pid 1925] AH00111: Config variable ${APACHE_RUN_DIR} is not defined
CentOS:
sudo yum update httpd
sudo yum install httpd
hostname -I
122.27.142.103
Add Apache to Firewall
However, in most cases, Apache is enabled by the firewall. Still, it is necessary to check its existence in the firewall. If you find that Apache is not listed in the firewall, add it as follows:
sudo ufw app list
Available applications: Apache Apache Full Apache Secure OpenSSH
sudo ufw allow 'Apache'
Rule added Rule added (v6)
Check localhost
Upon completing the installation of Apache2, it's time to start Apache services and check whether localhost is working or not.
hostname -I
172.17.235.107
http:// 172.17.235.107/
Commands to Start/Stop/Restart Apache2 on Ubuntu
After successful installation of Apache2, it is necessary to learn some important commands to manage Apache2 process such as starting the Apache service, stopping the Apache service, Restarting the Apache service, etc.
Using systemctl commands.
Start Apache service
sudo systemctl start apache2
Stop Apache service
sudo systemctl stop apache2
Restart Apache service
sudo systemctl restart apache2
Reload Apache service
sudo systemctl reload apache2
know status
sudo systemctl status apache2
Using Service commands
Start Apache service
sudo service apache2 start
Stop Apache service
sudo service apache2 stop
Restart Apache service
sudo service apache2 restart
Reload Apache service
sudo service apache2 reload
know status
sudo service apache2 status
Summary
In this tutorial, you learned how to install Apache2 on Ubuntu and CentOS VPS servers. In the next article, you will learn how to create a sample web page and load it in a web browser. You will also discover where the web application is stored on your Ubuntu server.