Debian – Where in Apache 2 do you set the ServerName directive globally

apache-httpdconfigurationdebian

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.

Best Answer

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
Related Question