When I restart my Apache server using the command
sudo /etc/init.d/apache2 restartI 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 ServerNameIs the server using 127.0.1.1 instead of 127.0.0.1? What causes this error?
14 Answers
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:
/etc/apache2/apache2.confand insert:
ServerName localhost and then restart apache by typing into the terminal:
sudo systemctl reload apache2the notice will disappear.
If you have a name inside /etc/hostname you can also use that name instead of localhost.
And it uses 127.0.1.1 if it is inside your /etc/hosts:
127.0.0.1 localhost
127.0.1.1 myhostnameTroubleshooting Apache
If you get this error:
apache2: Could not determine the server's fully qualified domain name,
using 127.0.0.1 for ServerNamethen use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop to create a new file,
sudo nano /etc/apache2/conf.d/fqdnor
gksu "gedit /etc/apache2/conf.d/fqdn"then add
ServerName localhostto the file and save. This can all be done in a single command with the following:
echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdnBut on Ubuntu 14.04:
echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/fqdn.conf sudo a2enconf fqdnDon't forget the ".conf" (without will not work).
2213.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.
sudo vi /etc/apache2/conf-available/servername.confAnd inside this we just need to add one line
ServerName localhostYou can combine the previous two commands in one with:
echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/servername.confIf 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:
sudo a2enconf servernamea2enconf is a command to enable a configuration file in Apaches 2.4. Also note that servername on the above command is from the name of the configuration file servername.conf. If your configuration file was ngenericserver.conf then you would have to write sudo a2enconf ngenericserver.
After this reload the server and the above message will no longer bug you.
sudo service apache2 reloador
sudo apache2ctl gracefulNow after this you will see that the message will not be shown again and the problem will be fixed.
8Apache2 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 in httpd.conf or any apache config files.
Put the following in /etc/hosts:
# IPv4 and IPv6 localhost aliases
127.0.0.1 hostname.domainname.com hostname localhost
::1 hostname.domainname.com hostname localhostwhere hostname.domainname.com is the FQDN of your machine.
Along with a properly configured hostname in /etc/hostname/ or with hostnamectl, this will also help other services on your machine run properly (i.e. the login prompt, showing This is hostname.domainname.com instead of This is hostname.unknown_domain.)
- Open a terminal
Open the
/etc/apache2/httpd.conffile:sudo editor /etc/apache2/httpd.conf # [1]By default, it would be blank. Simply add the following line:
ServerName localhostSave the file and exit
Restart the server
sudo service apache2 restart
[1] Launch default editor, see sudo update-alternatives --config editor
In new version of apache2 you just following command like this:
sudo nano /etc/apache2/apache2.confAdd the following new line end of file:
ServerName localhostThen restart apache2:
sudo service apache2 restartIt's done.
1I find it is a bit better to create a new file in /etc/conf.d that to modify either apache2.conf or httpd.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:
ServerName myhost.mycomain.tldThe other suggestions certainly work also.
In Ubuntu 16.04:
sudo -i
echo 'ServerName localhost' > /etc/apache2/conf-available/server-name.conf
a2enconf server-name 0 On Ubuntu 16.04:
Add ServerName localhost to the file httpd.conf usin gthe following command.
sudo vi /etc/apache2/httpd.confThen include this line Include httpd.conf at the end of this file
sudo vi /etc/apache2/apache2.confCheck for syntax errors again
sudo apache2ctl configtestYou should now get
Syntax OKYou can now restart the server gracefully by reloading the configuration
sudo service apache2 reloador kill the process and start again
sudo service apache2 restart Add ServerName localhost
To
sudo leafpad /etc/apache2/apache2.conf sudo leafpad /etc/apache2/httpd.confIt'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:
# create the configuration file in the "available" section
echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/servername.conf
# enable it by creating a symlink to it from the "enabled" section
sudo a2enconf servername
# restart the server
sudo service apache2 restartThis 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:
On Ubuntu 11.10, I saw this message, along with a hung boot occurring because my disk was full. One of the log files had gone rogue. Probably there was not actually a problem with Apache, but this message was the last clue given before the boot hung.
To fix the problem, I had to boot into recovery mode and remove the wayward log file.
If you're using bash and want minimal dependencies (and just want a one-liner for your entrypoint script if you are using Docker like me), these two options should work.
If you want localhost:
echo "ServerName localhost" >> /etc/apache2/apache2.conf
If you want the existing hostname:
echo "ServerName $(cat /etc/hostname)" >> /etc/apache2/apache2.conf
This uses the bash redirection operators to append the string to the end of the file. Echo automatically inserts the newline, so you are all set.
Run the following command:
apachectl -t -D DUMP_INCLUDESto determine path to your httpd.conf configuration file, then edit that file and uncomment/modify the line which specifies the value for ServerName option, e.g.
ServerName localhostFor the web server, use the registered DNS name (e.g. example.com).
If your host doesn't have a registered DNS name, enter its IP address here.
On Ubuntu 16.04:
Add ServerName localhost to the file httpd.conf usin gthe following command.
sudo vi /etc/apache2/httpd.confThen include this line Include httpd.conf at the end of this file
sudo vi /etc/apache2/apache2.confCheck for syntax errors again
sudo apache2ctl configtestYou should now get
Syntax OKYou can now restart the server gracefully by reloading the configuration sudo service apache2 restart