Apache is the most popular web server in the world.
If you want to learn how to install and manage it on Ubuntu, this post should be a good starting point.
This brief tutorial shows students and new users how to install Apache HTTP server on Ubuntu 20.04 | 18.04.
Apache is a free, opensource, cross-platform and the most popular web server in use today. Whether you want to run a personal website or company portal, Apache is a powerful webserver that can serve all your users.
Installing Apache on Ubuntu is pretty simple and straightforward. In fact, Apache packages are available in Ubuntu repositories.
All one has to do is run the apt get command to install it.
To get started with installing Apache, follow the steps below:
Step 1: Install Apache
As we mentioned above, installing Apache is simple and straightforward. Because it stable packages come with Ubuntu, simply run the commands below to install.
sudo apt update sudo apt install apache2
After installing the package above, you can check Apache status by running the commands below:
sudo systemctl status apache2
That should display similar lines as shown below:
apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2020-04-30 15:23:46 CDT; 13s ago Docs: https://httpd.apache.org/docs/2.4/ Main PID: 2882 (apache2) Tasks: 55 (limit: 4657) Memory: 5.0M CGroup: /system.slice/apache2.service ├─2882 /usr/sbin/apache2 -k start ├─2884 /usr/sbin/apache2 -k start └─2885 /usr/sbin/apache2 -k start Apr 30 15:23:46 ubuntu2004 systemd: Starting The Apache HTTP Server...
Step 2: Managing Apache
When you install Apache, it might be good to how to manage the server’s services. To learn how to stop,start, restart Apache services, the commands below will be helpful.
To stop Apache services, run the commands below:
sudo systemctl stop apache2
To start it, run the commands below:
sudo systemctl start apache2
To restart it, run the commands below:
sudo systemctl restart apache2
Reload allows you to apply new configuration changes without restarting the services.
sudo systemctl reload apache2
If Ubuntu server is protected by a firewall you’ll need to open HTTP 80 and HTTP 443 ports to allow communication to the Apache.
Assuming you’re using Ubuntu default firewall, run the commands below:
sudo ufw allow 'Apache Full'
To validate that Apache is working, open your web browser and browse to the server IP address or hostname.
If you see a similar page below, then Apache is working as expected.
Step 3: Important Locations
By default, these important locations are automatically created on Ubuntu servers. Below are some details of each location.
All Apache configuration files are located in: /etc/apache2 directory.
Apache main configuration file is at /etc/apache2/apache2.conf.
Apache will listen on ports defined in the file /etc/apache2/ports.conf.
Each website will be hosted as a Virtual Host. All Virtual Hosts file are stored in /etc/apache2/sites-available.
Virtual Hosts in the location above will not be enabled unless they’re linked in this directory: /etc/apache2/sites-enabled.
To activate a Virtual Host, run the commands below:
To disable, run the commands below
sudo a2ensite example.com.conf
sudo a2dissite example.com.conf
Configurations that are responsible for loading modules in Apache are located in this directory: /etc/apache2/mods-available.
Modules are not enabled unless they’re linked in this directory: /etc/apache2/mods-enable.
Modules can be enabled and disabled using the commands below:
That should be a good started point.
More configurations and files are available in the main configuration directory. Look them, read about them and use them.
This post showed you how to install Apache HTTP server on Ubuntu 20.04 | 18.04. If you find any error above, please use the comment form below to report it.
You may also like the post below: