• WordPress
  • cPanel
  • Softaculous
  • KVM Virtualization
  • Vmware Virtualization
  • Proxmox
Monday, May 12, 2025
LinuxBoost
  • Home
  • Almalinux
  • CentOS
  • Debian
  • Fedora
  • Ubuntu
  • Red Hat Enterprise Linux
  • Rocky Linux
  • OpenSUSE
  • Arch Linux
  • Oracle Linux
No Result
View All Result
LinuxBoost
  • Home
  • Almalinux
  • CentOS
  • Debian
  • Fedora
  • Ubuntu
  • Red Hat Enterprise Linux
  • Rocky Linux
  • OpenSUSE
  • Arch Linux
  • Oracle Linux
LinuxBoost
  • Home
  • Almalinux
  • CentOS
  • Debian
  • Fedora
  • Ubuntu
  • Red Hat Enterprise Linux
  • Rocky Linux
  • OpenSUSE
  • Arch Linux
  • Oracle Linux

How to set up a web server on CentOS 7 using Apache

in CentOS, Linux OS
How to set up a web server on CentOS 7 using Apache

A web server is software that allows web browsers to access and display content on the internet. Apache is one of the most popular web servers available and it can be easily installed on CentOS 7. In this blog post, we will guide you through the process of How to set up a web server on CentOS 7 using Apache.

Before you begin, make sure that you have a CentOS 7 server set up and that you have root access. You will also need to make sure that you have an internet connection as we will be downloading and installing software.

Step 1: Install Apache

To install Apache on CentOS 7, you will need to run the following command in the terminal:

sudo yum install httpd

This command will download and install Apache and all its dependencies. Once the installation is complete, you can start the Apache service using the following command:

sudo systemctl start httpd

To make sure that Apache starts automatically at boot time, run the following command:

sudo systemctl enable httpd

Step 2: Configure Firewall

By default, CentOS 7 comes with a firewall that blocks incoming traffic. To allow web traffic to reach the server, we need to add a firewall rule. To do this, we will use the firewall-cmd command.

First, check if the firewall is running:

sudo systemctl status firewalld

If it is not running, start it using the following command:

sudo systemctl start firewalld

Next, add a rule to allow HTTP traffic:

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

This command tells the firewall to add a rule to allow HTTP traffic permanently. Finally, reload the firewall to apply the changes:

sudo firewall-cmd --reload

Step 3: Configure Apache

Apache’s configuration files are located in the /etc/httpd/conf directory. The main configuration file is httpd.conf. To edit this file, run the following command:

sudo nano /etc/httpd/conf/httpd.conf

In this file, you can configure various settings such as the server name, document root, and virtual hosts. By default, Apache serves files from the /var/www/html directory. You can change this by modifying the DocumentRoot directive.

To test that Apache is working, create a simple HTML file in the document root directory:

sudo nano /var/www/html/index.html

Add some content to the file, such as “Hello, world!”. Save and close the file. Next, open your web browser and enter the IP address of your server in the address bar. You should see the content of your HTML file.

Step 4: Secure Apache

By default, Apache is not secure. There are several steps you can take to secure your web server:

  • Disable directory listing: Apache can show a list of files in a directory if there is no index file. To disable this feature, add the following line to your httpd.conf file:
Options -Indexes
  • Enable SSL/TLS: SSL/TLS is a protocol that encrypts traffic between the server and the client. To enable SSL/TLS, you will need to obtain a certificate from a trusted certificate authority (CA). You can then configure Apache to use the certificate by adding the following lines to your httpd.conf file:
SSLEngine on
SSLCertificateFile /path/to/your/certificate.crt
SSLCertificateKeyFile /path/to/your/private.key
  • Enable ModSecurity: ModSecurity is a web application firewall that can protect your web server from attacks. To enable ModSecurity, install the

In conclusion, setting up a web server on CentOS 7 using Apache is a straightforward process that can be completed by following the steps outlined in this blog post. Once you have installed Apache and configured it to serve files from the desired directory, you can test your web server by creating a simple HTML file and accessing it through a web browser. It is important to also take steps to secure your web server, such as disabling directory listing, enabling SSL/TLS, and enabling ModSecurity. By doing so, you can ensure that your web server is safe and secure for your users to access.

ShareTweet
Previous Post

How to secure your CentOS 7 system with firewall and SELinux policies

Next Post

How to set up a web server on CentOS 7 using Nginx

Related Posts

How to Install Tomcat on Rocky Linux

How to Install Apache Tomcat on Rocky Linux

How to Set up NTP Server on Rocky Linux

How to Set up NTP Server on Rocky Linux

How to Install Bacula Backup Server on Rocky Linux

How to Install Bacula Backup Server on Rocky Linux

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Golden Host VPS
  • Privacy Policy
  • Terms and Conditions
  • About Us
  • Contact Us

Copyright © 2023 linuxboost.com All Rights Reserved.

  • Privacy Policy
  • Terms and Conditions
  • About Us
  • Contact Us

Copyright © 2023 linuxboost.com All Rights Reserved.