How to use vagrant on multiple projects

前端 未结 1 1829
独厮守ぢ
独厮守ぢ 2021-01-27 05:15

I\'m new to Vagrant and I\'m trying out PuPHPet in order to get things up and running. I can get a debian box up and running and ssh into it. It\'s more the workflow I\'m unclea

相关标签:
1条回答
  • Short Answer


    I recommend that you keep your PuPHPet files, the resulting Vagrantfile and its environment in a directory separate from your site (source) files directory because this seems more organized and secure to me. It is perfectly fine to set up a new virtual machine for each project, but I prefer to set up one single Vagrant box and have it service all of my projects at once so I'm not constantly putting boxes up-and-down as I switch between projects.


    Explanation


    To do this, configure your "Shared Folder Pairs" on PuPHPet.com to map your Folder Source (the /source/code/path/name where your source files are on your main computer) to the Folder Target (the /destination/path/name on the Vagrant-generated virtual machine where your Vagrant-generated web server can find them) for each of your projects (screenshot). Configure the web server (using PuPHPet's Web Servers configuration page) to reference such /destination/path/name directories, which maps those working files to a usable server name, server alias and document root.

    As a warning, do NOT use the /var/www folder directly as a Folder Target. In some configurations, this will cause Apache to fail installation when provisioning with Vagrant.

    In the config.yaml file created by PuPHPet, you'll see entries like this:

    synced_folder:
        vflsf_12randomlettersandnumbers:
            source: /Users/unrivaled/www-development-source-files
            target: /var/www/dev
    

    On PuPHPet.com, where you would configure your environment, there is a section where you configure your "Shared Folder Pairs." This is where you tell Vagrant where your files are now (on your main computer) and where you want them to appear in your Vagrant-generated virtualized environment.

    An important concept to grasp here is my use of the words "are" and "appear."

    Your files "are" on your computer - the one you are presumably using to edit and debug your projects, and from which you want to run PuPHPet to host a Vagrant-generated web server. This is your "host" operating system, and your development files (source code) will always simply reside here. You will never need to copy them back-and-forth between your main computer and the Vagrant-generated web server.

    By contrast, your files "appear" on the Vagrant-generated web server created when you run vagrant up, which generates a "guest" operating system in a Vagrant-generated virtualized environment where the web server, database engines and so forth run. Note that you are not copying files there (onto the "guest" operating system). Instead, Vagrant will cause them to appear there for you, per your use of the "Shared Folder Pairs" mentioned earlier:

    Folder Source represents the location on your main computer (the "host" operating system), where your source files reside.

    Folder Target represents the location on your virtual computer (the "guest" operating system), where you want Vagrant to make them visible in the guest OS.

    In this way, you simply edit your files in your development environment, wherever they happen to be now; and Vagrant will make sure your Vagrant-generated web server sees those files instantly, live, in real time. Even if you vagrant destroy this generated web server environment, your source files will be completely untouched. Simply recreate a new environment (vagrant up), and bam! There you go. Back in business.

    0 讨论(0)
提交回复
热议问题