fbpx

In this article, we will go over the steps to install Apache on CentOS.

Apache is a widely used web server software that allows you to serve web pages to users over the internet. It is a free and open-source software that is highly configurable and can be customized to meet the needs of your specific web application.

Prerequisites

Before we get started, there are a few prerequisites that need to be met. You will need:

  • A CentOS server running on your machine. You can download the latest version of CentOS from the official website.
  • A user account with root privileges.

Step 1: Update the system

Before installing Apache on CentOS, it is important to update the system to ensure that it is up to date with the latest software patches and security updates. You can do this by running the following command:

sudo yum update

This will download and install all available updates for your system.

Step 2: Install Apache on CentOS

Once the system is up to date, you can begin installing Apache. To do this, run the following command:

sudo yum install httpd

This will install the Apache web server software and all of its dependencies.

Install Apache on CentOS

Step 3: Start Apache

After the installation is complete, you can start the Apache on CentOS service by running the following command:

sudo systemctl start httpd
sudo systemctl enable httpd
[root@Virtono-Tutorials ~]# sudo systemctl start httpd
[root@Virtono-Tutorials ~]# sudo systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@Virtono-Tutorials ~]#

This will start the Apache service, allowing it to serve web pages to users over the internet.

Step 5: Verify Apache

Once Apache on CentOS is installed and started, you can verify that it is running by visiting your server’s IP address or domain name in a web browser. You should see the Apache default page, which confirms that Apache is running correctly.

You can find your server’s IP address by running the following command:

hostname -I
Verify Apache on CentOS

Step 6: Set up Virtual Hosts

Virtual hosts allow you to host multiple websites on a single server, each with their own domain name, content, and configuration.

First, you need to create a directory to store the website files. This can be done with the following command:

sudo mkdir /var/www/example.com

Replace “example.com” with the domain name of your website.

Next, you need to grant permissions to the directory you just created so that Apache on CentOS can read and write to it. This can be done with the following command:

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

Now you need to create a virtual host configuration file. This file tells Apache which domain name to listen for and which directory to use to serve the website files.

Create a new virtual host configuration file with the following command:

sudo nano /etc/httpd/conf.d/example.com.conf

Replace “example.com” with the domain name of your website.

Add the following content to the file:

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

This configuration file sets up a virtual host that listens for requests on port 80 (HTTP) for the domain name “example.com” and “www.example.com“. It serves files from the directory you created in step 1, and logs errors and access to the website.

Save and close the file when you are done.

sudo systemctl restart httpd

Conclusion

In this article, we have gone over the steps to install Apache on CentOS. By following these steps, you should now have a fully functional Apache web server running on your CentOS server, allowing you to serve web pages to users over the internet. If you encounter any issues during the installation process, be sure to check the CentOS documentation for more information or seek help from the CentOS community.


1 Comment

How To Install Apache On AlmaLinux 9.1 - Virtono Community · May 24, 2023 at 9:30 AM

[…] the system update is complete, you can proceed with installing the Apache on AlmaLinux web server. AlmaLinux uses the DNF package manager, which makes the installation […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.