How to Install Apache on Ubuntu 18.04

Table of Contents
Install Apache on Ubuntu 18.04
Apache is the most popular and most used HTTP web server in the world. Apache is the opensource, cross-platform, powerful, stable, reliable and free web server providing features which can be extended by the wide variety of modules. It is also used as a reverse proxy server in different scenarios. In this tutorial, you are going to learn how to install Apache on Ubuntu 18.04.
Prerequisites
Before you start to install Apache on Ubuntu 18.04. You must have the root user account credentials of your system.
Install Apache
Apache is already available in Ubuntu default software repositories. So in this tutorial, we will install Apache by using apt
package manager.
First, update the apt
package manager index by typing the following command:
sudo apt update
In Debian based system Apache service is called apache2
. To install apache2
package run below command.
sudo apt install apache2
After completion of the above command, Apache is installed on your system. Run the following command to check apache
service status.
sudo systemctl status apache2
The output should look like:
● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d `-apache2-systemd.conf Active: active (running) since Sun 2019-02-06 10:56:11 PDT; 2min 41s ago Main PID: 3143 (apache2) Tasks: 55 (limit: 2321) CGroup: /system.slice/apache2.service |-3143 /usr/sbin/apache2 -k start |-3144 /usr/sbin/apache2 -k start `-3145 /usr/sbin/apache2 -k start
Adjust the Firewall
After installing Apache it is necessary to modify UFW firewall rules to open HTTP and HTTPS ports assuming you have configured UFW firewall already.
Now to open HTTP and HTTPS ports for Apache run following command:
sudo ufw allow 'Apache Full'
To verify changes run following command:
sudo ufw status
The output should look like:
Status: active To Action From -- ------ ---- 22/tcp ALLOW Anywhere Apache Full ALLOW Anywhere 22/tcp (v6) ALLOW Anywhere (v6) Apache Full (v6) ALLOW Anywhere (v6)
As you can check in above output access to Apache is allowed.
Verify Apache Installation
Open your favorite browser and open below URL to verify Apache
installation.
http://YOUR_IP_ADDRESS_OR_DOMAIN_NAME/
The output should be:

If you get above output screen which contains basic information about Apache configuration, then you have successfully verified Apache installation on Ubuntu.
Manage Apache Process
Following are some basic commands to manage Apache
processes.
Restart apache web server type following command:
sudo systemctl restart apache2
Stop web server type following command:
sudo systemctl stop apache2
To start web server type following command:
sudo systemctl start apache2
Reload configuration file typing following command:
sudo systemctl reload apache2
Apache service will start after boot to disable this run below command:
sudo systemctl disable apache2
To enable Apache service to start after boot run:
sudo systemctl enable apache2
Apache important default files
Following are the Apache important files and directories:
- Apache main configuration file is located at
/etc/apache2/apache2.conf
- Apache main configuration files directory:
/etc/apache2/
- Ports where apache can listen are defined in
/etc/apache2/ports.conf
- Virtual Host files stored at
/etc/apache2/sites-available
and to activate each file should be linked to/etc/apache2/sites-enabled
directory - Error log file located at
/var/log/apache/error.log
- Access log file located at
/var/log/apache/access.log
- Document root for web files
/var/www/html/
Conclusion
You have successfully learned how to install Apache on Ubuntu 18.04. If you have any queries please don’t forget to comment out.
LATEST POSTS
-
How to install Laravel PHP Framework With Nginx on Ubuntu 18.04
-
How to Install XAMPP on Manjaro 18
-
Secure Apache with Let’s Encrypt SSL on Debian 9
-
How to Install PyCharm on Ubuntu 18.04
-
How to Install CMake on Debian 10
-
How to Install XAMPP on Fedora 29
-
How to Add Swap Space on Ubuntu 18.04
-
How to Reboot Linux System with Command Line
-
How to Install Apache Tomcat 9 on CentOS 7
-
Secure Nginx with Let’s Encrypt SSL on CentOS 7
-
Best Ways to Check MySQL Version
-
How to Install Opera Browser on Ubuntu 18.04