How to Configure Virtual Hosts on Centos 7 Apache Server

Prerequisites for a vhost setup:

1chown -R apache:apache /path_to/site_root

Set the permission of the root directory to 755, you may already know. ๐Ÿ™‚
Well, letโ€™s create a vhost config file before you edit it.

1cd /etc/httpd/conf.d
2vim domain_name.conf

Now, grab this content to your config file:

 1<VirtualHost *:80>
 3  ServerName
 4  ServerAlias
 5  DocumentRoot /var/www/path_to/site_root
 7  <Directory /var/www/path_to/site_root>
 8    Options Indexes FollowSymLinks MultiViews
 9    AllowOverride All
10  </Directory>
12  CustomLog /var/log/httpd/ combined
13  ErrorLog /var/log/httpd/
14  # Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
15  LogLevel warn

Finally, restart the apache to check if you done well. ๐Ÿ™‚

1sudo systemctl restart httpd

In some cases, like Laravel apps or Magento, in case you got stuck, donโ€™t forget to check selinux status first.
Happy networking gents! ๐Ÿ™‚

comments powered by Disqus