Site icon CentLinux

How to Change Apache Port in Linux

Share on Social Media

Discover how to change Apache port in Linux easily. Follow our simple guide to modify the default port and enhance your server’s security and configuration. #centlinux #linux #apache

Why Should you Change Apache Port?

Here are some reasons why you might want to change the Apache port:

  1. Avoiding Conflicts: If another service is already using the default port 80, changing the Apache port can prevent conflicts and ensure that both services run smoothly.
  2. Enhanced Security: Changing the default port makes it slightly more difficult for attackers to target your web server since port 80 is commonly targeted by bots and attackers.
  3. Multiple Web Servers: Running multiple instances of Apache or different web servers on the same machine requires using different ports for each server to operate without interference.
  4. Custom Network Configuration: Some network setups or hosting environments might require non-standard ports to accommodate specific rules or firewall settings.
  5. Testing and Development: Developers often change the Apache port to test applications on different environments or to run multiple projects simultaneously on the same machine.

Change Apache Port in Linux

Below is the code with added descriptions and instructions for each piece of code to change Apache port in Linux server:

How to Change Apache Port in Linux

1. Check Operating System and Kernel Version

cat /etc/os-release
uname -r

2. Update System Packages

dnf update -y

Recommended Training: Apache Web Server from Vipin Gupta

3. Install Apache Server

dnf install -y httpd

4. Enable and Start Apache Server

systemctl enable --now httpd

5. Allow HTTP Traffic Through Firewall

firewall-cmd --permanent --add-service=http
firewall-cmd --reload

6. Create a Test Web Page

vi /var/www/html/index.html
<html><head><title>My Test Page</title></head>
<body>
<h2>My Test Page</h2>
</body>
</html>

Read Also: Change Apache Document Root in Linux

7. Test Apache Server

curl http://localhost/

8. Edit Apache Configuration to Change Port

vi /etc/httpd/conf/httpd.conf

9. Allow New Port Through Firewall

firewall-cmd --permanent --add-port=8800/tcp
firewall-cmd --reload

10. Install SELinux Management Utilities

dnf install -y policycoreutils-python-utils

11. Configure SELinux to Allow Apache on New Port

semanage port -l | grep http_port
semanage port -a -t http_port_t -p tcp 8800

12. Restart Apache Service

systemctl restart httpd

13. Test Apache on the New Port

curl http://localhost/
curl http://localhost:8800

Complete Video Guide to Change Apache Port in Linux

Conclusion

These instructions cover the steps to change the Apache web server’s listening port on a Linux system using the dnf package manager, commonly used on RHEL-based distributions like CentOS, Fedora, or Red Hat Enterprise Linux. Make sure to replace 8800 with any other port number if you prefer a different port.

Looking for a Linux server expert? I provide top-tier administration, performance tuning, and security solutions for your Linux systems. Explore my Fiverr profile for details!

Exit mobile version