This post shows students and new users the steps to install, configure and use the Apache HTTP web server on Ubuntu Linux. Apache is the most popular open source web server in the world. Most likely, many of the websites you visit today are running the Apache HTTP server.

If you are thinking of running a website, you are more likely to choose Apache or have Apache support from web hosting companies than other web servers. Apache provides powerful functions that can be extended by a wide variety of modules.

If you are a student or a new user learning Linux, the easiest place to start learning is on Ubuntu Linux. Ubuntu is the modern open source Linux operating system for desktops, servers, and other devices.

To start installing Apache HTTP server on Ubuntu Linux, follow the steps below.

How to use Apache HTTP server on Ubuntu Linux

As mentioned above, Apache is widely used on the internet. If you want to learn how to install and use it on Ubuntu Linux, continue below.

Apache is available in the Ubuntu repositories, so we can easily install it using the suitable package management tool.

To install Apache, run the following commands:

sudo apt update
sudo apt install apache2

The above commands will install the Apache HTTP server.

Now to find out if Apache is actually installed and running, use the health check command below.

sudo systemctl status apache2

The command will generate similar lines below when Apache is running.

How to allow Apache through the Ubuntu firewall

If you are running Ubuntu in protected mode with the firewall enabled, you will have to allow HTTP (80) and HTTPS (443) to the Apache web server. In most cases, the Ubuntu server runs without the firewall enabled. However, run the following commands if you are unsure.

If you are using UFW to manage the Ubuntu firewall, run the following commands to allow traffic.

sudo ufw allow 'Apache Full'

That will allow full traffic to Apache.

With the firewall open, just look up the server’s hostname or IP address to see if the Apache default page is active.

http://localhost

You should see Apache’s default welcome page.

How to configure Apache on Ubuntu Linux

Now that Apache is installed, there are important folders and locations that you should know about. Other Linux systems may have different folder structures and configuration files.

On Ubuntu Linux, these are Apache configuration files and directory structures.

All Apache configuration files are located in the / etc / apache2 directory. This is considered the Apache home directory.

The main Apache configuration file is /etc/apache2/apache2.conf. Global configuration settings are made in the file, but this file is rarely touched.

This file specifies the port settings, including changing the listener posts. /etc/apache2/ports.conf. The ports here are what Apache listens for for traffic.

Apache Virtual Hosts files are stored in / etc / apache2 / sites-available directory. This is the directory where individual websites are defined. Apache does not use website settings until they are activated. Once activated, they are linked to the / etc / apache2 / sites-enabled directory.

To activate websites to be linked to the / etc / apache2 / sites-enable directory, these are the command below. (replace example.com.conf with your VirtualHost file)

sudo a2ensite example.com.conf

The above command will create a symbolic link to the website configuration files found in the available sites directory to enabled sites directory.

To deactivate a virtual host, use the following command. (replace example.com.conf with your website’s VirtualHost file).

sudo a2dissite example.com.conf

Apache uses modules to enhance and add additional functionality and they are located in the / etc / apache2 / mods-available / directory.

Modules are only available to load with Apache when they are enabled and symbolically linked to the / etc / apache2 / mods-enable / directory.

the a2enconf and a2disconf Commands can enable or disable modules. Once the modules are activated and linked to the enable mod directory, they are then available for Apache to load.

Apache also has log files (access.log and error log) are in the / var / log / apache / directory. You can see the access and error logs in these files in Ubuntu.

There are other Apache configuration files that may be available in Ubuntu that are not listed above. For more Apache configurations and how to use it, we will continue to post a valuable tutorial here.

Conclusion:

In this tutorial we have seen how to install and use Apache on Ubuntu Linux. If you find any errors above or have something to add, use the comment form below.

Write A Comment