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 updatesudo apt install apache2apache2 --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 httpdsudo yum install httpdhostname -I122.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 listAvailable 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 -I172.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 apache2Stop Apache service
sudo systemctl stop apache2Restart Apache service
sudo systemctl restart apache2Reload Apache service
sudo systemctl reload apache2know status
sudo systemctl status apache2Using Service commands
Start Apache service
sudo service apache2 startStop Apache service
sudo service apache2 stopRestart Apache service
sudo service apache2 restartReload Apache service
sudo service apache2 reloadknow status
sudo service apache2 statusSummary
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.
