Install Apache on CentOS 7: Complete Setup Guide
Install the Apache server:
- Open the terminal and use the following command to install the Apache server:
sudo yum install httpd
- After installation is complete, start the Apache server and set it to start automatically on boot.
sudo systemctl start httpd
sudo systemctl enable httpd
Set up an Apache server.
- The configuration file for the Apache web server.
sudo vi /etc/httpd/conf/httpd.conf
- You can configure some basic settings of the Apache server in the httpd.conf file, such as port number and virtual hosts. Modify the configuration file as needed.
- Once you have saved and exited the httpd.conf file, reload the Apache server configuration.
sudo systemctl reload httpd
- Configure the website’s root directory:
By default, the website root directory for an Apache server is /var/www/html/, where website files can be placed. If you want to change the website root directory, you can modify the DocumentRoot option in the httpd.conf file.
- Set up firewall:
If the firewall is enabled on the system, it is necessary to configure the firewall to allow HTTP traffic access. Use the following command to enable the HTTP service:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
- Test the Apache server.
Open a browser and type http://localhost or the server IP address in the address bar. If you can see the default Apache page, it means that the Apache server has been installed and configured successfully.