This post shows students and new users steps to install, configure and use Apache HTTP web server on Ubuntu Linux. Apache is the most popular open source web server in the world. Chances are many of the websites you visit today mostly likely are running Apache HTTP server.
If you’re thinking of running a website, you’re more likely to go with Apache or have support for Apache on web hosting companies than other web servers. Apache provides powerful features which can be extended by a wide variety of modules.
If you’re a student or new user learning Linux, the easiest place to start learning is on Ubuntu Linux. Ubuntu is the modern, open source Linux operating system for desktop, servers and other devices.
To get started with 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 across the internet. If you want to learn how to install and use it on Ubuntu Linux, then continue below.
Apache is available in Ubuntu repositories so we can easily install it using the apt package management tool.
To install Apache, run the commands below:
sudo apt update sudo apt install apache2
The commands above will install Apache HTTP server.
Now, to find out if Apache is actually installed and running, use the status check command below.
sudo systemctl status apache2
The command will output similar lines below when Apache is running.
apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2021-09-15 12:29:40 CDT; 10s ago Docs: https://httpd.apache.org/docs/2.4/ Process: 4860 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS) Main PID: 4864 (apache2) Tasks: 55 (limit: 4651) Memory: 4.7M CGroup: /system.slice/apache2.service ├─4864 /usr/sbin/apache2 -k start ├─4865 /usr/sbin/apache2 -k start └─4866 /usr/sbin/apache2 -k start Sep 15 12:29:40 ubuntu2004 systemd: Starting The Apache HTTP Server... Sep 15 12:29:40 ubuntu2004 apachectl: AH00558: apache2: Could not reliably determine the >
How to allow Apache through Ubuntu firewall
If you’re running Ubuntu in protected mode with firewall enabled, then you’ll have to allows HTTP (80) and HTTPS (443) to Apache web server. In most cases, Ubuntu server are running without firewall enabled. However, run the commands below if you’re not sure.
If you’re using UFW to manage Ubuntu firewall, then run the commands below to allow traffic.
sudo ufw allow 'Apache Full'
That will allow full traffic to Apache.
With the firewall opened, simply browse to the server hostname or IP address to see if Apache default page is up.
You should see Apache default welcome page.
How to configure Apache on Ubuntu Linux
Now that Apache is installed, there are important folders and locations that you should be aware of. Other Linux systems might have different folder structures and configuration files.
On Ubuntu Linux, these are Apache directory structures and configuration files.
All Apache configuration files are located in the /etc/apache2 directory. This is considered Apache home directory.
Apache main configuration file is /etc/apache2/apache2.conf. Global configuration settings are done in the file, but this file is rarely ever touched.
Port configurations, including changing the default listen ports are specified in this file /etc/apache2/ports.conf. The ports in here are what Apache listens on for traffic.
Apache Virtual Hosts files are stored in /etc/apache2/sites-available directory. This is the directory where individual website are defined. Website configurations are not used by Apache until they’re activated. Once activated, they are then linked to the /etc/apache2/sites-enabled directory.
To activate websites so they’re linked to the /etc/apache2/sites-enable directory, these the command below. (replace example.com.conf with your VirtualHost file)
sudo a2ensite example.com.conf
The command above will create a symlink of the website configuration files found in the sites-available directory to the sites-enabled directory.
To deactivate a virtual host use the command below. (replace example.com.conf with your website VirtualHost file).
sudo a2dissite example.com.conf
Apache uses modules to enhance and add additional functionalities and they are located in the /etc/apache2/mods-available/ directory.
Modules are only available to load with Apache when they’re enabled and symlinked to the /etc/apache2/mods-enable/ directory.
The a2enconf and a2disconf commands can enable or disable modules. Once modules are activated and linked to the mod-enable directory, they’re then made available to Apache to load.
Apache also has log files (access.log and error.log) are located in the /var/log/apache/ directory. You can view access and error logs in these files on Ubuntu.
There are other Apache configuration files that might be available in Ubuntu that are not listed above. For more Apache configurations and how to use it, we’ll continue posting valuable tutorial here.
This post showed you how to install and use Apache on Ubuntu Linux. If you find any error above or have something to add, please use the comment form below.