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

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.

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.

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

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

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

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.

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.

In the Apache httpd.conf file:
ServerName: 127.0.0.1

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

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.

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

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.

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.

Related

How to build a simple website into a embedded Linux using Apache and Yocto?

I like to build a demo of a website running on an eval board from ATMEL. For this eval board I am building an Linux by the use of Yocto. For handling the website the apache webserver should be used.
I got the apache2 recipe build and installed, as well as my simple website. But I failed to set up the apache configuration right.
My system has two ethernet ports eth0 and eth1. Eth0 is configured to the IP 1.2.3.4 and eth1 to dchp. The index.html should be accessed through eth0. Maybe it is possible to have an literal like "mywebsite" to access it.
The website files are put in to the custom dir: /var/www/html/
Actual I am copying an virtual host config(myweb.conf) to /etc/apache2/sites-available/. It looks like:
# Ensure that Apache listens on port 80
Listen 80
<VirtualHost *:80>
ServerName mywebsite
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
</VirtualHost>
The yocto recipe unzips the index.html which is in myweb.zip and installs the virtual host config. The code looks like:
SUMMARY = "myweb"
SECTION = "test"
LICENSE = "CLOSED"
SRC_URI = "file://myweb.zip \
file://myweb.conf \
"
DEPENDS = "apache2"
S = "${WORKDIR}"
WWWdestPATH = "/var/www/html/"
do_install () {
install -d ${D}${WWWdestPATH}
cp -r ${S}/myweb/* ${D}${WWWdestPATH}
install -d ${D}/etc/apache2/sites-available/
cp ${S}/myweb.conf ${D}/etc/apache2/sites-available/myweb.conf
}
FILES_${PN} += "${WWWdestPATH}*"
FILES_${PN} += "/etc/apache2/sites-available/*"
Any ideas how to modify the files to get the website started?
Stefan,
If I understand you correctly you want to host web pages on the ATMEL board for clients connecting via eth0. I can't see anything obviously incorrect in your virtual host definition.
Adding mywebsite as ServerName tells Apache that that is the name for this specific virtual host - but clients still need to be able to resolve that name. Please note that if you only have a single site on the server the name doesn't matter in the Apache configuration - what matters is the DNS configuration. As long as the hostname resolves to the web server any request for any hostname would get the default site - unless there is a virtual site with a name that matches the requested host name.
What I would do is to start from the web server end and work your way out from there:
If you have included telnet in your build you could for instance access the web page directly from the command line to make sure that it answers. Do this on the ATMEL board (e.g. via ssh or if you have a display+keyboard):
telnet localhost 80 <ENTER>
GET / HTTP/1.1 <ENTER>
Host: mywebsite <ENTER><ENTER>
If that returns your web page then the web server is configured correctly.
Make sure that you can reach the ATMEL board from your client. On the client:
ping 1.2.3.4
If this doesn't work you need to put the client on the same network as the eth0 interface by setting it manually on the client or by adding a DHCP server on the ATMEL board, bound to eth0.
Make sure that the client can resolve the mywebsite host name. On the client:
ping mywebsite
If this doesn't work you need to add a DNS service (e.g. bind) to your image or, for a quick test, add the following line to the /etc/hosts file on your client (c:\windows\system32\drivers\etc\hosts if you are running Windows):
1.2.3.4 mywebsite
Hope that helps.

My Linux System doesn't recognize hostname. How could I fix it?

I am setting a Linux machine and I have a problem. When I try to run the command:
hostname -f
I get this error:
hostname: Name or service not known
I am ew on this and I would like to know how could I solve it. My /etc/hosts and /etc/hostname files show the next:
/etc/hostname:
namehost
/etc/hosts:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
Thak you so much!
Try sudo apt-get -f install first and then retry.
I had to configure the file /etc/hosts and add there the next line:
127.0.0.1 namehost
Doing this, it works!

Host name showing (none) at login

I am a newbie to Linux environment and building a Linux system from scratch using busy box. I created /etc/hosts and /etc/hostname file. But every time I start the system it shows (none)login:
But I can change the hostname using hostname command after logging in. I don't want any FQDN hostname or dynamic hostname configuration from DNS server. The content of the host name files are:-
$cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 tiny
$cat /etc/hostname
tiny
Is there wrong with the procedure or file. Please any help is appreciated.
You're likely going about this the right way and just need to either restart the system sudo reboot (or just reboot as the root user) or reload networking.
On Ubuntu and other Debian-variants, you're correct - you need to update /etc/hostname and /etc/hosts. To reload networking: service networking reload or invoke-rc.d networking force-reload.
On Fedora/CentOS and other Red Hat variants, you can set the hostname using the hostnamectl program. To reload networking: /etc/init.d/network reload
On Android, I believe the command you want is: setprop net.hostname <your name here>.
Also, you can combine your entry in /etc/hostname to:
127.0.0.1 localhost tiny
Perhaps your IP-address is not really 127.0.1.1 (it seems unlikely).
On most Linux systems, you have the ifconfig tool, which can show your IP-address. I would check if the IPv4 address displayed by ifconfig matches the IP-address given for "tiny" in your /etc/hosts file - and modify it to match. Once you have done that, you should be able to ping "tiny" to verify that the hosts file is updated. Verifying that the hostname is going to be used takes a reboot, of course.
Setting /etc/hostname and /etc/hosts doesn't work for my embedded arm Linux box. Instead, I put this line in the start script:
echo tiny > /proc/sys/kernel/hostname

Dedicated Server HTTPD Error

Recently I edited some files on my dedicated server (CentOS 6 64 bit) and when I decided to restart httpd I received the following error:
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
Does anybody know how I can resolve this issue?
Look in /etc/httpd/conf/httpd.conf for ServerName. Change that:
ServerName www.yourwebserver.com:80
Restart httpd.
Check to make sure the hostname you are using is reverse mapped. Or that it's defined in DNS.
You need to change the /etc/hosts file.
It should be like :
127.0.0.1 yourservername.yourdomain yourservername
Please be sure that this line appears once.

linux centos 6.3 hostname (dhcppc4) assigned automatically

Linux terminal showing hostname dhcppc4 that i never configured. As per configuration files hostname must be localhost :
[root#dhcppc4 ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
[root#dhcppc4 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
Note : I attached a new monitor to my laptop.
Don't know how but sometimes terminal shows localhost as hostname.
what is dhcppc4? How to resolve the issue?
This question is not suitable for stackoverflow (this should be on serverfault i guess)
Anyway, DHCP server could even assign an hostname to your machine
Look here: RFC 1553 - DHCP
Maybe this is your case?
You are most assuredly allowed to edit the HOSTNAME line of that config' file you refer to in your question just fine.
It will not show up until you logout & back in again. You will also want to run /etc/init.d/rsyslogd restart (or whatever syslog daemon you are using) to make that name take effect in the log files.
You may or may not need to run a vi /etc/hosts to adjust the lines in there as you need for your specific applications. Most will be fine, but some are very very picky, like the otherwise very awesome software, Zimbra, for one example, wont work if those lines are not perfect. Asterisk could be another one that might require that file to be perfect match with your configuration.
You can or can not work with your DHCP server to set this, but most people dont, most edit the HOSTNAME and move on.
It is actually important, though, and do in fact resolve this, dont just leave it, as we sysadmins do not want to be typing mission critical commands at the BASH prompt on the wrong machine when all 6 of your servers all say "localhost".

Resources