Prerequisites for a vhost setup:

1
chown -R apache:apache /path_to/site_root

Set the permission of the project root directory to 755, you may already know. 🙂

Well, let’s create a vhost config file before you edit it.

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

Now, grab this content to your config file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<VirtualHost *:80>

  ServerName domain.com
  ServerAlias www.domain.com
  DocumentRoot /var/www/path_to/site_root

  <Directory /var/www/path_to/site_root>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
  </Directory>

  CustomLog /var/log/httpd/domain.com-access.log combined
  ErrorLog /var/log/httpd/domain.com-error.log
  # Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
  LogLevel warn

</VirtualHost>

Finally, restart the apache server to apply your changes.

1
sudo systemctl restart httpd

If you get stuck when using a framework like Laravel or Magento, don’t forget to check selinux status.

Happy networking! 🙂