Introduction
Apache HTTP server is the leading web server software globally, renowned for its reliability and configurability, making it perfect for managing extensive projects and offering extensive customization options to implement all features of the hosted web resource.
This guide will walk you through the steps to install Apache on RedHat-based distributions (CentOS, AlmaLinux).
Step for AlmaLinux 8 Only: Import GPG Key Repository
This step is necessary only for AlmaLinux 8. Skip this if you are using CentOS 7 or AlmaLinux 9.
To install the updated GPG keys on AlmaLinux 8, execute:
rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux
1. Installing Apache
- First, ensure your system's software is updated with:
yum update
- After updating, install Apache by running:
yum install httpd
2. Starting Apache
- Start the Apache service using:
systemctl start httpd
3. Checking Apache Status
- To verify Apache's status, use the command:
systemctl status httpd
- The output will provide Apache and some additional information:
- You can also check if Apache is running by entering your server's public IP address into your web browser:
http://your_server_IP_address
If Apache is working correctly, you will see the default Apache web page, which varies between CentOS and AlmaLinux:
CentOS: Default Apache Page
AlmaLinux: Default Apache Page
4. Additional Configurations
- To prevent Apache from starting automatically at boot, run:
systemctl disable httpd
- To re-enable Apache to start automatically at boot, use:
systemctl enable httpd
systemctl stop httpd
systemctl restart httpd
- To reload Apache without dropping connections, run:
systemctl reload httpd
5. Virtual Host (Optional)
A VirtualHost directive in Apache's configuration file is used to configure IP addresses, domains, and directories on the server, allowing management of multiple sites on a single server.
Create a virtual host configuration file with:
vi /etc/httpd/conf.d/yourdomain.ltd.conf
- Add the following lines to the configuration file:
systemctl restart httpd
For establishing a secure connection, refer to a guide on Let's Encrypt for further instructions.