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>
2
3 ServerName domain.com
4 ServerAlias www.domain.com
5 DocumentRoot /var/www/path_to/site_root
6
7 <Directory /var/www/path_to/site_root>
8 Options Indexes FollowSymLinks MultiViews
9 AllowOverride All
10 </Directory>
11
12 CustomLog /var/log/httpd/domain.com-access.log combined
13 ErrorLog /var/log/httpd/domain.com-error.log
14 # Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
15 LogLevel warn
16
17</VirtualHost>
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! ๐