Installing RHEL7 or CentOS7 on a PC is fairly easy to do. In this tutorial, we will review the installation process step-by-step. Today’s focus will
Looking to establish a reliable and secure web presence? Learn how to Install Apache web server on CentOS and unlock the potential of your website today.
The Apache web server, commonly referred to as an HTTP/HTTPS server, is one of the most popular and widely used web servers in the world. In this tutorial, we’ll explore how to Install Apache web server on CentOS, a popular Linux distribution used for server applications.
Whether you’re a beginner looking to get started or an experienced web developer seeking to enhance your skills, this guide will provide you with everything you need to know to set up a secure web server on CentOS.
The Apache Software Foundation (ASF) was founded in March 25, 1999 (when it was officially incorporated). However, the Apache HTTP server development began some six years earlier in February 1993 with developers that would eventually be known as the Apache Group.
The initial members of the Apache Software Foundation consisted of the Apache Group: Brian Behlendorf (as the primary developer/contributor), Ken Coar, Miguel Gonzales, Mark Cox, Lars Eilebrecht, Ralf S. Engelschall, Roy T. Fielding, Dean Gaudet, Ben Hyde, Jim Jagielski, Alexei Kosut, Martin Kraemer, Ben Laurie, Doug MacEachern, Aram Mirzadeh, Sameer Parekh, Cliff Skolnick, Marc Slemko, William (Bill) Stoddard, Paul Sutton, Randy Terbush and Dirk-Willem van Gulik.
As of 2021, the ASF decentralized open-source community consists of about 1000 members and several open-source projects. Some of ASF’s main objectives include but are not limited to: providing legal protection to volunteers working on Apache projects and–prevent the Apache brand from being used by other organizations without permission.
This install procedure assumes that you already have RHEL/CentOS7 installed and updated. If not, install the CentOS7 operating system (OS) and revisit this page to proceed with the HTTP server setup. Also, you will need to have privileged access to become the root user.
First things first, it’s always best practice to update your system before proceeding with any package install. Run the following on the command-line:
# yum update -y
Now that our CentOS7 is up-to-date, we can proceed with installing the Apache HTTP package and associated dependencies.
# yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.umd.edu
* epel: epel.mirror.constant.com
* extras: mirrors.advancedhosters.com
* remi-php70: mirror.pit.teraswitch.com
* remi-php73: mirror.pit.teraswitch.com
* remi-safe: mirror.pit.teraswitch.com
* updates: mirror.ette.biz
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-97.el7.centos.2 will be reinstalled
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================================================
Package Arch Version Repository Size
=========================================================================================================================
Installing: httpd x86_64 2.4.6-97.el7.centos.2 updates 2.7 M
Transaction Summary
=========================================================================================================================
Reinstall 1 Package
Total download size: 2.7 M
Installed size: 9.4 M
Is this ok [y/d/N]: Y
After the installation is complete, there are few more steps left to do to ensure our web server is operational.
First, lets test things out and ensure the httpd service starts up properly for the first time. We can also enable the service to start up automatically on boot up.
# systemctl start httpd; systemctl enable httpd; systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/httpd.service.d
└─php-fpm.conf
Active: active (running) since Tue 2021-11-16 03:50:34 UTC; 14s ago Docs: man:httpd.service(8)
Main PID: 94043 (httpd)
Status: "Running, listening on: port 443, port 80"
Tasks: 213 (limit: 12436)
Memory: 25.4M
CGroup: /system.slice/httpd.service
├─94043 /usr/sbin/httpd -DFOREGROUND
├─94044 /usr/sbin/httpd -DFOREGROUND
├─94045 /usr/sbin/httpd -DFOREGROUND
├─94046 /usr/sbin/httpd -DFOREGROUND
└─94047 /usr/sbin/httpd -DFOREGROUND
...output omitted...
Now, we set the firewall rules to allow http and https traffic (we do plan on securing our web server so, HTTPS and SSL certs…but for now, lets proceed). By default, the built-in CentOS7 firewall blocks http/https traffic.
# firewall-cmd --zone=public --permanent --add-service=http
success
Allow HTTPS service by running the following command:
# firewall-cmd --zone=public --permanent --add-service=https
success
Reload the firewall settings:
# firewall-cmd --reload
success
Verify the firewall settings:
# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp1s0
sources:
services: cockpit dhcpv6-client http https ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
Enter the IP address (not the most secure option) or server domain name (preferred) into the address bar of your favorite browser! If all goes as planned, you should see the Apache Test Page (below): http://localhost or http://<ip-address>
Photo by admingeek from Infotechys
Now that we’ve established a running HTTP web server, we can secure it in a few additional steps.
Obtain an SSL/TLS certificate for your domain. You can get a free SSL/TLS certificate from Let’s Encrypt or purchase one from a trusted Certificate Authority (CA).
This involves editing your server configuration files to enable HTTPS, specifying the location of your SSL/TLS certificate and private key, and setting up redirects from HTTP to HTTPS.
Begin with installing the Apache module for enabling SSL.
# yum install mod_ssl
Once you have obtained your SSL/TLS certificate, copy the certificate and private key to the appropriate directories on your server. The certificate file should be saved as /etc/pki/tls/certs/yourdomain.crt
, and the private key file should be saved as /etc/pki/tls/private/yourdomain.key
. You may need to create these directories if they do not exist.
# sudo mkdir -p /etc/pki/tls/certs; sudo mkdir -p /etc/pki/tls/private
# sudo cp yourdomain.crt /etc/pki/tls/certs/
# sudo cp yourdomain.key /etc/pki/tls/private/
Edit your Apache configuration file (/etc/httpd/conf/httpd.conf
) to enable HTTPS. Add the following lines to the file:
LoadModule ssl_module modules/mod_ssl.so
Listen 443 https
Configure your virtual host to use HTTPS. Locate your virtual host configuration file (/etc/httpd/conf.d/yourdomain.conf
) and add the following lines to the file:
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/yourdomain.com/public_html
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/yourdomain.crt
SSLCertificateKeyFile /etc/pki/tls/private/yourdomain.key
Replace yourdomain.com
with your actual domain name, and DocumentRoot
with the path to your website’s root directory.
sudo systemctl restart httpd
https://yourdomain.com
. You should see a green padlock icon in the address bar, indicating that your website is using a secure HTTPS connection.That’s it! Your website is now hosted on an HTTPS web server, ensuring that all data exchanged between your server and your users is encrypted and secure. Was this article helpful to you? If so, leave us a comment below and share!
Related Posts
Installing RHEL7 or CentOS7 on a PC is fairly easy to do. In this tutorial, we will review the installation process step-by-step. Today’s focus will
Unlock the power of relational databases and streamline your data management processes by discovering how to easily install MySQL on CentOS – a must-know skill
In this article, we will review installing and using Git on Linux machines. Besides minor differences in syntax, the install commands and procedures are similar