71

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 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK

This is the /etc/hosts file:

 $ cat /etc/hosts
127.0.0.1    localhost
127.0.1.1    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
debian

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>

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

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

and

/etc/apache2/conf.d$ ls *.conf
httpd.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 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
127.0.1.1:80           debian (/etc/apache2/sites-enabled/minidebconfindia.conf:1)
*:80                   127.0.1.1 (/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"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

Maybe somebody has more insight.

5 Answers 5

81

The file to edit:

/etc/apache2/apache2.conf

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
5
  • 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
    Commented Jul 21, 2015 at 17:29
  • 4
    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
    Commented Aug 24, 2015 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). Commented Dec 27, 2016 at 13:41
  • @PeterMortensen could you use the example shared so I can understand what you mean.
    – shirish
    Commented Jan 4, 2017 at 17:39
  • The file does not exist
    – Black
    Commented Jul 30, 2019 at 12:37
14

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
  • 8
    In Ubuntu, set it in /etc/apache2/apache2.conf
    – macki
    Commented Dec 1, 2014 at 6:28
  • 1
    Debian either: apache2.conf.
    – DrBeco
    Commented Jul 21, 2015 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. Commented Dec 27, 2016 at 13:01
  • it works, Apache 2.4 on Debian 8
    – erajuan
    Commented Feb 20, 2017 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
    Commented Dec 12, 2020 at 18:29
6

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
3

I'm a few years late to the party ... 2023. I'm on Raspian, Apache2, I ran this command to find ServerName ...

find /etc/apache2 -type f -exec grep -s ServerName {} \;

I found it in sites-available/000-default.conf, in the VirtualHost configuration, nowhere else. I would think the correct file for ServerName would have it in place already, perhaps commented out, as it is where I found it.

6
  • 1
    grep -R ServerName /etc/apache2/* also works, no need to use exec.
    – dr_
    Commented Mar 23, 2023 at 13:16
  • @dr_ Does using exec cause problems? Commented Mar 26, 2023 at 13:46
  • 1
    It's unnecessary here. Always do things the simplest possible way (but not simpler, as Einstein used to say).
    – dr_
    Commented Mar 27, 2023 at 7:28
  • @dr_ Are you sure? I thought that was Ghandhi ... ;)
    – AdminBee
    Commented Mar 28, 2023 at 9:36
  • 1
    I'm gong to side with user3481644 here. The correct answer states that ServerName should be in the top-level file. It works just fine if you put the line there, but it isn't originally there, even commented out. This makes the original answer outdated. Commented Apr 17, 2023 at 21:32
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .