How to install Apache Web Server on Ubuntu 20.04?
Overview
The Apache web server is one of the most widely used web servers in the world. It offers a host of powerful capabilities, including modules that can be loaded dynamically, powerful media support as well as full integration with various well-liked programs.
This tutorial will show you how to set up the Apache server on a host running Ubuntu version 20.04.
Prerequisites
There are certain prerequisites that need to be met before you begin.
Ubuntu 22.04-equipped system
A regular user (non-root) having Sudo privileges
Internet connection
Knowledge of Command Line Interface (CLI)
Get Started
Step 1: Setting up Apache
Apache can be installed using customary tools (package management) since it is part of Ubuntu's usual software repositories.
Let's start by incorporating the most recent upstream updates by using the following command:
Now install apache2 package by using the following command:
After you've confirmed the installation process, apt will now install Apache along with all required components.
Step 2: Checking the Web Server
The latest Ubuntu version 20.04 launches Apache after the installation procedure is complete and the web server will be operational by now.
Ensure that the service runs by verifying it by using the following command:
This result shows that the service launched properly. However, requesting a webpage from Apache is the most effective approach to testing this.
Through your IP address, you can browse the default home page of Apache to make sure the program is functioning properly. There are several ways to obtain your server's IP address from the command prompt interface if you are unsure of it.
Enter the following at the command prompt on your server:
A list of addresses with spaces between them will be returned. To find out if they function, you can test each one on your system.
Utilizing the Icanhazip program is a different choice that should provide you with your IP address:
Once you know your server's IP address, type it into the address bar of your browser as http://server_ip.
The default Apache web page for Ubuntu version 20.04 should appear:
This page ensures Apache is now operating properly. Additionally, it contains certain fundamental details regarding the locations of key Apache files as well as the directories.
Step 3: Handling the Apache Services
Now that the web server is operational, let's review some fundamental systemctl administration commands.
Type the following to terminate the web server:
When a web server is halted, enter the following command to restart it:
Restart the service once again after stopping it by typing:
Most of the time, Apache can reload without losing connections if you are only making configuration-based changes. Use the following command to accomplish this:
When a server boots up, Apache is set up by default to launch immediately. Disable this behavior if that is not your requirement by using:
Type the following command to make the service start up again at boot:
When the server restarts, Apache will now launch automatically.
Step 4: Setting up of Virtual Hosts (Optional)
Using virtual hosts, you can host several domains on a single Apache web server by encapsulating configuration information.
For your domain, make the following directory:
Next, use the $USER variable to specify who owns the directory:
Your web roots' permissions should be correct if you haven't modified the umask value, which controls the default file permissions. The following command can be used to check your permissions to determine if they are configured appropriately such that the owner has written, read, and execute permissions while only groups and other users have read and executed permissions:
Next, utilizing nano or your preferred editor, make a test index.html file as follows:
Add the given template HTML inside:
When you're done, save and shut the file.
It is important to construct virtual configuration files with the appropriate directives to enable Apache to deliver this content. Let's create a new configuration file by using the following command:
Paste the configuration block that follows:
When you're done, save and shut the file.
Let's now enable the file using:
Let's check for configuration issues next:
To put your modifications to work, restart Apache:
Your domain name should now be served by Apache. You may verify this by typing http://my_domain on your browser.
Conclusion
Now that your web server is set up, you have a variety of options for the content types you can offer and the technology you can utilize to give users a richer experience.
Last updated