Apache is one of the most popular and longstanding HTTP servers. It’s an open-source and cross-platform web server software developed and maintained by Apache Software Foundation. It’s easy to set up and learn to use, which has led to its widespread adoption for small and large scale websites.
In this guide, we’ll go over the step by step instructions to install Apache on AlmaLinux. Feel free to follow along with us, whether you have a fresh AlmaLinux installation or have migrated from CentOS to AlmaLinux.
In this tutorial you will learn:
- How to install Apache web server on AlmaLinux
- How to control Apache web server with systemctl commands
- How to open firewall for HTTP (port 80) and HTTPS (port 443)
- How to host a website with Apache
- How to install SSL certificate with Let’s Encrypt
|Category||Requirements, Conventions or Software Version Used|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Install Apache on AlmaLinux
Open a command line terminal and follow along with the steps below to install Apache on your system, and learn the basics of using the HTTP server.
- First step is to install Apache via dnf package manager by executing the following command.
# dnf install httpd
- Once it’s installed, you can use systemd’s systemctl commands to control the service.
Enable or disable Apache from starting at system boot:
# systemctl enable httpd OR # systemctl disable httpd
Start or stop Apache web server:
# systemctl start httpd OR # systemctl stop httpd
Check to see if Apache is running, and any recent log messages about the httpd service.
# systemctl status httpd
You can also perform a hard restart of the Apache service, or a graceful reload of configuration files with the following two commands, respectively.
# systemctl restart httpd OR # systemctl reload httpd
- If you have firewalld turned on in AlmaLinux, you’ll need to allow port 80 for HTTP traffic and 443 for HTTPS if you plan to use SSL. This will allow outside traffic to access your website.
# firewall-cmd --zone=public --add-service=http --permanent # firewall-cmd --zone=public --add-service=https --permanent # firewall-cmd --reload
- You can test to make sure everything is working correctly by navigating to
http://localhoston your system. You should be greeted by the default Apache page, as seen below.
- With Apache up and running, we’re ready to configure our website. The default directory for our website’s files is /var/www/html. Move your files here, or begin by replacing the default index.html greeting page. In this example, we’ll just make a simple HTML document to see the changes reflected on the website.
# echo Apache on AlmaLinux > index.html # mv index.html /var/www/html
To learn more about virtual hosts, which allows you to host multiple websites or change the configuration of your current one (such as the directory where files are stored, domain name, as well as the error logs, etc), check our guide on Apache virtual hosts explained.
- If you have SELinux enabled on AlmaLinux, you’ll need to execute the following command to change the context for the
/var/www/htmldirectory. Otherwise, you’ll end up with a 403 Forbidden error when visiting the site.
# chcon -R -t httpd_sys_rw_content_t /var/www/html
- To setup SSL encryption using Let’s Encrypt, install the certbot utility with the following command.
# dnf install certbot python3-certbot-apache
- Configure the SSL certificate by executing the following command and going through the prompts that pop up. The last question will ask you if you want to redirect HTTP requests straight to HTTPS. It’s recommended that you opt for this. Obviously, for this to work the domain must point correctly to our publicly accessible server IP.
# certbot --apache
In this guide, we saw how to install Apache on AlmaLinux. We also learned how to control the Apache service via systemd, configure the firewall to allow outside traffic, begin setting up a website, and obtain an SSL certificate through Let’s Encrypt.
This will be enough to get you started hosting a basic website. Many modern websites also utilize other web technologies like PHP or a database. These modules are easily installed alongside Apache, and the software can be downloaded from AlmaLinux’s package manager.