This article explains how to change the Apache port in CentOS. Changing the Apache port in CentOS is often necessary to resolve port conflicts, improve security, or accommodate specific application requirements.
Follow these steps:
- Edit the Apache Configuration File:
- Open the Apache configuration file using a text editor like vi or nano.
sudo vi /etc/httpd/conf/httpd.conf
- Open the Apache configuration file using a text editor like vi or nano.
- Find and Change the Listen Directive:
- Look for the Listen directive in the file. It usually looks like this:
Listen 80
- Change it to the desired port number. For example, to change it to port 8080:
Listen 8080
- Look for the Listen directive in the file. It usually looks like this:
- Update Virtual Hosts (if necessary):
- If you have virtual hosts configured, you also need to update their port numbers. Locate the virtual host configurations, which may look like this:
<VirtualHost *:80> ... </VirtualHost>
- Change the port number to match the new port:
<VirtualHost *:8080> ... </VirtualHost>
- If you have virtual hosts configured, you also need to update their port numbers. Locate the virtual host configurations, which may look like this:
- Restart Apache:
- After making the changes, restart Apache to apply the new configuration.
sudo systemctl restart httpd
- After making the changes, restart Apache to apply the new configuration.
- Update Firewall Rules (if necessary):
- If you are using a firewall, you need to update the firewall rules to allow traffic on the new port. For example, to allow port 8080 through the firewall:
sudo firewall-cmd --permanent --add-port=8080/tcp sudo firewall-cmd --reload
- If you are using a firewall, you need to update the firewall rules to allow traffic on the new port. For example, to allow port 8080 through the firewall:
- Verify the Changes:
- Ensure that Apache is listening on the new port by using the netstat or ss command:
sudo netstat -tuln | grep 8080
or
sudo ss -tuln | grep 8080
- Ensure that Apache is listening on the new port by using the netstat or ss command:
By following these steps, you should be able to change the Apache ports on CentOS successfully.
Explore our in-depth guide on How to Modify the Apache port in WHM