In this guide, we will explore installing Apache Web server on a Centos 8 server.
The Apache HTTP Server(Apache), is one of the most popular free and open-source cross-platform web server software, released under the terms of Apache License 2.0.
The Apache is popular as part of the LAMP setup, being the A in the Acronym. The apache server functionality can be extended with the many available modules.
Prerequisites
- Up to date Centos 8 Server
- Root access to the server (Or user with sudo access)
- Firewall set up to allow traffic to port 80 and 443
Installing Apache
Ensure packages are up to date:
|
|
Apache is available in the default CentOS 8 software repositories as httpd
. You can check info about it using this command:
|
|
You should see something similar to this:
|
|
Install it with this command:
|
|
Enabling http and https in firewalld
If you have firewalld up and running, you need to enable the http and https ports using these commands:
|
|
Now reload the firewall to put these new rules into effect:
|
|
Starting and enabling httpd service
By default, the service is not started. Confirm with the following command:
|
|
Output:
|
|
Start the service with this command:
|
|
You will receive an active status when the service is running Confirm that its now working fine:
|
|
The above confirms that apache is working fine now.
To confirm that the service is accessible, please head to the url http://server_ip to see if you can get the httpd page:
If you don’t know the server up, use the following command in your terminal:
|
|
Once you visit that page,if everything is working fine you should see apache default page
To ensure that the service is always started on boot, use this systemctl command:
|
|
Setting Up Virtual Hosts
With Apache, it is possible to host multiple sites on the same server where the Apache is running. This can always be achieved using multiple domains each representing a site that the server is hosting.
Apache virtual hosts are similar to Nginx server blocks . Each virtual host will have configuration details for a single host. You can have as many virtual hosts as you want.
In this example, we will use the domain site1.citizix.com
for the virtual host but be free to use the domain of your choice. Please note that the DNS for the domainto be used should already be configured to point to the IP address of the server.
Confirm that with:
|
|
Creating directory and sample content
The default page of apache is configured as a default virtual host serving content from /var/www/html
. It’s a best practice to create the directory of your site in the /var/www
directory since its a best practice to serve from there.
Lets create a directory for our site with the following command:
|
|
Lets create a simple index.html
page to serve from our site. You will require vim installed for this to work, if not use this command:
|
|
Edit the file:
|
|
Add content to the file:
|
|
Finally, lets make sure that the current user owns the site directory:
|
|
Creating virtual host
Apache Virtual host files specifies the configuration of each sites and tell the Apache web server how to respond to various domain requests.
The Apache configurations will be stored in the directory /etc/httpd/conf.d/
. Lets create a config for our site:
|
|
Add the following content:
|
|
This will tell Apache the following:
ServerName
and ServerAlias - name of the host to serveDocumentRoot
- where to find the root directly that holds the publicly accessible web documentsErrorLog
- where to store error logs for this siteCustomLog
- where to store request logs for this particular site
Save and close the file when you are finished
Testing the Virtual Host
Now that the configuration is in place, we need to test that everything is working as expected.
First restart apache to reload config:
|
|
List the contents of the /var/log/httpd/
directory to see if Apache created the log files:
If all is well, you should see output similar to this:
|
|
If all is well, Apache will now serve your domain name. You can test this by navigating to http://site1.citizix.com
, where you should see the information for the site we set up.
The above screenshot confirms that the virtual host is successfully configured and serving content.
If you need to host multiple other sites, repeat the steps above for the sites you want.
Conclusion
We managed to install and set up Apache web server in the above instructions in Centos 8 Server.