The Apache HTTP Server, commonly referred to as Apache, is one of the most widely used web servers. By default, Apache listens on port 80 for HTTP and port 443 for HTTPS. However, there may be situations where you need to change these default ports, such as avoiding conflicts with other services or implementing specific network configurations.
Changing the listen port for Apache is a straightforward process but requires administrative access to the server. It involves modifying the Apache configuration files and restarting the service to apply the changes.
Whether you are running Apache on a Linux, macOS, or Windows system, the steps to change the listen port are similar. Below, you'll find a guide tailored to a typical Linux-based Apache installation.
$ sudo grep -nr "^Listen" /etc/{httpd,apache2}/ [sudo] password for user: grep: /etc/httpd/: No such file or directory /etc/apache2/ports.conf:5:Listen 80
Related: Location for Apache configuration
$ sudo vi /etc/apache2/ports.conf
Listen 80
Listen 8080
Make sure no other services are using the port you have chosen. You can use the netstat command to check for conflicts.
<VirtualHost *:8080> ##### snipped </VirtualHost>
$ sudo iptables -A INPUT -p tcp --dport 8080 -j ACCEPT $ sudo ufw allow 8080/tcp
$ sudo semanage port -a -t http_port_t -p tcp 8080
$ sudo systemctl restart apache2 # Ubuntu, Debian, openSUSE and SLES $ sudo systemctl restart httpd # CentOS and Red Hat
$ curl -I 127.0.0.1:8080 HTTP/1.1 200 OK Date: Fri, 01 Sep 2023 11:58:10 GMT Server: Apache/2.4.55 (Ubuntu) Last-Modified: Thu, 31 Aug 2023 09:37:27 GMT ETag: "29af-60434cacb2109" Accept-Ranges: bytes Content-Length: 10671 Vary: Accept-Encoding Content-Type: text/html
Comment anonymously. Login not required.