Apache – Issue with HTTPD Configuration for Virtual Hosts

apache-2.4httpd

SHORT VERSION

  • Trying to use virtual hosting on an old computer to serve web content on my home network over different domains linked to the same ip address by following a tutorial.

  • After following the tutorial, I get the error:

    $sudo service httpd restart
    $Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details
    
  • After reviewing systemctl and journalctl's output as directed, forum reading and going through stuff, find that commenting out the following line in /etc/httpd/conf/httpd.conf allows me to start httpd:

    IncludeOptional sites-enabled/*.conf
    
  • I believe something is wrong with the directory that is symbolically linked to sites-enabled, but can't figure out what against the tutorial. All information is posted below.

Necessary Information

  • Link to tutorial I'm following

  • Version of Apache: 2.4.6

  • Files in /etc/httpd/sites-available (sites-enabled symlinked to this dir)

    • example2.com.conf
    • example.com.conf
  • example.com.conf contents

    <VirtualHost 192.168.1.4:80>
      ServerName www.example.com
      ServerAlias example.com
      DocumentRoot /var/www/example.com/public_html
      ErrorLog /var/www/example.com/error.log
      CustomLog /var/www/example.com/requests.log combined
    </VirtualHost>
    

The contents of example2.com.conf are the same except with "example2" replacing every instant of "example"

Please let me know of any other files or output needed to help troubleshoot this.

Best Answer

Something like this should work - be sure that the filename ends in .conf. I host quite a few domains for me and my friends, so the DocumentRoot for each is /var/www-domain. I name the file /etc/apache2/sites-available/domain.conf and then link it over or use a2ensite and then restart/reload apache. Be sure to make the /var/www-example.com directory! Finally, apache2ctl -S will show/test your config

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAdmin webmaster@example.com
    DocumentRoot /var/www-example.com
    <directory /var/www-example.com>
        Options All
                AllowOverride All
                Require all granted
    </directory>
</VirtualHost>
Related Topic