How to Install Apache on AlmaLinux?

AlmaLinux is a potential replacement for CentOS and is compatible with all CentOS services and applications. AlmaLinux is a free open source product with no licenses or restrictions and the current 8.3 version is supported until 2029.

Ensure you have created a Linode account and Compute Instance before we start, also set the timezone, configure hostname, create a limited user account, and harden SSH access.

Make sure you have installed AlmaLinux already to proceed with the Apache installation. You can check the  GitHub site for the instructions to switch to AlmaLinux.

 

  1. To check the current update, use the dnf check-update If there is any update available, update the Linode. If any of the kernel components are updated, restart the Lionde.

 

sudo dnf check-update 

sudo dnf update

sudo reboot

 

  1. Now install the Apache packages.
sudo dnf install httpd httpd-tools

 

  1. After the installation, Apache will not start automatically. Use the systemctl utility to start and enable it.
sudo systemctl start httpd  

sudo systemctl enable httpd 

 

Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

 

  1. Check the Apache status by using systemctl status It must be in active state and display the running states.
sudo systemctl status httpd 

httpd.service - The Apache HTTP Server

Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor prese>

Active: active (running) 

Docs: man:httpd.service(8)

Main PID: 5933 (httpd)

Status: "Running, listening on: port 80"

 

Enable Apache connection to configure the AlmaLinux Firewall

By default, AlmaLinux comes with pre-installed and enabled firewall services. Further, some setup is required to enable Apache connection to pass through the firewall.

Remember: You should keep the firewall turned ON (Highly recommended).

  1. Check whether firewalld is already enabled or not.
sudo systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon

Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor p>

Active: active (running) 

 

  1. To allow Apache HTTP and HTTPS connections via the firewall, add the rules.
sudo firewall-cmd --zone=public --add-service=http --permanent

 sudo firewall-cmd --zone=public --add-service=https --permanent
  1. Now restart firewalld to apply the changes.
sudo firewall-cmd --reload
  1. Confirm the registration of the application.
sudo firewall-cmd --list-all
public (active)

target: default

...

services: cockpit dhcpv6-client http https ssh

...

Note:

  1. sudo systemctl start firewalld – To restart the firewall
  2. sudo systemctl stop firewalld – To temporarily disable the firewall
  3. sudo systemctl disable firewalld.- To permanently disable the firewall

In addition to firewalld, AlmaLinux is also pre-installed with the security tool SELinux. In some conditions, the two applications may not work together. To verify the status of SELinux by using the command – sestatus and for debugging process, SELinux can be temporarily disabled using the command – sudo setenforce 0.

Check the Apache Web Server and Host a Web Page

  1. Ensure that the Apache server is working properly and using a web browser, check the IP address of Linode. You will get the AmlaLinux test page if you have configured everything properly.
  2. The default web page location for the server is /var/www/html. If your website has a home page, copy index.html into the var/www/html directory.

Note: Create an index.html file in the /var/www/html directory if you do not already have one. It confirms that the web server page is serving from this directory.

cp path-to-home-page/index.html /var/www/html
  1. This directory web access is blocked by the SELinux configuration. To update the directory’s security context, use the command chcon to ensure the web page is accessible.
chcon -R -t httpd_sys_rw_content_t /var/www/html
  1. Again, navigate to the IP address of the Linode. At this point, the content of the home page in your domain should be visible.

 

To get more updates you can follow us on Facebook, Twitter, LinkedIn

Subscribe to get free blog content to your Inbox
Loading

Written by actsupp-r0cks