Change Apache Port on Fedora

2 Comments

Sometimes we want Apache to listen on a port other than the default 80. To achieve this on a Fedora box, one needs to modify its configuration file /etc/httpd/conf/httpd.conf. Change the port number on the line 'Listen 80' to the number you like. If virtual hosts are used, change the related port number as well, eg. NameVirtualHost *:8000. However, when you restart Apache after configuration changes, you may encounter errors like the following, even if you are root:

Starting httpd: (13)Permission denied: make_sock: could not bind to address [::]:8000
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:8000
no listening sockets available, shutting down
Unable to open logs
[FAILED]

This is due to the SELinux policy which prevents Apache from binding to the port you've selected. You can use this shell command to check whether SELinux is in enforcing mode or permissive mode:
cat /selinux/enforce
Output 1 indicates it's in enforcing mode and 0 permissive mode.

To resolve this, you can do either of the following:
1) Switch SELinux to permissive mode