Installing Apache is a must for users who want to host or manage a website. As such, they have to choose between the available operating systems that support this web server software. And while Linux might have a niche following and not as much of a user count, it is a powerful and efficient OS when it comes to running a web server. Thus, we have dedicated an entire article to cover the various methods a user can install Apache on different Linux distros.
Table of contents
What is Apache?
But the question remains, what is Apache? Sure, we know it is open-source, free cross-platform web server software. But it is as if we have said nothing. Apache is an HTTP server that can host different websites. While there are web services such as WordPress that can create a website, Apache is needed to host said websites.
And since it is an open-source initiative, it has a dedicated community of developers who contribute majorly to the maintenance and enhancement of the web server. Moreover, Apache is a popular software as over 40% of websites use it for hosting. And that too globally.
Apache Software Foundation was the first to develop this software back in 1995, and since then, it has become a staple in web hosting. Not only is it fast, but equally reliable. Furthermore, users can always customize it to their liking, using extensive extensions and modules library.
Prerequisites to install Apache on a Linux distro:
As things stand, it is not always simple to install Apache on a Linux distro. There are quite a few requirements that the user has to meet before, such as:
- APR and APR Utility – Users have to ensure that they have the APR and APR-Util working on their distribution. Otherwise, they are required to download the necessary packages from Apache APR and unpack them to /httpd_source_tree_root/srclib/apr and /httpd_source_tree_root/srclib/apr-util
- Perl-Compatible Regular Expressions Library or PCRE – Next, the users have to install, if not available, the PCRE library which is no longer bundled with the HTTPD command. Thus, the users must download the source code from http://www.pcre.org. If the system is still unable to find the pcre-config script, use the –with-pcre parameter to point to it.
- Memory or Disk space – Users also have to ensure at least 50 MB of free disk space for the Apache installation.
- ANSI-C Compiler and Build System – Another point to note is the ANSI-C compiler which should be installed on the system. Apache devs recommend using the GNU-C compiler or GCC.
- Accurate time format – HTTP protocol is reliant on time and date. Hence, the users should ensure the time sync function of the system is working fine.
Installing Apache on Linux:
Now, we can proceed with the installation. There are two different methods for Apache installation. If the user wants to install the basic version, they can directly install it after updating the respective repository, as shown in method 1. Otherwise, they can build it from scratch using the source code, as covered in method 2.
Method 1. Using the Command Terminal for installation
The following method utilizes the command terminal to install Apache on different Linux distros.
On Ubuntu and Debian
Step 1. First, launch the command terminal using Ctrl + Alt + T.
Step 2. Then, update the APT repository.
sudo apt update
sudo apt-get update
Step 3. Lastly, install Apache.
sudo apt install apache2
Note – Apache is available on most distros by default. Hence, you can use the APT package to install it.
On Red Hat, Fedora, Amalinux, Rocky, CentOS, Oracle, and Amazon
Step 1. Start the command terminal.
Step 2. Now, update the DNF repository.
sudo dnf update
Step 3. Finally, install Apache using HTTPD.
sudo dnf install httpd
Method 2. Compiling and installing from source
In this method, users can compile and build Apache using the source code. The steps are:
Step 1. First, use a web browser and go to the Apache HTTP server download page.
Step 2. Download the Apache HTTP server package from the website.
Step 3. Now launch the command terminal. Make sure you have root access. Otherwise, use the sudo command.
Step 4. Use the following code to extract the source:
sudo gzip -d httpd-NN.tar.gz
Step 5. Then decompress the file using the tar command:
sudo tar xvf httpd-NN.tar
Step 6. A new directory will get created. Navigate to it by using the cd command.
Step 7. Finally, build the parts for Apache.
Step 8. And lastly, install the build on your system.
sudo make install