AlmaLinux is tagged as a forever-free Linux Operating System Distribution because of the numerous benefits it has to offer to its user community. If you were too attached to CentOS before it got discontinued, think of AlmaLinux as its renamed and continued OS version.
AlmaLinux is a free and open-source server-oriented Linux operating system distribution is a carbon copy of the discontinued CentOS. It offers the same user footprints with features like Errata and Secure Boot Support. Also, it is easy to migrate from CentOS to AlmaLinux.
[ You might also like: How to Sync Two Web Servers in Linux Automatically ]
The reputation of the Apache webserver speaks for itself. It is free and open-source implies that you can use it for your individual or commercial projects. Apache is reliable and stale such that you won’t have to worry about downtime issues when your web apps are online.
Also, its security patches are frequently updated to make sure that no bugs resurface while you are hosting a website in a production environment. Finally, Apache is beginner-friendly and easy to configure making it an ideal web server candidate for AlmaLinux.
Install Apache in AlmaLinux
Make sure you have the needed Sudoer user privileges before proceeding with the installation of Apache on AlmaLinux.
Update AlmaLinux system to accommodate the latest security patches and fixes.
$ sudo dnf update
Now execute the following command to install Apache and other Apache-associated tools for it to function correctly.
$ sudo dnf install httpd httpd-tools
In most circumstances, Apache usually starts after its package installation successfully completed. To be certain that it is running, execute the following command to start the Apache service.
$ sudo systemctl start httpd
Next, enable Apache so that it continuously executes even when/after your AlmaLinux server reboots.
$ sudo systemctl enable httpd
After enabling Apache, we can now check on its status to make sure it is up and running.
$ sudo systemctl status httpd
The Apache web server is up and running on AlmaLinux.
Enable Apache on Firewall in AlmaLinux
The installed and enabled Apache web server is fully operational within the machine/computer hosting AlmaLinux server OS. For Apache to be accessible to the outside world via a web browser, we have to consider two ports (80 and 443).
Apache uses port 80 to communicate with web clients via HTTP and port 443 is for secure HTTPS traffic.
$ sudo firewall-cmd --permanent --zone=public --add-service=http $ sudo firewall-cmd --permanent --zone=public --add-service=https
For these changes to be effective, firewall-cmd needs to be reloaded.
$ sudo firewall-cmd --reload
The final step is to make sure your Apache installation can serve web applications from the browser.
http://YOUR-IP-ADDRESS
Hosting a Website with Apache in AlmaLinux
The default configuration of Apache is enough to host a single website, but if you want to host multiple websites, you should use the Apache Virtual Hosts directive.
The default Document path /var/www/html holds the single website, but if you wish to host multiple websites, you need to create a separate virtual host for each site.
For example, to host another domain website called ‘linuxshelltips.in‘, you need to create a separate virtual host directory and a log directory to keep the site’s log files with correct permissions.
$ sudo mkdir -p /var/www/linuxshelltips.in/html $ sudo mkdir -p /var/www/linuxshelltips.in/log $ sudo chown -R $USER:$USER /var/www/linuxshelltips.in/html $ sudo chmod -R 755 /var/www
Now create a sample index.html file (landing page) to test the site.
$ sudo vi /var/www/linuxshelltips.in/html/index.html
Populate it with some data.
<!DOCTYPE html> <html> <head> <title>Welcome to linuxshelltips.i</title> </head> <body> <h1>LinuxShellTips Introduces linuxshelltips.in</h1> <p>You have successfully accessed linuxshelltips.in home page!</p> </body> </html>
Creating a Virtual Host in AlmaLinux
Now create the sites-available and sites-enabled directories for keeping the virtual host file and the virtual host’s symbolic link respectively.
$ sudo mkdir /etc/httpd/sites-available $ sudo mkdir /etc/httpd/sites-enabled
Next, define the sites-enabled directory location in the main Apache configuration file that needs access to the virtual host files.
$ sudo vi /etc/httpd/conf/httpd.conf
At the bottom, add the following line before saving and closing it.
IncludeOptional sites-enabled/*.conf
Finally, create a virtual host file for our domain linuxshelltips.in.
$ sudo vi /etc/httpd/sites-available/linuxshelltips.in
Next, add the following virtual host configuration with the domain name you are using.
<VirtualHost *:80> ServerAdmin www.linuxshelltips.in ServerAlias linuxshelltips.in DocumentRoot /var/www/linuxshelltips.in/html ErrorLog /var/www/linuxshelltips.in/log/error.log CustomLog /var/www/linuxshelltips.in/log/access.log combined </VirtualHost>
Save the file and close the terminal editor.
To active our virtual host file, you need to create a symbolic link between the sites-available and the sites-enabled directories.
$ sudo ln -s /etc/httpd/sites-available/linuxshelltips.in /etc/httpd/sites-enabled/linuxshelltips.in.conf
Finally, restart the Apache and make sure it is running.
$ sudo systemctl restart httpd $ sudo systemctl status httpd
Now you should be able to see the hosted index.html page through your domain name.
http://linuxshelltips.in
Secure Apache with Let’s Encrypt in AlmaLinux
To enable HTTPS on your domain website, you need to use Free Let’s Encrypt SSL certificate by installing Certbot and mod_ssl.
$ sudo dnf install epel-release $ sudo dnf install certbot python3-certbot-apache mod_ssl
Once Certbot is installed, you can run the following command to obtain your Free SSL certificate for your domain.
$ sudo certbot --apache -d linuxshelltips.in
The downloaded certificates are placed under a subdirectory named after your domain in the /etc/letsencrypt/live directory.
Once you obtain a certificate for your domain, you can verify the SSL certificate at the following URL.
https://www.ssllabs.com/ssltest/analyze.html?d=linuxshelltips.in
Apache is a dynamic and reputable web server which when fused with a server OS like AlmaLinux creates a very performant and efficient environment.