In this article, we want to teach you how to install an Apache web server on AlmaLinux 8.
The Apache HTTP Server is free and open-source software that allows users to deploy their websites on the internet.
You can learn more about AlmaLinux by visiting this article about Introducing AlmaLinux on the Orcacore website.
Steps To Install an Apache web server on AlmaLinux 8
To install the Apache web server on AlmaLinux 8 you need to follow these requirements first.
You need to log in as a non-root user to your server with Sudo privileges. and a basic setup for the firewall. to do this you can check out our article about the Initial server setup with AlmaLinux 8.
When you are done with these requirements let’s start installing Apache on AlmaLinux 8.
Install Apache on AlmaLinux 8
To install Apache you need to update the DNF package manager with the following command:
sudo dnf update
Now install the Apache package with the following command:
sudo dnf install httpd
When your installation is completed, you need to configure Apache to serve content over HTTPS and HTTP.
Configure Firewall for Apache
We assumed that you installed firewalld from the requirements. now run the commands below:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https
Then, reload the firewall to apply the changes:
sudo firewall-cmd --reload
At this point, you can start your service and check the webserver.
Check Apache Status on AlmaLinux
You need to start Apache on AlmaLinux 8 manually by the following command:
sudo systemctl start httpd
You can check that your Apache web server is active and running with the following command:
sudo systemctl status httpd
In your output you should see:
Output httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor pres> Active: active (running) since Mon 2021-09-06 08:05:21 EDT; 7s ago Docs: man:httpd.service(8) Main PID: 52316 (httpd) Status: "Started, listening on: port 80" Tasks: 213 (limit: 11409) Memory: 30.9M CGroup: /system.slice/httpd.service ├─52316 /usr/sbin/httpd -DFOREGROUND ├─52317 /usr/sbin/httpd -DFOREGROUND ├─52318 /usr/sbin/httpd -DFOREGROUND ├─52319 /usr/sbin/httpd -DFOREGROUND └─52320 /usr/sbin/httpd -DFOREGROUND
Now you can access to default Apache landing page. for that, you need your server’s IP address.
To get your IP address you can use the following command:
Or you can use the curl command to request your IP from icanhazip.com. run the following command:
curl -4 icanhazip.com
When you have your IP address, type it in your web browser to access the default Apache landing page.
You should see a page similar to this:
If you see this page, it shows that Apache is working correctly.
At this point, you are finished with how to install Apache on AlmaLinux 8. let’s see some basic management processes.
Manage Apache process on AlmaLinux 8
Here your service is active and running on your server. you can use the systemctl command to manage the service.
To stop the service use:
sudo systemctl stop httpd
Start the service with:
sudo systemctl start httpd
You stop and start the service again with the following command:
sudo systemctl restart httpd
If you made configuration changes, you need to apply the changes with the following command:
sudo systemctl reload httpd
Apache is configured to start automatically when the server boots. if you don’t want to happen this, run the following command:
sudo systemctl disable httpd
To re-enable the service starts at boot, use the command below:
sudo systemctl enable httpd
The default configuration for Apache will allow your server to host a single website. If you plan on hosting multiple domains on your server, you will need to configure virtual hosts on your Apache webserver.
Let’s see how to set up Apache virtual hosts on ALmaLinux 8.
Set up Apache virtual hosts on AlmaLinux 8
The concept of virtual hosts allows more than one Web site on one system or Web server. The servers are different by their hostname.
To set up Apache virtual hosts on AlmaLinux 8 follow these steps and replace our domain name with yours:
- Create an HTML directory for apache.orcacore.net with the following command:
sudo mkdir -p /var/www/apache.orcacore.net/html
2. Now you should create a directory to store log files for the site:
sudo mkdir -p /var/www/apache.orcacore.net/log
3. Set ownership of the Html directory with the $USER environmental variable by the following command:
sudo chown -R $USER:$USER /var/www/apache.orcacore.net/html
4. Here you need to set default permissions for your webroot. use:
sudo chmod -R 755 /var/www
5. Create a sample index.html page with your favorite editor. here we use vi editor:
sudo vi /var/www/apache.orcacore.net/html/index.html
Then, add the following HTML sample to your file:
<html> <head> <title>Welcome to apache.orcacore.net!</title> </head> <body> <h1>Success! The apache.orcacore.net virtual host is working!</h1> </body> </html>
Save and close the file when you are done.
To set up Apache virtual host on AlmaLinux 8, you need to create sites-available and sites-enabled directories.
6. Create directories with the following command:
sudo mkdir /etc/httpd/sites-available /etc/httpd/sites-enabled
7. Here you need to edit Apache’s main configuration file and add a line declaring an optional directory for additional configuration files. open the file with:
sudo vi /etc/httpd/conf/httpd.conf
Then, add the line below to the end of the file:
When you are finished save and close your file.
8. In this step, you need to create your Apache virtual host file by creating a new file in the sites-available directory:
sudo vi /etc/httpd/sites-available/apache.orcacore.net.conf
Now, add the configuration block into your file:
<VirtualHost *:80> ServerName www.apache.orcacore.net ServerAlias apache.orcacore.net DocumentRoot /var/www/apache.orcacore.net/html ErrorLog /var/www/apache.orcacore.net/log/error.log CustomLog /var/www/apache.orcacore.net/log/requests.log combined </VirtualHost>
9. At this point, Create a symbolic link for each virtual host in the sites-enabled directory:
sudo ln -s /etc/httpd/sites-available/apache.orcacore.net.conf /etc/httpd/sites-enabled/apache.orcacore.net.conf
10. To set a universal Apache policy run the command below:
Note: if you disable SELinux before, you don’t need to run this command.
sudo setsebool -P httpd_unified 1
11. check the context type that SELinux gave the /var/www/apache.orcacore.net/log directory:
sudo ls -dZ /var/www/apache.orcacore.net/log/
12. Generate and append to web application log files:
sudo semanage fcontext -a -t httpd_log_t "/var/www/apache.orcacore.net/log(/.*)?"
13. use the restorecon command to apply these changes:
sudo restorecon -R -v /var/www/apache.orcacore.net/log
Restart your web server with the following command:
sudo systemctl restart httpd
Now you are ready to test your Apache virtual host configuration on AlmaLinux 8.
Type this in your web browser with your domain name:
You will see a page similar to this:
At this point, you learn How to install an Apache web server on AlmaLinux 8. Also, for more information, you learn how to set up Apache virtual hosts on AlmaLinux 8.
Hope you enjoy it.
You may be like these articles:
Install an Apache web server on AlmaLinux 9
Install an Apache web server on Rocky Linux 8