How To Install Apache on CentOS 7

Install Apache on CentOS 7

In this tutorial, we will show you how to install and configuration of Apache on your CentOS 7. For those of you who didn’t know, Apache Web Server is an open-source Web server creation, deployment, and management software. Initially developed by a group of software programmers, it is now maintained by the Apache Software Foundation. Apache HTTP Server is the most popular web server in the world and has been so since April 1996. It played a key role in the growth of the World Wide Web. It is estimated that Apache Server is serving 54.2% of all active websites and 53.3% of the top servers across all domains.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation Apache web server on a CentOS 7 server.


  • A server running one of the following operating systems: CentOS 7.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • Basic knowledge of Linux command line.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Apache on CentOS 7

Step 1. To ensure a smooth installation process and maintain the security of your server, it is essential to update your system before installing any new software. Updating the system will fetch the latest security patches, bug fixes, and software versions available in the repositories. To update your CentOS 7 system, run the following command:

yum clean all
yum -y update

Step 2. Installing Apache on CentOS 7.

Apache is available in CentOS 7’s default software repositories, making the installation process straightforward. To install Apache, run the following command:

yum install httpd openssl mod_ssl

Once Apache has finished installing, the httpd service will need to be started and enabled so it will run automatically when the server starts:

sudo systemctl restart httpd
sudo systemctl status httpd
sudo systemctl enable httpd

To verify that Apache is running, use the following command:

sudo systemctl status httpd

If Apache is running correctly, you will see an output similar to this:

● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2024-04-14 10:30:00 UTC; 5s ago
Docs: man:httpd(8)
Main PID: 1234 (httpd)
Status: "Processing requests..."
Tasks: 6
Memory: 23.0M
CGroup: /system.slice/httpd.service
├─1234 /usr/sbin/httpd -DFOREGROUND
├─1235 /usr/sbin/httpd -DFOREGROUND
├─1236 /usr/sbin/httpd -DFOREGROUND
├─1237 /usr/sbin/httpd -DFOREGROUND
├─1238 /usr/sbin/httpd -DFOREGROUND
└─1239 /usr/sbin/httpd -DFOREGROUND

You can verify that Apache is really running by opening your favorite web browser and entering the URL http://your-server's-address. you should get a “Testing 123″ page similar to the image below:

Install Apache on CentOS 7

Step 3. Configure Firewalld for Apache.

By default, CentOS 7 comes with a firewall (firewalld) that blocks incoming network traffic. To allow access to your Apache web server from the internet, you need to configure the firewall to permit HTTP (port 80) and HTTPS (port 443) traffic.

To allow HTTP and HTTPS traffic, run the following command:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https

After adding the necessary rules, reload the firewall to apply the changes:

systemctl restart firewalld.service

Step 4. Configure Virtual Hosts.

Virtual hosts allow you to host multiple websites on a single Apache server. Each virtual host can have its own domain name, document root, and configuration settings.

Create a new configuration file for your virtual host in the /etc/httpd/conf.d/ directory. For example, sudo nano /etc/httpd/conf.d/example.com.conf

Add the following configuration to the file, replacing example.com with your domain name and /var/www/example.com/html with the desired document root path:

<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/html
ErrorLog /var/log/httpd/example.com-error.log
CustomLog /var/log/httpd/example.com-access.log combined

Save the file and exit the editor.

Next, create the document root directory for your virtual host:

sudo mkdir -p /var/www/example.com/html

Set the appropriate ownership and permissions for the document root directory:

sudo chown -R apache:apache /var/www/example.com/html
sudo chmod -R 755 /var/www/example.com

Restart the Apache service to load the new virtual host configuration:

sudo systemctl restart httpd

Your virtual host is now set up and ready to serve content. Place your website files in the document root directory (/var/www/example.com/html) and access your website using the domain name.

Congratulations! You have successfully installed Apache. Thanks for using this tutorial for installing the Apache webserver on the CentOS 7 system. For additional help or useful information, we recommend you check the official Apache website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!



r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button