0
votes

I have installed an Apache server in CentOS 8 and it was serving both http and https pages correctly, that is, I could view the Apache test page when connected to the server from my browser

I used this tutorial to enable https: https://www.techrepublic.com/article/how-to-enable-https-on-apache-centos/

This much worked. But when I tried to enable the server to serve webpages other that the default test page, I am getting the error "AH00558: httpd: Could not reliably determine server's fully qualified servername error after creating VirtualHost" when trying to restart the apache server using

sudo systemctl restart httpd  

Here are the contents of my /etc/https/conf/http.conf with some comments removed.

ServerRoot "/etc/httpd"
Listen 80

Include conf.modules.d/*.conf

User apache
Group apache

ServerAdmin root@localhost

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/var/www/html"

<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>

    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on

IncludeOptional conf.d/*.conf

IncludeOptional sites-enabled/*.conf

I have a feeling this has something to do with the ServerName entry. It is commented by default as shown above, but I have tried uncommenting it as well as matching it with the coonfiguration in my VirtualHost file, but I am getting the same error.

Here are the contents of the /etc/httpd/sites-available/adorkable.conf

(NOTE: the word adorkable has been replaced with my username, username1)

<VirtualHost *:443>
    ServerAdmin [email protected]
    DocumentRoot "/var/www/html/username1/"
    ServerName localhost.localdomain
    ServerAlias username1
    ErrorLog /var/www/html/username1/error.log

<Directory "/var/www/html/username1/">
    DirectoryIndex index.html index.php
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

Output of systemctl status httpd after issuing a systemctl restart httpd:

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2020-05-14 14:53:28 KST; 43s ago
     Docs: man:httpd.service(8)
  Process: 11746 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 11746 (code=exited, status=1/FAILURE)
   Status: "Reading configuration..."

May 14 14:53:28 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
May 14 14:53:28 localhost.localdomain httpd[11746]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
May 14 14:53:28 localhost.localdomain systemd[1]: httpd.service: Main process exited, code=exited, status=1/FAILURE
May 14 14:53:28 localhost.localdomain systemd[1]: httpd.service: Failed with result 'exit-code'.
May 14 14:53:28 localhost.localdomain systemd[1]: Failed to start The Apache HTTP Server.

How do I restart the httpd service here?

UPDATE: the linked tutorial above says that we need to add the following line at the end of httpd.conf

IncludeOptional sites-enabled/*.conf  

This is the only change I have made to the default httpd.conf file, and if I comment this line I can restart httpd normally. So the problem is somewhere in my version of the /etc/httpd/sites-available/adorkable.conf file (renamed to username1.conf in my case. I have a symlink to this file in sites-enabled, created using the command

sudo ln -s /etc/httpd/sites-available/adorkable.conf /etc/httpd/sites-enabled/adorkable.conf  

as instructed in the linked tutorial.

1
Try removing ServerName from virtualhostExample person
@Chi.C.J.RajeevaLochana didn't work, i tried removing ServerName, ServerAlias, ServerAdmin; same erroruser13267
instead of sudo ln -s /etc/httpd/sites-available/adorkable.conf /etc/httpd/sites-enabled/adorkable.conf , you could also try using just the command a2ensite adorkable. But I don't think it makes a differenceExample person
@Chi.C.J.RajeevaLochana I don't ave a2ensite commanduser13267
oh ok. I though you were using Ubuntu, sorryExample person

1 Answers

1
votes

Remove ErrorLog from virtualhost. And try. As /var/www/html/username1/error.log doesn't exist. Try running chown apache:apache /var/www/html/username1 -R only if apache restart is successful after removing the ErrorLog directive. After you run the command, try adding back the ErrorLog directive, I believe it should work.