httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

LinuxApacheCentos

Linux Problem Overview


I tried to restart my Apache server on CentOS 5.0 and got this message:

> httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

Here is the /etc/hosts file:

127.0.0.1    server4-245    server4-245.com    localhost.localdomain localhost
::1        localhost6.localdomain6 localhost6

Here is the /etc/sysconfig/network file:

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=server4-245

I also have this in the Apache httpd.conf file:

ServerName localhost

However, I still get the first error message when I restart Apache.

Linux Solutions


Solution 1 - Linux

If you don't have httpd.conf in folder /etc/apache2, you should have apache2.conf - simply add:

> ServerName localhost

Then restart the apache2 service.

Solution 2 - Linux

Your hosts file does not include a valid FQDN, nor is localhost an FQDN. An FQDN must include a hostname part, as well as a domain name part. For example, the following is a valid FQDN:

host.server4-245.com

Choose an FQDN and include it both in your /etc/hosts file on both the IPv4 and IPv6 addresses you are using (in your case, localhost or 127.0.0.1), and change your ServerName in your httpd configuration to match.

/etc/hosts:

127.0.0.1    localhost.localdomain localhost host.server4-245.com
::1          localhost.localdomain localhost host.server4-245.com

httpd.conf:

ServerName host.server4-245.com

Solution 3 - Linux

After the initial install of Apache server, I got the following error while restarting the Apache service on Ubuntu 12.04 (Precise Pangolin)

The solution is really simple. Just add the ServerName directive to /etc/apache2/httpd.conf:

sudo nano /etc/apache2/httpd.conf

Add: ServerName localhost

Finally restart the Apache server:

sudo /etc/init.d/apache2 restart

Solution 4 - Linux

Make sure you're editing the right httpd.conf file, then the error about unreliable server's domain name should be gone (this is the most common mistake).

To locate your httpd.conf Apache configuration file, run:

apachectl -t -D DUMP_INCLUDES

Then edit the file and uncomment or change ServerName line into:

ServerName localhost

Then restart your apache by: sudo apachectl restart

Solution 5 - Linux

So while this is answered and accepted it still came up as a top search result and the answers though laid out (after lots of research) left me scratching my head and digging a lot further. So here's a quick layout of how I resolved the issue.

Assuming my server is myserver.myhome.com and my static IP address is 192.168.1.150:

  1. Edit the hosts file

     $ sudo nano -w /etc/hosts
    
     127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
    
     127.0.0.1 myserver.myhome.com myserver
    
     192.168.1.150 myserver.myhome.com myserver
    
     ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
     ::1 myserver.myhome.com myserver
    
  2. Edit httpd.conf

     $ sudo nano -w /etc/apache2/httpd.conf
    
     ServerName myserver.myhome.com
    
  3. Edit network

     $ sudo nano -w /etc/sysconfig/network HOSTNAME=myserver.myhome.com
    
  4. Verify

     $ hostname
    
     (output) myserver.myhome.com
    
     $ hostname -f
    
     (output) myserver.myhome.com
    
  5. Restart Apache

     $ sudo /etc/init.d/apache2 restart
    

It appeared the difference was including myserver.myhome.com to both the 127.0.0.1 as well as the static IP address 192.168.1.150 in the hosts file. The same on Ubuntu Server and CentOS.

Solution 6 - Linux

In httpd.conf, search for "ServerName". It's usually commented out by default on Mac. Just uncomment it and fill it in. Make sure you also have the name/ip combo set in /etc/hosts.

Solution 7 - Linux

In the Apache httpd.conf file:

ServerName: 127.0.0.1

Solution 8 - Linux

There are two ways to resolve this error:

  1. Include /etc/apache2/httpd.conf

    Add the above line in file /etc/apache2/apache2.conf

  2. Add this line at the end of the file /etc/apache2/apache2.conf:

    ServerName localhost

Solution 9 - Linux

I've resolved the fully qualified domain name message on different occasions by adding my server hostname to the /etc/apache2/httpd.conf file and to the /etc/apache2/apache2.conf file.

Type hostname -f in your terminal. This query will return your hostname.

Then edit the /etc/apache2/httpd.conf file (or create it if it does not exist for some reason) and add ServerName <your_hostname>.

Alternatively, I have also been able to eliminate the message by adding ServerName <your_hostname> to the /etc/apache2/apache2.conf file.

If all goes well, when you restart Apache, the message will be gone.

Solution 10 - Linux

Most answers suggest to just add ServerName localhost to /etc/apache2/apache2.conf.

But quoting Apache documentation :

> The presence of this error message also indicates that Apache httpd was unable to obtain a fully-qualified hostname by doing a reverse lookup on your server's IP address. While the above instructions will get rid of the warning in any case, it is also a good idea to fix your name resolution so that this reverse mapping works.

Therefore adding such a line to /etc/hosts is probably a more robust solution :

192.0.2.0  foobar.example.com  foobar

where 192.0.2.0 is the static IP address of the server named foobar within the example.com domain.

One can check the FQDN e.g. with

hostname -A

(shortcut for hostname --all-fqdn).

Solution 11 - Linux

Turns out that I had this problem and it was because I used "tabs" to indent lines instead of spaces. Just posting, in case it helps anyone.

Solution 12 - Linux

If you've edited /etc/apache2/httpd.conf with the ServerName localhost you may be editing the wrong file. All answers I found were pointing towards that standard httpd.conf. After some foraging, I found a good answer here.

To locate the right httpd.conf file use

apachectl -t -D DUMP_INCLUDES

I found mine was actually /usr/local/etc/httpd/httpd.conf.

Use your preferred editor to comment out the line (i.e. remove the # before) starting with ServerName, and replace the domain name for the appropriate one – local environments should work with

ServerName localhost

I hope this helps more people who may be stuck.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1220351View Question on Stackoverflow
Solution 1 - LinuxriegersnView Answer on Stackoverflow
Solution 2 - LinuxPaul StengelView Answer on Stackoverflow
Solution 3 - LinuxrizonView Answer on Stackoverflow
Solution 4 - LinuxkenorbView Answer on Stackoverflow
Solution 5 - Linuxuser2416772View Answer on Stackoverflow
Solution 6 - LinuxsparkyspiderView Answer on Stackoverflow
Solution 7 - Linuxuser1992487View Answer on Stackoverflow
Solution 8 - LinuxJimit ShahView Answer on Stackoverflow
Solution 9 - LinuxJohn CreamerView Answer on Stackoverflow
Solution 10 - LinuxSkippy le Grand GourouView Answer on Stackoverflow
Solution 11 - LinuxRichard KerseyView Answer on Stackoverflow
Solution 12 - LinuxFilipe FonsecaView Answer on Stackoverflow