I'm trying to restart Apache 2:

sudo service apache2 restart

But get the below error:

* Restarting web server apache2 

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using

Set the 'ServerName' directive globally to suppress this message

I've tried to change

sudo gedit /etc/apache2/httpd.conf

A blank file appears, and I'd added this:

ServerName localhost

But that error doesn't disappear!

How can I fix this problem?

  • 1
    well have you checked the link I posted? The error is clearly the same. try "my" Answer below. – Meintjes Aug 6 '13 at 13:58

I found this: How do I restart/reload Apache when it can't determine the domain name?

Good news! Apache is restarting successfully. Apache just isn't sure where you want serve from, so it's choosing your localhost ( by default. To prevent this message from appearing, clarify that you want to serve from localhost ( by adding the following line into your /etc/apache2/apache2.conf file:

ServerName localhost
  • 2
    Optionally you can add this under the "Global Configuration" section. Order doesn't matter, but if you're trying to find it later this helps for organization. – Rebecca Dessonville Dec 11 '13 at 18:52
  • 8
    In newer versions of Ubuntu, it may make more sense to put it in /etc/apache2/conf-available/ServerName.conf and then run 'sudo a2enconf ServerName'. This way you don't change the app controlled config and you will override it if it does get changed in a future version for some reason. – flickerfly Mar 2 '15 at 19:24
  • 1
    It worked for me, thanks. I up voted this answer. – ThunderBird Apr 20 '16 at 22:58

Specifying ServerName localhost in your configuration files outside of the virtual host sections is the way to do this.

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 restart
  • 4
    more clean solution maybe – khaled_webdev May 12 '14 at 11:29

Your localhost IP Address should be, instead of Please setup your /etc/hosts file properly. Then edit the httpd.conf file:

sudo -H gedit /etc/apache2/httpd.conf

When a blank file appears, please add this line, then save:

ServerName localhost

Here is another Solution:


[root@centos ~]# /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: apr_sockaddr_info_get() failed for centos.wks.local
httpd: Could not reliably determine the server's fully qualified domain name, using for ServerName
                                                           [  OK  ]

Added centos.wks.local in /etc/hosts file

Note: is my Apache server IP address.


[root@centos ~]# /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
  • 1
    No /etc/init.d/httpd for Apache on Ubuntu. It's /etc/init.d/apache2. Just pointing out. – moon.musick Aug 6 '13 at 14:47
  • Yes, it's from CentOS but solution will work, because it's required FQDN – Rahul Patil Aug 6 '13 at 15:44
  • Editing /etc/hosts is quite bad practice to say the least. – Giacomo1968 Oct 13 '17 at 15:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.