set up a vhost with vagrant

Matheus picture Matheus · Jul 16, 2014 · Viewed 9.6k times · Source

I'm having troubles with setting a vhost with vagrant. I've configured my host file on my host (192.168.33.10 local.dev). Yet I don't know how to set up my vhost within my VM and how to access it. And I don't want to use puppet or chef or other as I want to understand what I'm doing... :) At the moment here are my settings of my vhost:

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/support/mysite
<Directory /var/www/html/support/mysite>
     Options -Indexes +FollowSymLinks
     AllowOverride All
     Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/mysite-error.log
CustomLog ${APACHE_LOG_DIR}/mysite-access.log combined

The problem is I don't really know what I should put as server name or alias and how to access it then. Thanks for any help !!!

Answer

noeldiaz picture noeldiaz · Jul 18, 2014

If you already added all the sites you want to run as virtual ones on your host file (all with same IP), then all you need to do is add multiple "VirtualHost" configurations to your apache conf file and use the same "site.dev" name you defined. Apache will read that and direct to the correct "DocumentRoot".

Here is a snippet with two sites defined. Just add more definitions for more sites:

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/html/site1/
  ErrorLog logs/site1_error_log
  CustomLog logs/site1_access_log combined
  ServerName site1.dev
</VirtualHost>

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/html/site2/
  ErrorLog logs/site2_error_log
  CustomLog logs/site2_access_log combined
  ServerName site2.dev
</VirtualHost>