Aug 23, 2014

Setting Up Virtual Hosts With Apache 2.4.6

I've got two servers - one running Apache/2.2.15 (Unix) sitting on Cent OS version 6 and the other running Apache/2.4.6 (CentOS) sitting on Cent OS version 7. These two versions require very different approaches to setting up virtual hosts and to managing Apache itself.

For 2.4.6, the configuration file is located at /etc/httpd/conf/httpd.conf

Previously in 2.2.15 you would configure namevirtualhosts in this httpd.conf file.

The virtual hosts settings in 2.4.6 are set in the vhost.conf file located at:
/etc/httpd/conf.d/vhost.conf

You no longer include "namevirtualhosts" in your config. If you do you will get this message:
AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/httpd/conf.d/vhost.conf:1

The virtual hosts settings themselves remain unchanged and would typically look something like this:
<VirtualHost *:80>
    ServerAdmin admin@domain.com
    DocumentRoot /var/www/yourapp  
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    ErrorLog /var/www/logs/error-log
    CustomLog /var/www/logs/access-log common
</VirtualHost>

Restarting Apache would be via "service httpd restart" in 2.2.15.

In 2.4.6 the command is now "systemctl restart httpd."

Syntax checking is still via "httpd -t". Apache recommends httpd -S which gives you expanded information.

Official 2.4.6 page [Link.]

Official current version page [Link.]

No comments:

Post a Comment