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
Table of Contents
Why Should you Change Apache Port?
Here are some reasons why you might want to change the Apache port:
- 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.
- 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.
- 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.
- Custom Network Configuration: Some network setups or hosting environments might require non-standard ports to accommodate specific rules or firewall settings.
- 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:

1. Check Operating System and Kernel Version
cat /etc/os-release
uname -r
- Description: This command checks the operating system’s release information and the current kernel version.
- Purpose: To verify the Linux distribution and kernel version before proceeding with the installation, ensuring compatibility.
2. Update System Packages
dnf update -y
- Description: Updates all the installed packages to their latest versions.
- Purpose: Ensures that the system is up to date and that there are no security vulnerabilities.
Recommended Training: Apache Web Server from Vipin Gupta

3. Install Apache Server
dnf install -y httpd
- Description: Installs the Apache server package.
- Purpose: To set up the Apache server, which is required for hosting web pages.
4. Enable and Start Apache Server
systemctl enable --now httpd
- Description: Enables Apache server to start at boot and immediately starts the Apache service.
- Purpose: To ensure Apache server is running and will automatically start on system reboot.
Shell Scripting: How to Automate Command Line Tasks Using Bash Scripting and Shell Programming
$2.99 (as of February 5, 2025 14:54 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)5. Allow HTTP Traffic Through Firewall
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
- Description: Adds a permanent rule to the firewall to allow HTTP traffic, then reloads the firewall to apply the changes.
- Purpose: To allow web traffic to reach the Apache server.
6. Create a Test Web Page
vi /var/www/html/index.html
- Description: Opens the default web page directory in the
vi
text editor to create or edit a test HTML file. - Purpose: To create a simple web page for testing the Apache server.
<html><head><title>My Test Page</title></head>
<body>
<h2>My Test Page</h2>
</body>
</html>
- Description: The HTML content to be placed in
index.html
. - Purpose: This basic HTML file will be served by Apache, allowing you to verify the server is working correctly.
Read Also: Change Apache Document Root in Linux
7. Test Apache Server
curl http://localhost/
- Description: Uses
curl
to fetch the default page from the Apache server. - Purpose: To verify that Apache is serving the test web page correctly.
8. Edit Apache Configuration to Change Port
vi /etc/httpd/conf/httpd.conf
- Description: Opens the main Apache configuration file in the
vi
text editor. - Purpose: To change the port number Apache listens on (from default port 80 to a new port, e.g., 8800).
- Instruction: Locate the line starting with
Listen 80
and change it toListen 8800
to set Apache to listen on port 8800.
iBUYPOWER Y60 Black Gaming PC Computer Desktop Y60BA9N47TS03 (AMD Ryzen 9 7900X CPU, NVIDIA GeForce RTX 4070 Ti Super 16GB GPU, 32GB DDR5 RGB 5200MHz RAM, 2TB NVMe, WiFi Ready, Windows 11 Home)
$1,899.99 (as of February 5, 2025 14:54 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)9. Allow New Port Through Firewall
firewall-cmd --permanent --add-port=8800/tcp
firewall-cmd --reload
- Description: Adds a permanent rule to the firewall to allow traffic on TCP port 8800, then reloads the firewall to apply changes.
- Purpose: To permit HTTP traffic on the new port.
10. Install SELinux Management Utilities
dnf install -y policycoreutils-python-utils
- Description: Installs the SELinux policy management utilities.
- Purpose: Required to configure SELinux for the new port.
11. Configure SELinux to Allow Apache on New Port
semanage port -l | grep http_port
- Description: Lists all the currently allowed HTTP ports in SELinux configuration.
- Purpose: To check which ports are currently allowed for HTTP traffic.
semanage port -a -t http_port_t -p tcp 8800
- Description: Adds TCP port 8800 to the SELinux configuration for HTTP traffic.
- Purpose: To allow Apache to use the new port while SELinux is enabled.
Beech-Nut Baby Food Pouches Variety Pack, Veggie Purees, 3.5 oz (18 Pack)
$24.99 (as of February 5, 2025 14:49 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)12. Restart Apache Service
systemctl restart httpd
- Description: Restarts the Apache service to apply the changes made in the configuration.
- Purpose: Necessary to make Apache listen on the new port.
13. Test Apache on the New Port
curl http://localhost/
curl http://localhost:8800
- Description: Uses
curl
to test the Apache server on both the default port (80) and the new port (8800). - Purpose: To verify that Apache is correctly serving content on the newly configured port.
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!
Leave a Reply
You must be logged in to post a comment.