When I restart my Apache server using the command
sudo /etc/init.d/apache2 restart
I get the following error:
Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2:
Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
Is the server using 127.0.1.1 instead of 127.0.0.1? What causes this error?
13.04 and older
This is just a friendly warning and not really a problem (as in that something does not work).
If you go to:
and insert:
and then restart apache by typing into the terminal:
the notice will disappear.
If you have a name inside
/etc/hostname
you can also use that name instead oflocalhost
.And it uses
127.0.1.1
if it is inside your/etc/hosts
:Preferred method
If you get this error:
then use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop to create a new file,
or
then add
to the file and save. This can all be done in a single command with the following:
But on Ubuntu 14.04:
Don't forget the ".conf" (without will not work).
13.10 or newer
As of Apache 2.4 - which is available by default as of 13.10 - you cannot use the method about adding a config file in the
conf.d
directory.Apache no longer uses the
conf.d
directory. All the configuration files are stored inside/etc/apache2/conf-available
directory and all the configuration files should now have a.conf
extension.In order to solve this message in Apache 2.4, we have to create a configuration file inside the conf-available directory. For example
servername.conf
.And inside this we just need to add one line
You can combine the previous two commands in one with:
If you want to use a domain name or any other name depending on the requirement its fine, just replace
localhost
with whatever you need. Next you have to enable this configuration. For this, you need to run the following command:a2enconf
is a command to enable a configuration file in Apaches 2.4. Also note thatservername
on the above command is from the name of the configuration fileservername.conf
. If your configuration file wasngenericserver.conf
then you would have to writesudo a2enconf ngenericserver
.After this reload the server and the above message will no longer bug you.
or
Now after this you will see that the message will not be shown again and the problem will be fixed.
Apache2 can also get the FQDN from a properly configured system hostname rather than hardcoded into the apache config file. Hardcoding it will also cause confusion if the hostname changes. You actually don't need any
ServerName
directives inhttpd.conf
or any apache config files.Put the following in
/etc/hosts
:where
hostname.domainname.com
is the FQDN of your machine.Along with a properly configured hostname in
/etc/hostname/
or withhostnamectl
, this will also help other services on your machine run properly (i.e. the login prompt, showingThis is hostname.domainname.com
instead ofThis is hostname.unknown_domain
.)Open the
/etc/apache2/httpd.conf
file:By default, it would be blank. Simply add the following line:
Save the file and exit
Restart the server
[1] Launch default editor, see
sudo update-alternatives --config editor
In new version of apache2 you just following command like this:
Add the following new line end of file:
Then restart apache2:
It's done.
I find it is a bit better to create a new file in
/etc/conf.d
that to modify eitherapache2.conf
orhttpd.conf
.It's a personal preference that keeps my configuration changes separated from the distribution package. So updates are less complicated.
I create the file
/etc/apache2/conf.d/AAserverName
and it contains only:The other suggestions certainly work also.
In Ubuntu 16.04:
On Ubuntu 16.04:
Add
ServerName localhost
to the filehttpd.conf
usin gthe following command.Then include this line
Include httpd.conf
at the end of this fileCheck for syntax errors again
You should now get
You can now restart the server gracefully by reloading the configuration
or kill the process and start again
Add
ServerName localhost
To
It's not an error.. It's just a friend reminder
Specifying
ServerName localhost
in your configuration files outside of the virtual host sections is the way to do this.Some other answers suggest that you should modify
/etc/apache2/httpd.conf
. This file gets overwritten when apache gets upgraded from apt. For Apache configuration that you don't want to get overwritten, you should create a new file. Here is the "Debian way" to make this configuration change:This is basically the same as Stark's answer, but in an easy to copy and paste script form. I had originally posted this in a question that was marked as duplicate: https://askubuntu.com/a/432408