Reputation: 1895
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.
Upvotes: 189
Views: 539568
Reputation: 33
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.
Upvotes: 2
Reputation: 5880
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.
Upvotes: 2
Reputation: 166899
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
Upvotes: 17
Reputation: 7734
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
).
Upvotes: 2
Reputation: 8187
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
Upvotes: 67
Reputation: 713
There are two ways to resolve this error:
Include /etc/apache2/httpd.conf
Add the above line in file /etc/apache2/apache2.conf
Add this line at the end of the file /etc/apache2/apache2.conf:
ServerName localhost
Upvotes: 3
Reputation: 119
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:
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
Edit httpd.conf
$ sudo nano -w /etc/apache2/httpd.conf
ServerName myserver.myhome.com
Edit network
$ sudo nano -w /etc/sysconfig/network HOSTNAME=myserver.myhome.com
Verify
$ hostname
(output) myserver.myhome.com
$ hostname -f
(output) myserver.myhome.com
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.
Upvotes: 11
Reputation: 2849
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.
Upvotes: 218
Reputation: 9854
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.
Upvotes: 2
Reputation: 1149
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
Upvotes: 99
Reputation: 13529
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.
Upvotes: 9