How to Install Apache on CentOS 8

0 4 minutes read
| Published on: March 1, 2023 | Last updated on: July 23, 2023

This article will talk about how to instal and run the Apache web server on CentOS 8.

The most popular web server worldwide is Apache HTTP server. It is a powerful, open-source, free, and cross-platform HTTP server that can be expanded with a huge selection of modules.

Installing Apache

The installation of Apache is fairly simple and includes access to the default CentOS repositories.

httpd is the name of the Apache package and service on RHEL-based distributions. Run the following command as root or a user with sudo permissions to install Apache:

sudo yum install httpd

After installation is finished, turn on and launch the Apache service:

sudo systemctl enable httpd
sudo systemctl start httpd

Check the service’s status to ensure that it is active:

sudo systemctl status httpd

The final result should resemble this:

● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2022-12-1 15:24:58 UTC; 6s ago
...

Adjusting the Firewall

On Centos 8, FirewallD is the pre-installed firewall program.

Apache creates firewalld service files with pre-set rules for allowing access to HTTP (80) and HTTPS (443) ports during installation.

The required ports will be permanently opened by the following commands:

sudo firewall-cmd --permanent --zone=public --add-service=httpsudo firewall-cmd --permanent --zone=public --add-service=https 
sudo firewall-cmd --reload

Managing Apache

What follows is a detailed breakdown of the Apache configuration file structure, as well as recommendations for optimal administration of the Apache web server.

The /etc/httpd directory houses all of Apache’s configuration files.

The httpd.conf file in the /etc/httpd/conf directory is where Apache’s primary settings are stored.

The main Apache configuration file incorporates all.conf-ending configuration files in the /etc/httpd/conf.d subdirectory.

The /etc/httpd/conf.modules.d folder contains configuration files used to load specific Apache modules.

Each Apache vhost file must have a.conf extension and live in the /etc/httpd/conf.d folder. Create as many virtual hosts as you like. When you make a virtual host (vhost) for each domain, you reduce the server’s administration burden.

Establishing and sticking to a consistent naming convention is a good idea. As an illustration, if the domain is mydomain.com, the corresponding configuration file should also be named mydomain.com. conf Apache log files (access log and error log) are located in the /var/log/httpd/ directory. In order to keep track of what went wrong in each vhost, it’s best to keep the access and error logs separate.

You’re free to choose any directory you like as the root directory of your domain. Webroot is most frequently used in the following places:

/home/<user_name>/<site_name>
/var/www/<site_name>
/var/www/html/<site_name>
/opt/<site_name>

Conclusion

Your CentOS 8 server now has Apache installed successfully. Now that you’re prepared, you can use Apache as a web or proxy server to begin deploying your applications.

Similar to how you manage other systemd units, you can manage the Apache service.

Please leave a comment if you have any queries or suggestions.

IF YOU ARE HAVING PROBLEMS WITH THIS GUIDE, EMAIL US AT:

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

Copyright @2022-2024 All Right Reserved – PCPlanet

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. You understand and give your consent that your IP address and browser information might be processed by the security plugins installed on this site. By clicking “Accept”, you consent to the use of ALL the cookies.
.
Accept Read More

Privacy & Cookies Policy