How to Install Apache on CentOS 8

How to Install Apache on CentOS 8

Apache is the web server that processes requests and serves web assets and content via HTTP. MySQL is the database that stores all your information in an easily queried format. PHP is the programming language that works with apache to help create dynamic web content.

Install apache on centOS 8; Through this tutorial, we will learn how to install and configure apache on centOS 8.

How to Install Apache on CentOS 8

Just follow the following steps to install apache on CentOS 8:

  • Step 1 – Update System Software Repository
  • Step 2 – Install Apache
  • Step 3 – Start and Manage Apache Web Server
  • Step 4 – Adjusting the Firewall
  • Step 5 – Managing Apache

Step 1 – Update System Software Repository

First of all, open terminal and command line and execute the following command into it to update system software repository:

sudo yum update

Step 2 – Install Apache

Once the system packages has been updated, then execute the following command on command line or terminal to install apache:

sudo yum install httpd

Step 3 – Start and Manage Apache Web Server

Once the installation is complete, execute the following command on command line or terminal to enable and start the Apache service:

sudo systemctl enable httpd
sudo systemctl start httpd

Then execute the following command on terminal or command line to verify apache services:

sudo systemctl status httpd

Step 4 – Adjusting the Firewall

During the installation, Apache creates firewall service files with predefined rules for allowing access to HTTP (80) and HTTPS (443) ports.

Execute the following commands will permanently open the necessary ports:

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

Step 5 – Managing Apache

Let’s see Apache configuration files are structured and the best practices for managing the Apache webserver.

  • All Apache configuration files are located in the /etc/httpd directory.
  • The main Apache configuration file is /etc/httpd/conf/httpd.conf.
  • Configuration files ending with .conf located in the /etc/httpd/conf.d directory are included in main Apache configuration file.
  • Configuration files that are responsible for loading various Apache modules are located in the /etc/httpd/conf.modules.d directory.
  • Apache vhost files must end with .conf and be stored in /etc/httpd/conf.d directory. You can have as many vhosts as you need. Creating a separate configuration file (vhost) for each domain makes the server easier to maintain.
    • It is a good practice to follow a standard naming convention. For example, if the domain name is mydomain.com then the configuration file should be named mydomain.com.conf
  • Apache log files (access_log and error_log) are located in the /var/log/httpd/ directory. It is recommended to have a different access and error log files for each vhost.
  • You can set your domain document root directory to any location you want. The most common locations for webroot include:
    • /home/<user_name>/<site_name>
    • /var/www/<site_name>
    • /var/www/html/<site_name>
    • /opt/<site_name>

Conclusion

Through this tutorial, we have learned how to install and configure apache on centOS 8.

Recommended CentOS Tutorials

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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