Linux – service httpd restart failure on aws amazon linux ami

amazon-web-servicesapache-2.2linux

Thanks for your help. I recently did the following:

  1. Ran sudo yum update on my ec2 instance running the Amazon Linux ami
  2. I then added a virtual host to my vhost.conf for a subdomain.
  3. While the server is still accessible, When I ran sudo httpd restart I received the following:

.

Stopping httpd:                                            [FAILED]
Starting httpd: AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/httpd/conf.d/vhost.conf:1
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
                                                           [FAILED]

Also, if I run the restart command without sudo service httpd restart I receive the following message:

rm: cannot remove `/var/run/httpd/httpd.pid': Permission deniedLED]

rm: cannot remove `/var/run/httpd/httpd.pid': Permission denied
Starting httpd: AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/httpd/conf.d/vhost.conf:1
(13)Permission denied: AH00058: Error retrieving pid file /var/run/httpd/httpd.pid
AH00059: Remove it before continuing if it is corrupted.
                                                           [FAILED]

Best Answer

From what you have provided seems that there is another process using port 80

Try to do the following:

First you need to be a root user to execute them, either you add sudo before the command, or before doing anything, switch to the user root like this:

su -root

and type the root password.

Then, proceed with:

netstat -tulpn| grep :80

The above command displays list of connections that are using port 80

Then execute the following command to kill the process that is using port 80

kill -9 <process id>

Replace process id with the process number that is shown on the screen from the previous command.

Then execute this command to start httpd process:

service httpd start
If the above did not work with you then try this

Try this i have just tested it:

for i in `lsof -i :80 | grep http | awk {' print $2'}`; do kill -9 $i; done

Then perform the restart:

service httpd restart