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

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.

This question is related to linux apache centos

The answer is


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.


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).


In the Apache httpd.conf file:

ServerName: 127.0.0.1

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

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.


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


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.


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


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.


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.


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.


Examples related to linux

grep's at sign caught as whitespace How to prevent Google Colab from disconnecting? "E: Unable to locate package python-pip" on Ubuntu 18.04 How to upgrade Python version to 3.7? Install Qt on Ubuntu Get first line of a shell command's output Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running? Run bash command on jenkins pipeline How to uninstall an older PHP version from centOS7 How to update-alternatives to Python 3 without breaking apt?

Examples related to apache

Enable PHP Apache2 Switch php versions on commandline ubuntu 16.04 Laravel: PDOException: could not find driver How to deploy a React App on Apache web server Apache POI error loading XSSFWorkbook class How to enable directory listing in apache web server Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details How to enable php7 module in apache? java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing while starting Apache server on my computer

Examples related to centos

How to uninstall an older PHP version from centOS7 Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details pip install - locale.Error: unsupported locale setting ssh : Permission denied (publickey,gssapi-with-mic) How to change the MySQL root account password on CentOS7? Completely remove MariaDB or MySQL from CentOS 7 or RHEL 7 ffprobe or avprobe not found. Please install one How to check all versions of python installed on osx and centos Cannot find java. Please use the --jdkhome switch VirtualBox: mount.vboxsf: mounting failed with the error: No such device