Greetings, fellow tech enthusiasts! Are you struggling to install Apache web server on your CentOS operating system? Fear not, for in this journal article, we will guide you through the entire process step-by-step.
Table of Contents
- Introduction
- Prerequisites
- Step 1: Update CentOS
- Step 2: Install Apache Web Server
- Step 3: Configure Apache
- Step 4: Verify Apache
- Step 5: Create Virtual Hosts
- Step 6: Secure Apache with SSL
- Step 7: Test SSL Configuration
- Frequently Asked Questions (FAQs)
- Conclusion
1. Introduction
Apache is one of the most popular open-source web servers globally. It is known for its flexibility, stability, and security. CentOS is a Linux distribution that is powerful, reliable, and well-suited for running enterprise-level applications. In this article, we will explain how to install and configure Apache web server on CentOS.
2. Prerequisites
Before proceeding with the installation, you should ensure that the following prerequisites are met:
- A CentOS 7 or 8 server
- Root access or a user account with sudo privileges
- A stable internet connection
- A domain name or IP address for your server
- Basic knowledge of Linux commands
3. Step 1: Update CentOS
The first step is to update the CentOS server to the latest version available using the following command:
$ sudo yum update -y
This command will upgrade all installed packages on your server, including the kernel. If prompted, enter the root or sudo user password to proceed.
4. Step 2: Install Apache Web Server
Once the system is up-to-date, it’s time to install the Apache web server using the following command:
$ sudo yum install httpd -y
The above command will install the latest version of Apache and its dependencies on your CentOS server. You can verify the installation by checking the Apache version using the following command:
$ httpd -v
If the installation is successful, the Apache version will be displayed on the screen.
5. Step 3: Configure Apache
After installing Apache, you need to configure it properly using the following steps:
5.1 Start Apache
To start the Apache web server, run the following command:
$ sudo systemctl start httpd
5.2 Enable Apache
To enable the Apache web server to start automatically at system boot time, run the following command:
$ sudo systemctl enable httpd
5.3 Check Apache Status
To check the status of the Apache web server, run the following command:
$ sudo systemctl status httpd
If the output shows “Active (running),” then Apache is working correctly.
6. Step 4: Verify Apache
After configuring Apache, you can verify its functionality by accessing the Apache default page using a web browser. Open the browser and type http://your_server_IP_address/ or http://your_domain_name/ in the address bar. It should display the Apache default page.
7. Step 5: Create Virtual Hosts
If you want to host multiple websites on your Apache web server, you can create virtual hosts. To create a virtual host on Apache, follow the below steps:
7.1 Create a Directory for Your Website
Create a new directory for your website under the Apache document root directory using the following command:
$ sudo mkdir -p /var/www/example.com/public_html
7.2 Set Permissions for Your Website Directory
Set the appropriate permissions for your website directory using the following command:
$ sudo chmod -R 755 /var/www/example.com/public_html
7.3 Create a Virtual Host File
Create a virtual host file for your website using the following command:
$ sudo nano /etc/httpd/conf.d/example.com.conf
Add the following code to the file:
“`
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog /var/www/example.com/error.log
CustomLog /var/www/example.com/access.log combined
“`
Save and exit the file.
7.4 Reload Apache Configuration
Reload the Apache configuration using the following command:
$ sudo systemctl reload httpd
7.5 Test Your Website
Open a web browser and type your domain name or IP address to test your website.
8. Step 6: Secure Apache with SSL
If your website deals with sensitive information, it’s essential to secure it with an SSL certificate. To secure Apache with SSL, you need to follow the below steps:
8.1 Install the SSL Module for Apache
To enable SSL encryption on your Apache server, you need to install the SSL module using the following command:
$ sudo yum install mod_ssl
8.2 Generate SSL Certificate
Generate an SSL certificate for your website using the following command:
$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/pki/tls/private/example.com.key -out /etc/pki/tls/certs/example.com.crt
Replace example.com with your domain name.
8.3 Configure SSL on Apache
Configure SSL on Apache by editing the SSL configuration file using the following command:
$ sudo nano /etc/httpd/conf.d/ssl.conf
Uncomment the following lines:
“`
SSLCertificateFile /etc/pki/tls/certs/example.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/example.com.key
“`
Save and exit the file.
9. Step 7: Test SSL Configuration
Restart Apache using the following command to apply the changes:
$ sudo systemctl restart httpd
Open a web browser and type https://your_domain_name/ or https://your_server_IP_address/ in the address bar. It should display a lock icon, indicating that your website is secured with SSL.
10. Frequently Asked Questions (FAQs)
10.1 What is Apache Web Server?
The Apache HTTP Server, commonly referred to as Apache, is an open-source web server software developed and maintained by the Apache Software Foundation. It is used to serve web pages and other content over the internet.
10.2 What is CentOS?
CentOS is a Linux distribution that is enterprise-level and is based on the Red Hat Enterprise Linux. It offers a free, open-source, and stable operating system for hosting servers.
10.3 How can I check the Apache version?
You can check the Apache version by running the following command:
$ httpd -v
10.4 How can I start, stop or restart Apache?
You can start, stop or restart Apache using the following command:
$ sudo systemctl start httpd
$ sudo systemctl stop httpd
$ sudo systemctl restart httpd
10.5 How can I test my Apache web server?
You can test your Apache web server by accessing the Apache default page using a web browser. Open the browser and type http://your_server_IP_address/ or http://your_domain_name/ in the address bar.
11. Conclusion
In conclusion, installing Apache web server on CentOS is a straightforward process. By following the steps outlined in this article, you should now have a fully functional Apache web server running on your CentOS machine. Remember to keep your Apache web server secure by configuring SSL encryption and creating virtual hosts. If you have any questions or encounter any issues, feel free to refer to our FAQs section or leave a comment below. Happy web serving!