Search code examples
drupalvagrantvirtual-machinehostname

How can I access files outside of my webroot when using Vagrant?


I have a directory that contains the following structure:

phpinfo.php
adminer.php
drupal/
Vagrantfile
bootstrap.sh (config file)
index.html (on-boarding information for site-builder, etc.)

My synced folder is drupal (mapped to /var/www/html), but I also want to access phpinfo.php and adminer.php.

A hostname is also setup to be built as a webapp.dev host mapped to this new vagrant guest.

I could make the overall directory the synced folder, but I don't want to create clutter or have to access the site at webapp.dev/drupal.

How can I access both the drupal site as web root but still run the various tools? Is it possible to create an additional virtual host and synced directory that maps to the containing folder structure?


Solution

  • You can configure another synced folder. I'm doing this for certs that should be kept above webroot. Here's an excerpt from my Vagrantfile.

    config.vm.synced_folder "./public_html", "/vagrant",
      id:            "vagrant-root",
      owner:         "vagrant",
      group:         "www-data",
      mount_options: ["dmode=775,fmode=664"]
    
    config.vm.synced_folder "./certs", "/certs",
      id:            "certs"
    

    Note you have to use a separate id for each folder.