NOTE: This is related to my question: "Apache 2.4 won't reload, any problem with my configuration?".

I'm trying to test a local site, locally. As I understand Apache 2 (and perhaps Apache as well) has something called VirtualHost. My little bit of understanding tells me that virtualhosting is a way where one server/IP address can serve multiple domains.

Anyway, I'm getting the following error when running Apache 2's configtest to see where I'm failing. I'm running Apache 2.4.10-1, and it seems there are a lot of changes which have happened between Apache 2.2 and Apache 2.4 which I'm not aware of.

$ sudo apache2ctl configtest
[sudo] password for shirish:
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using Set the 'ServerName' directive globally to suppress this message
Syntax OK

This is the /etc/hosts file:

 $ cat /etc/hosts    localhost    debian mini

I also see an empty /etc/hosts.conf file. Perhaps the data in /etc/hosts needs to be copied to /etc/hosts.conf for the server to take cognizance?

My hostname:

$ hostname

This is the configuration file of the site:

$ cat /etc/apache2/sites-available/minidebconfindia.conf
<VirtualHost mini:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/html/in2014.mini/website

    <Directory />
        Options +FollowSymLinks +Includes
        Require all granted

    <Directory /var/www/html/in2014.mini/website/>
        Options +Indexes +FollowSymLinks +MultiViews +Includes
        Require all granted

I also read about binding to addresses and ports, but I haven't understood that well for multiple reasons. It doesn't give/share an example as to in which file those lines need to be put and what will come before and after. An example would have been much better.

I did that and restarted the server, but I still get the same error.

~$ sudo apache2ctl configtest
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using Set the 'ServerName' directive globally to suppress this message
Syntax OK

It seems there are three configuration files in Debian that I need to know and understand.

/etc/apache2$ ls *.conf
apache2.conf  ports.conf


/etc/apache2/conf.d$ ls *.conf

Apparently, apache2.conf IS the global configuration file while the httpd.conf is a user-configuration file. There is also ports.conf. Both apache2.conf and ports.conf are at the defaults except I have changed the loglevel of Apache from warn to debug.

I tried one another thing:

$ sudo apache2ctl -S
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:           debian (/etc/apache2/sites-enabled/minidebconfindia.conf:1)
*:80          (/etc/apache2/sites-enabled/000-default.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
User: name="www-data" id=33
Group: name="www-data" id=33

Maybe somebody has more insight.


The file to edit:


Command to edit file:

sudo nano /etc/apache2/apache2.conf

For a global servername you can put it at the top of the file (outside of virtual host tags).

The first line looks like:

ServerName myserver.mydomain.com

Then save and test the configuration with the following command:

apachectl configtest

You should get:

Syntax OK

Then you can restart the server and check you don't get the error message:

sudo service apache2 restart
  • 2
    This is the Debian correct answer. I tried /etc/apache2/conf-available/fqdn.conf, or servername.conf or httpd.conf to no avail. Debian Jessie, and apache 2.4.10
    – DrBeco
    Jul 21 '15 at 17:29
  • 3
    If you have conf-available/ and conf-enabled/, create a file in conf-available/ and use the command a2enconf to enable it. This way, dpkg will not annoy you about untracked changes when/if the apache2-common package updates apache2.conf
    – Kevin
    Aug 24 '15 at 14:28
  • The file in conf-available after this and an edit might be /etc/apache2/conf-available/servername.conf with content ServerName myserver.mydomain.com (tried on Raspberry Pi, Apache 2.4.10, Debian 8 (Jessie), Linux kernel 4.4.34). Dec 27 '16 at 13:41
  • @PeterMortensen could you use the example shared so I can understand what you mean.
    – shirish
    Jan 4 '17 at 17:39
  • The file does not exist
    – Black
    Jul 30 '19 at 12:37

You must set ServerName directive:

ServerName localhost

In Debian, you can set it in /etc/apache2/conf.d/httpd.conf.

On macOS, you can set it in /private/etc/apache2/httpd.conf.

  • 6
    In Ubuntu, set it in /etc/apache2/apache2.conf
    – macki
    Dec 1 '14 at 6:28
  • 1
    Debian either: apache2.conf.
    – DrBeco
    Jul 21 '15 at 17:29
  • 1
    What versions of Apache/Debian does this work for? I don't think it works for Apache 2.4. It could be /etc/apache2/apache2.conf instead. Dec 27 '16 at 13:01
  • it works, Apache 2.4 on Debian 8
    – erajuan
    Feb 20 '17 at 2:35
  • Everything gets more complicated. Setting it near the top of /etc/apache2/apache2.conf works, there's a "Global configuration" label but it's just a comment. On a LAN with NAT your servername can be the machine's hosthname that's in /etc/hostname. If you use static IPs you can put your IP in there. Using Apache 2.4.25. apache2ctl is in /usr/sbin which is maybe not in all user's paths.
    – Alan Corey
    Dec 12 '20 at 18:29

To locate your Apache configuration file, try running the following command:

apachectl -t -D DUMP_INCLUDES

Then edit that file and locate line with ServerName and uncomment it, so it looks like:

ServerName localhost

In apache24 config file, you will see the line ServerName:80:

  1. Leave it blank.
  2. Then below that line in the empty space write:
    ServerName www.name (of your official domain or website.com:80)
  3. Save the config file.
  4. Go to cmd, open it as administrator change dir to where apache24 is
  5. Then cd apache24 then cd bin then httpd.exe

You will see the problem is solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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