In this article, we'll explain how to install Apache HTTP Server on AlmaLinux. We will install from source and built-in installation package.
It's open-source HTTP server for modern operating systems including UNIX and Windows. Apache HTTP server provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards. It is developed and maintained by a community of developers under the auspices of the Apache Software Foundation.
Install Apache HTTP Server on AlmaLinux
Let's start with the installation process.
There are two ways to install Apache HTTP server. First way is simple, we just need to execute one command and it gets installed. Second way is installing from source. It is bit complex process and need to have Linux command knowledge.
Let's check the first way of the installation.
Keep the server up-to-date
First, we need to update the server using following command:
sudo dnf update -y
Install Apache HTTP Server
Now, execute the following command to install Apache HTTP server.
sudo dnf install httpd -y
Add port in firewalld
firewall-cmd --add-port={80,443}/tcp --permanent
firewall-cmd --reload
Start and enable Apache service
sudo systemctl start httpd
sudo systemctl enable httpd
That's it, we have installed Apache HTTP server.
Now, let's check the second way of the installation.
Install the dependencies
There are 2 options we can install dependencies. First way is as follow:
sudo dnf groupinstall "Development Tools" -y
Above command will install the all dependencies that required except expat-devel package but it also install unnecessary packages.
Second way is, install necessary packages. We have tested it in normal scenario. If you have any special scenario, the installation process or Apache it may gives error later. If any point you get an error, execute first way.
sudo dnf install expat-devel pcre pcre-devel make gcc openssl-devel python3 autoconf libtool -y
Download the latest release
Now, we need to download the latest release from [official website](http://httpd.apache.org/download.cgi).
wget https://dlcdn.apache.org/httpd/httpd-2.4.58.tar.gz
Extract the file
Next, we will extract it and change our working directory. Execute set of following commands:
tar xzvf httpd-2.4.58.tar.gz
cd httpd-2.4.58/srclib
Download Apr and Apr-util
We need it download Apr and Apr-util. It is required step to do. You can check the [official download](https://apr.apache.org/download.cgi) page for latest version. Execute set of following command:
wget https://dlcdn.apache.org//apr/apr-1.7.4.tar.gz
tar xvzf apr-1.7.4.tar.gz
mv apr-1.7.4 apr
wget https://dlcdn.apache.org//apr/apr-util-1.6.3.tar.gz
tar xvzf apr-util-1.6.3.tar.gz
mv apr-util-1.6.3 apr-util
cd ..
Install Apache HTTP server
Now, let's start the installation process. We need to run configure command.
First, we need to build configure script using following command:
sudo ./buildconf
Next, execute configure command with few options. You can modify the option as per your requirements. Here the official website, where you can find the options.
./configure --enable-ssl --with-mpm=event --with-included-apr
Next, compile and install the files using following commands:
sudo make
sudo make install
If you want to customize the default configuration file, you can do it using following command:
vi /usr/local/apache2/conf/httpd.conf
Note: Replace /usr/local/apache2 if you have custom prefix.
Create systemd file
If you want to start and stop the httpd service, we need to create systemd file. Execute following commands:
vi /etc/systemd/system/httpd.service
Add following lines:
[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/apache2/bin/apachectl -k start
ExecReload=/usr/local/apache2/bin/apachectl -k graceful
ExecStop=/usr/local/apache2/bin/apachectl -k graceful-stop
PIDFile=/usr/local/apache2/logs/httpd.pid
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Note: If you have mention --prefix with different path, you need to add that path here.
Reload and start the httpd service using following commands:
systemctl daemon-reload
systemctl start httpd
systemctl enable httpd
Configure firewall
If you have firewall enabled, you need to add 80 and 443 port in the firewall. Execute following commands:
firewall-cmd --add-port={80,443}/tcp --permanent
firewall-cmd --reload
Verify the installation
Finally, let's verify the installation.
sudo systemctl status httpd
Navigate to your browser and access it using your server IP.
That's it, we have seen how to install Apache HTTP Server on AlmaLinux from source as well as built-in package.