How to Install Apache Web Server on CentOS 7 Print

  • apache, centos 7, web server, httpd, systemctl, linux, server administration, installation
  • 1

Installing Apache web server on CentOS 7 is straightforward using the yum package manager and systemctl commands. Apache (httpd) is a reliable, open-source web server that powers millions of websites worldwide, and it integrates seamlessly with CentOS 7's systemd service management system.

Installing Apache on CentOS 7

To install Apache web server (httpd package) on CentOS 7, use the following yum command as root or with sudo privileges:

yum install httpd

This command downloads and installs Apache along with all required dependencies. The installation typically completes within a few minutes depending on your server's internet connection.

Managing Apache Service at Boot

After installation, you need to configure whether Apache starts automatically when your server boots.

Enable Apache to Start on Boot

To ensure Apache starts automatically every time your server reboots, run:

systemctl enable httpd.service

You will see output similar to this confirming the service is enabled:

ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'

Disable Apache from Starting on Boot

If you need to prevent Apache from starting automatically, use:

systemctl disable httpd.service

Starting, Stopping, and Restarting Apache

CentOS 7 uses systemctl to manage services. Here are the essential commands for controlling Apache:

Start Apache Service

To start the Apache web server:

systemctl start httpd.service

Stop Apache Service

To stop Apache completely:

systemctl stop httpd.service

Restart Apache Service

To restart Apache (useful after configuration changes):

systemctl restart httpd.service

Checking Apache Status

To verify whether Apache is currently running on your CentOS 7 server, use:

systemctl is-active httpd.service

This command returns "active" if Apache is running or "inactive" if it's stopped.

For more detailed status information including recent log entries, you can use:

systemctl status httpd.service

Configuring Firewall for Apache

After installing Apache, you need to allow HTTP and HTTPS traffic through the firewall:

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

These commands open ports 80 (HTTP) and 443 (HTTPS) so visitors can access your website.

Testing Your Apache Installation

Once Apache is running, open a web browser and navigate to your server's IP address. You should see the default Apache test page confirming successful installation. The default document root is located at /var/www/html/ where you can place your website files.

Frequently Asked Questions

What is the difference between httpd and Apache?

There is no difference. The terms are used interchangeably. "httpd" stands for HTTP daemon and is the actual package name on CentOS 7, while "Apache" refers to the Apache HTTP Server project. When you install httpd on CentOS 7, you are installing Apache web server.

Why won't Apache start after installation?

Common reasons include port conflicts (another service using port 80), firewall restrictions, or configuration file syntax errors. Check the status with systemctl status httpd.service and review logs at /var/log/httpd/error_log for specific error messages. Ensure no other web servers are running on the same ports.

How do I reload Apache configuration without restarting?

To reload Apache configuration files without dropping active connections, use systemctl reload httpd.service. This gracefully reloads configuration changes while keeping the service running, which is preferable to a full restart for production environments.

Where are Apache configuration files located on CentOS 7?

The main Apache configuration file is located at /etc/httpd/conf/httpd.conf. Additional configuration files are typically stored in /etc/httpd/conf.d/ directory. Log files are found in /var/log/httpd/ and the default web root directory is /var/www/html/.

If you need assistance with Apache installation or server configuration on your hosting plan, the OBHost support team is available 24/7 to help. Visit our contact page or email support@obhost.org for expert guidance.


Was this answer helpful?

« Back