PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, September 21, 2022

[FIXED] How to route all *.dev to subfolders on vagrant box

 September 21, 2022     apache, vagrant, vhosts, virtual-hosts     No comments   

Issue

I want that every *.dev Host will be routed to my vagrant machine to /var/www/vhosts/*.dev/public, for example my local development environment project1.dev is located in /var/www/vhosts/project1.dev/public

So when I add a new (sub)project into my box, I do not need to change my config.yaml (Vagrant installed via puphpet.com) and reload the machine.

On my computer, I added the following to the hosts file in /private/etc:

192.168.56.101 *.dev

On my VM, I changed my 10-default_vhosts80.conf in /etc/apache2/sites-enabled to:

# ************************************
# Vhost template in module puppetlabs-apache
# Managed by Puppet
# ************************************

<VirtualHost *:80>
  ServerName default

  ## Vhost docroot
  DocumentRoot "/var/www/default"

  ## Directories, there should at least be a declaration for /var/www/default

  <Directory "/var/www/default">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Require all granted
  </Directory>

  ## Load additional static includes

  ## Logging
  ErrorLog "/var/log/apache2/default_vhost_80_error.log"
  ServerSignature Off
  CustomLog "/var/log/apache2/default_vhost_80_access.log" combined

  ## Custom fragment
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/default/$1
</VirtualHost>
<VirtualHost *.dev:80>
    ServerName dev
    VirtualDocumentRoot /var/www/vhosts/%0
</VirtualHost>

Unfortunately, this doesn't work. Any ideas? I am a beginner in this subject.


Solution

In the end, I use dnsmasq to route all .localdev Domains to 127.0.0.1. Note that I am using .localdev instead of just .dev or .local as this seems to cause problem (OS X 10.10) because .dev is a proposed gTLD and .local is used by Apple's Bonjour.

Then I configured Apache by creating and enabling this site:

<VirtualHost *:80>
  ServerAlias localhost *.localdev #wildcard catch all
  VirtualDocumentRoot /hosts/%1/public
  UseCanonicalName Off
  <Directory "hosts">
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

(from: http://brunodbo.ca/blog/2013/04/26/setting-up-wildcard-apache-virtual-host-wildcard-dns)



Answered By - luke
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing