Are you want to set up a web server for your website but not sure where to begin? No worries, we’ve got your back. In this comprehensive guide, we’ll take you through the process of install the Apache Web Server on CentOS 7 to make the journey as smooth as possible.
Introduction
Generally the Apache web server, often referred to as Apache HTTP Server, is one of the most popular and reliable web servers in the world. If you’re using CentOS 7 as your server’s operating system, you’re in the right place to learn how to install Apache with ease. For that reason this article will provide you with a straightforward, step-by-step guide on how to install the Apache web server on CentOS 7, using familiar words and helpful transition phrases.
Prerequisites
Before we dive into the installation process of Installing Apache Web Server on CentOS 7, make sure you have the following prerequisites in place:
- A CentOS 7 system with root or sudo access, to set this up, follow our guide : Initial Setup CentOS 7 Server: Secure and Efficient, you can deploy this on a physical machine or a virtual environment like VMware or VirtualBox.
- A stable internet connection to download packages
- Basic familiarity with command-line operations.
Installing Apache Web Server on CentOS 7
To get Apache up and running on your CentOS 7 server and make the most of its capabilities for web hosting, simply following these steps:
Step 1: Updating the System on CentOS 7
Start by updating the package list to ensure you have the latest information about available packages using the following command:
$ sudo yum update
$ sudo yum upgrade
This ensures your system is up-to-date before installing new software.
Step 2: Firewall Configuration on CentOS 7
Before your web server can be accessed from the internet, you need to allow HTTP (80) or HTTPS (443) traffic through the firewall. Execute these commands to open the necessary port. You can use the following command:
$ sudo firewall-cmd --permanent --add-service=http
$ sudo firewall-cmd --permanent --add-service=https
After that, reload the firewall to put these new rules into effect:
$ sudo firewall-cmd --reload
This step ensures that your server is reachable via a web browser. Now that we’ve got our system prepared, let’s move on to the Apache installation.
Step 3: Install Apache Web Server on CentOS 7
Basically Apache can be found in the standard software collection that comes with CentOS. This makes it super easy to install using the yum
package manager.
Afterwards, let’s move on to the next step. If you’ve set up a non-root sudo user, as mentioned in the earlier requirements, the next thing to do is to update the local Apache httpd
package index to ensure it’s in sync with the latest updates from upstream using the following command:
$ sudo yum install httpd
The ‘httpd
‘ package is the one CentOS uses for Apache. Shortly to the next step, you can start the Apache service and enable it to launch on boot:
$ sudo systemctl start httpd
$ sudo systemctl enable httpd
With these commands, Apache is up and running, and it will automatically start whenever your CentOS 7 system boots up.
Verify that the service is running with the following command:
$ sudo systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: disabled)
Drop-In: /etc/systemd/system/httpd.service.d
└─php-fpm.conf
Active: active (running) since Wed 2023-09-23 01:10:34 WIB; 2min 15s ago
Docs: man:httpd.service(8)
Main PID: 285920 (httpd)
Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes served/sec: 0 B/sec"
Tasks: 213 (limit: 23169)
Memory: 41.3M
CPU: 188ms
CGroup: /system.slice/httpd.service
├─285920 /usr/sbin/httpd -DFOREGROUND
├─285921 /usr/sbin/httpd -DFOREGROUND
├─285922 /usr/sbin/httpd -DFOREGROUND
├─285923 /usr/sbin/httpd -DFOREGROUND
└─285924 /usr/sbin/httpd -DFOREGROUND
Sept 23 01:10:34 apache systemd[1]: Starting The Apache HTTP Server...
Sept 23 01:10:34 apache systemd[1]: Started The Apache HTTP Server.
Sept 23 01:10:34 apache httpd[285920]: Server configured, listening on: port 80
As shown above from this output, it seems that the service has started without any issues. But the most reliable way to check this is by requesting a page from Apache. To verify that the software is working as it should, you can simply visit the default Apache landing page using your IP address.
Step 4: Testing Apache Web Server on CentOS 7
To make sure everything is working as expected, when open a web browser and enter your server’s IP address, you should see the Apache default welcome page, which indicates that the installation was successful.
http://your_server_ip
This page not only shows that Apache is doing its job correctly but also provides essential details about key Apache files and where you can find them.
Step 5: Setting Up Virtual Hosts
Basically Apache’s default setup works fine for simple situations. However, if you have special requirements, you should customize it. The main configuration file, usually called httpd.conf
, is located in the /etc/httpd/conf/
folder.
You have the flexibility to set up Apache for different purposes, including virtual hosting, directory indexing, and access control. To make the required changes, open this configuration file in your favorite text editor using the following command.
sudo vi /etc/httpd/conf.d/sammlearning.conf
Paste the following lines in the file.
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName test.sammlearning.com
ServerAlias test.sammlearning.com
DocumentRoot /var/www/sammlearning
ErrorLog /var/log/httpd/sammlearning.com-error.log
CustomLog /var/log/httpd/sammlearning.com-access.log combined
</VirtualHost>
Now, let’s create a folder to store all the files for the new domain ‘test.sammlearning.com
‘. When you install the Apache (httpd) package, it automatically creates a default ‘DocumentRoot’ directory at ‘/var/www/’. Generally Apache uses this directory as the starting point for delivering content, which is often called the root directory.
$ sudo mkdir -p /var/www/sammlearning
Then create a sample index.html file for testing the new domain.
$ sudo vi /var/www/sammlearning/index.html
Inside the file, add your HTML content, for example paste the following lines:
<html>
<head>
<title>Welcome to sammlearning.com!</title>
</head>
<body>
<h1>Congratulation! The virtual host for <span style="color:blue; font-size: 24px;">sammlearning.net</span> is now up and running!</h1>
</body>
</html>
After making changes, save the configure of Apache and restart Apache to apply the modifications with following command:
$ sudo systemctl restart httpd
For this reason you can insert your IP Address and Domain Name in your localhost.
$ sudo vi /etc/hosts
172.32.1.223 test.sammlearning.com
Step 6: Viewing Your Web Page
Once you’ve finished setting everything up, open a web browser. Then, type in your domain name and hit ‘Enter’. Below, as can be seen a screenshot that shows an example of your newly set up virtual hosting page.
Conclusion
Congratulations! You’ve successfully installing the Apache Web Server on CentOS 7 and created a basic web page. At any rate this is just the beginning of your web hosting journey. As shown above this step-by-step guide you can now start building and hosting your website with ease.
When you install Apache on your CentOS 7, you unlock a wealth of potent web hosting abilities. By following this step-by-step guide, you’ll smoothly complete the installation, granting you access to improved performance, security, and scalability. As a matter of fact with Apache as your web server, you’re all set to create a robust and secure environment for hosting websites, applications, and services. So, embrace the power of Apache and take your online presence to greater heights.
To sum up, we’ve covered:
- Updating CentOS 7
- Configuring the firewall
- Installing Apache Web Server
- Testing your web server
- Adding and viewing website content
Also Read Our Other Guides :
- How To Install and Configure Apache on Rocky Linux 9
- How To Install Apache 2.4 on Ubuntu 22.04
- How To Install PHP 8.2 on CentOS 7 / RHEL 7
- How To Install RTMP Server with Nginx on CentOS 7
- How To Install Nginx on CentOS 7: A Comprehensive Guide
- How To Build NGINX from Source (Compile) on Centos7
- How To Install Varnish Cache for Nginx on Rocky Linux 9
Finally, now you have learned how to install and configure Apache on your CentOS 7. You’re now ready to explore the world of web hosting. Happy hosting!