Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant Share - Accessing Virtual Hosts and accessing those that are not in the default web root

I have Vagrant setup and running CentOS 6.5 x64 and it runs great. No issues running multiple sites within this one VM. All sites are running from the /var/www/public folder with the exception of PhpMyAdmin which runs from /var/www/html. I am trying to use vagrant share to gain access to any of the vhost sites that are running. The problem is that vagrant share is only displaying the contents of the /var/www/html folder.

Is there something further that I need to do in order to gain access to my newly created /var/www/public folder? I have tried editing the hosts file, on another machine, to see if I can forward any of the url's I assigned to these sites to the current funky 'vagrant share' address but this does not work. I am just personally at a loss for what I should do next.

This is my basic setup. Vagrant version 1.5.4, VirtualBox version 4.3.8, Windows 7 x64, Config file by PuPHPet but highly customized after download for added vhosts, ssh config, mysql, and bash files.

Hopefully someone else may have run into this issue as well. Does anyone have a good direction I can turn?

Thanks everyone,

c0p


SELF UPDATE

I have significant headway with my own question. The point of what I'm doing is to allow access to person's offsite from my Vagrant machine. I don't need them to have complete access all of the time but rather just review things as they are and inform me of any changes they may need. You know, standard dev stuff. So here is what I have come up with.

Researching the web in general I ran into this link: https://groups.google.com/forum/#!topic/vagrant-up/IcEl9-V9wsU

This guy is running Nginx and looks to be asking the same question as me but using a different webserver. Please take a look at the page if you are running into something similar with Nginx. He does have an answer there. I know nothing about Nginx but was still able to extrapolate a bit of what I needed.

So what I got from that page was that once he received the unusual link from the Vagrant site, he quickly edited his config files for Nginx and restarted the webserver. Now, the crazy url was pointing to the virtual hosts file location and causing the page he wanted to appear, to actually appear and not just show the default 'Welcome' page.

I thought about it for a while and decided to edit my own config and see what happens.

I'm running CentOS so I edited the /etc/httpd/conf/httpd.conf file.

There is a commented #Listen 80 line about half way down this file. Immediately following this line (or give it a space if you want), I added this:

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/public/sitename
    ServerName hungry-lovebird-7142.vagrantshare.com
    ServerAlias hungry-lovebird-7142
    ErrorLog /var/www/www.sitename.dev-error_log
    CustomLog /var/www/www.sitename.dev-access_log common
</VirtualHost>

I've pointed the DocumentRoot to the folder of the site I want to access and set the ServerName and ServerAlias to the vagrant share link. I then saved the file and restarted Apache with sudo service httpd restart

I then jumped back to Firefox (Windows 7) and refreshed the oddball vagrantshare.com page that I had already gone to prior to editing this file. It actually pulled up the contents of the sitename folder I had given it in the httpd.conf file. So it works! Friggin' cool!

The only issue I have with this is that I was receiving this warning when restarting Apache:

Stopping httpd:                                            [  OK  ]
Starting httpd: [Wed May 21 00:11:37 2014] [warn] NameVirtualHost *:80 has no Vi
rtualHosts

Apache would start just fine but I didn't know what to do with that warning. Later I just removed the NameVirtualHost *:80 portion of what I added and restarted Apache. This time with no warnings at all.

Understand that this allows me to show a client updates to an individual site only. This worked for both static sites and for WordPress sites. I just changed where the vagrantshare.com link was looking for files. I was able to change to multiple sites by editing the httpd.conf file and restarting Apache all within the same vagrant share session (they do time-out). I'm using Windows so I had two copies of git-bash(msysgit) running at the same time. One hosting the vagrant share session and the other accepting edits to httpd.conf after vagrant ssh'ing in to the VM.

If you are going to be using this for some WordPress site, you will also need to edit the wp_options table for that site. Change the siteurl and home values in the option_value column to the complete url of the link given to you by vagrant share. You may also be able to just edit these values in the Admin Panel but I'm a lot faster with MySql so I chose that route.

Yay! Ok, great. I have achieved almost what I wanted to begin with. Hopefully someone can shed some light on why what I did actually works. Did I just basically do a redirect for that address?

By the way, when you're done with vagrant share, don't forget to comment out those lines (keep them as you'll probably need them later) and restart Apache. Now get back to work with whatever the client wants changed!

Anyway, I hope someone can answer the 'why did this work' question that remains and I really hope it helps someone along the way.

Thanks,

c0p

like image 485
cOp Avatar asked May 20 '14 07:05

cOp


2 Answers

Struggled with this a bit, your update pointed me in the right direction though.

What I ended up doing is as follows:

  1. vagrant share
  2. ssh to VM
  3. sudo vi /etc/apache2/sites-enabled/your-site-name.conf
  4. change ServerName to your-generated-name.vagrantshare.com
  5. sudo service apache2 reload

EDIT:

If you'd like to have access to the virtualhost on several domains (i.e. vagranshare's domain and your local like example.dev) After step 4 add ServerAlias example.dev to /etc/apache2/sites-enabled/ your-site-name.conf

Thanks, hope this helps anyone with as little server-knowledge as I have.

like image 55
michaeltintiuc Avatar answered Oct 07 '22 08:10

michaeltintiuc


Change your WhateverItIs.conf file followingly by adding ServerAlias:

ServerName WhateverItIs.com
ServerAlias *.vagrantshare.com 

and now you are good to go.

like image 33
Özgür Avatar answered Oct 07 '22 07:10

Özgür