service httpd restart / (98)Address already in use

Out of the blue, I can't restart apache on my CentOS 6.8 web server:

# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: (98)Address already in use: make_sock: could not bind to address [::]:7080
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:7080
no listening sockets available, shutting down
Unable to open logs
                                                           [FAILED]

I tried a bunch of things I read online, including removing lock files.

I decided to try rebooting the server. After reboot, attempting to load any hosted websites would result in "502 Bad Gateway".

# service httpd status
httpd is stopped

# service httpd start
Starting httpd:                                            [  OK  ]

# service httpd status
httpd dead but subsys locked

Despite the "dead" status, I can now load websites!

Sometimes service httpd restart works...

# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

But other times it results in the first error above. In which case I can fix it with:

# killall -9 httpd
# service httpd start

So I can work around it, but I'm really curious about what is going on and wondering if I should be concerned.


Solution 1:

You may have defined your listener on that port twice in your configs somewhere.

Listen *:7080

If you run an Apache config test, it will say the config is OK, until you actually restart the service, it will fail with a similar error to what you are seeing.

Also verify your logging location exists and is writable and has space to write, that message at the end is suspect.

Solution 2:

SSH to the server and the run the following:

setenforce 0

This will disable selinux until next reboot

Then try to reload Apache

service httpd restart

If this works somehow selinux got turned on.

To disable permanently follow this link:

https://kb.plesk.com/en/115626