Step-by-Step Guide
- Update the Package Index
Open a terminal and update the package index to ensure you have the latest information about available packages:
sudo yum update -y- Install Apache
Install Apache using theyumpackage manager:
sudo yum install httpd -y- Start and Enable Apache
Start the Apache service:
sudo systemctl start httpdEnable Apache to start on boot:
sudo systemctl enable httpd- Adjust the Firewall
Ensure that your firewall allows HTTP and HTTPS traffic. You can check the current firewall status and add the necessary rules:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload- Verify Apache Installation
After the installation is complete, Apache should start automatically. You can verify this by checking the service status:
sudo systemctl status httpdIf Apache is running, you should see an active (running) status.
- Test Apache
Open your web browser and visit your server’s IP address (http://your_server_ip/). You should see the Apache Test Page, indicating that the web server is running correctly. - Configure Apache (Optional)
The main configuration file for Apache is located at/etc/httpd/conf/httpd.conf. You can edit this file to customize your Apache configuration:
sudo nano /etc/httpd/conf/httpd.confAfter making changes, restart Apache to apply them:
sudo systemctl restart httpd- Enable/Disable Modules
Apache uses modules to extend its functionality. You can enable or disable modules by editing the configuration files in the/etc/httpd/conf.modules.d/directory. After enabling or disabling modules, reload Apache to apply changes:
sudo systemctl reload httpd- Set Up Virtual Hosts (Optional)
Virtual hosts allow you to run multiple websites on a single server. To set up a virtual host, create a new configuration file in the/etc/httpd/conf.d/directory:
sudo nano /etc/httpd/conf.d/your_domain.confAdd the following basic configuration to the file:
<VirtualHost *:80>
ServerAdmin webmaster@your_domain
ServerName your_domain
ServerAlias www.your_domain
DocumentRoot /var/www/your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>Save and close the file, then restart Apache to apply the changes:
sudo systemctl restart httpd

