I am very new in using Linux. I am using Centos 7 of vmware. I wanted to start the httpd but i am facing some problems. Please help.

March 26, 2017 909 views
Apache Linux Basics CentOS

[root@tbcl conf]# systemctl status -l httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2017-03-27 21:28:14 BDT; 1min 3s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 5590 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
Process: 5589 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
Main PID: 5589 (code=exited, status=1/FAILURE)

Mar 27 21:28:14 tbcl httpd[5589]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.176.129. Set the 'ServerName' directive globally to suppress this message
Mar 27 21:28:14 tbcl httpd[5589]: (98)Address already in use: AH00072: make_sock: could not bind to address 192.168.176.129:80
Mar 27 21:28:14 tbcl httpd[5589]: no listening sockets available, shutting down
Mar 27 21:28:14 tbcl httpd[5589]: AH00015: Unable to open logs
Mar 27 21:28:14 tbcl systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Mar 27 21:28:14 tbcl kill[5590]: kill: cannot find process ""
Mar 27 21:28:14 tbcl systemd[1]: httpd.service: control process exited, code=exited status=1
Mar 27 21:28:14 tbcl systemd[1]: Failed to start The Apache HTTP Server.
Mar 27 21:28:14 tbcl systemd[1]: Unit httpd.service entered failed state.
Mar 27 21:28:14 tbcl systemd[1]: httpd.service failed.

[root@tbcl conf]# systemctl start httpd
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

3 Answers

@zahedjoy009

The issue is this line:

Mar 27 21:28:14 tbcl httpd[5589]: no listening sockets available, shutting down

Something else is listening on port 80/443, thus Apache fails to start as you can't have two services listening on the same port at the same time.

You'll want to run:

netstat -ltnp | grep ':80'

... to see what else is listening on that port and kill the process, otherwise Apache will continue to fail to start.

Once you find the process, you can either shutdown the service, or use kill -9 to kill off the process using the id.

i.e.

kill -9 id

Where id is the process ID. Once the process is killed off, you can then start or restart Apache and it should work.

...

As a general note, please keep in mind this community designed for DigitalOcean customers as well as potential future customers, so while we can help with general linux issues like this one, there may be some issues we can't help with since DigitalOcean does not use VMWare.

  • when i ran "netstat -ltnp | grep ':80'" this command, its getting nothing in reply, is it mean there is nothing running on port 80? and if there is nothing running on port 80 then what is the issue?

    • @zahedjoy009

      Looking at the error logs, this message (in addition to the previous):

      Mar 27 21:28:14 tbcl httpd[5589]: (98)Address already in use: AH00072: make_sock: could not bind to address 192.168.176.129:80
      

      ...says that there is something listening on that port, otherwise it wouldn't fail to start.

      Try running:

      netstat -anp|grep :80
      

      What else is running on the server?

      The only other issue would be is if you've setup multiple VirtualHost blocks and use 192.168.176.129:80 for them all.

      i.e.

      <VirtualHost 192.168.176.129:80>
      ...
      ...
      ..
      </VirtualHost>
      <VirtualHost 192.168.176.129:80>
      ...
      ...
      ..
      </VirtualHost>
      <VirtualHost 192.168.176.129:80>
      ...
      ...
      ..
      </VirtualHost>
      

      In such a case, you need to replace:

      192.168.176.129:80
      

      with

      *:80
      

      The reason for this change is because you can't bind multiple VirtualHosts to the same IP directly.

      • i have changed the settings but still showing error in "systemctl status httpd.service"

        NameVirtualHost *:80
        
        <virtualHost *:80>
            ServerAdmin webmaster@example.com
            ServerName example.com
            ServerAlias www.example.com
            DocumentRoot /var/www/html/example.com/public_html/
            ErrorLog /var/www/html/example.com/logs/error.log
            CustomLog /var/www/html/example.com/logs/access.log combined
        </VirtualHost>
        
        
      • i have changed the settings and replaced with *:80 and now it says "AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.176...s message"

        • @zahedjoy009

          That's more of a warning than anything else. As long as Apache is starting, then it's not really an issue. You can get rid of that message by running:

          echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/servername.conf
          

          Followed by:

          a2enconf servername
          

          And then restart Apache. Since this generally isn't available on CentOS (the a2enconf command, as it's debian specific), you'd have to use a symlink which would link:

          /etc/apache2/conf-available/servername.conf
          

          to

          /etc/apache2/conf-enabled/servername.conf
          

          Since that's how default installations of Apache are setup. Normally I simply modify the main configuration file to use the core directories instead of using multiple symlinks.

          • I am using centos 7. I think this commands are for any other version of linux. can you pls translate it for centos 7?

@zahedjoy009

ln -s /etc/apache2/conf-available/servername.conf /etc/apache2/conf-enabled/servername.conf
  • but there is no directory /etc/apache2

    where to find this directory? additionally i am using centos 7 by the way

    • @zahedjoy009

      In CentOS, I believe /etc/apache would be /etc/httpd last I recall. Going based on memory as I generally only work with Ubuntu/Debian.

@zahedjoy009

What's the output of systemctl status httpd.service showing as of right now?

Quick note:

<virtualHost *:80>

should be:

<VirtualHost *:80>

Capital V.

Have another answer? Share your knowledge.