35

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.

40

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
  • 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 – Dr Beco Jul 21 '15 at 17:29
  • 2
    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). – Peter Mortensen 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 at 12:37
5

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.

  • 5
    In Ubuntu, set it in /etc/apache2/apache2.conf – macki Dec 1 '14 at 6:28
  • 1
    Debian either: apache2.conf. – Dr Beco 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. – Peter Mortensen Dec 27 '16 at 13:01
  • it works, Apache 2.4 on Debian 8 – erajuan Feb 20 '17 at 2:35
2

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

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.