Multiple vhosts with a simple LAMP in Vagrant

I am trying to create a simple LAMP via Vagrant, which can support multiple sites stored in / var / www. This can be done using vhosts.

Each project must end with .dev

It is not possible to create the idea of ​​creating each assembly that supports one project with each database.

I can't make a head or tail with a puppet or a chef. I rather avoid this, but I am happy to clone it from the repo.

I need advice or point me in the right direction.

thanks

+6
source share
3 answers

The easiest easy setup for strollers

https://github.com/fideloper/Vaprobash

See Apache Virtual Host Configuration for a quick start when creating a virtual host.

Do not forget to uncomment your preferred type of database before installation :)

Bonus : the only stray installation I could connect to Sequel Pro's db in seconds

0
source


Vagrant LAMP Multiple vhosts - UPDATED!


See Updated Information below.

I was looking for ways to improve my web development workflow. I am currently using various tools and applications such as LAMP, Webmin and Filezilla in Theming projects, etc. And then I discovered the existence of this amazing tool called Vagrant , and after testing it with my projects, I fell in love with it and decided to integrate it into the current local web developers environment. And so I pulled on and looked for opportunities to create and configure Multi Vhosts with Vagrant , using my selected Ubuntu 12.04 Precise Pangolin 32-bit base box. A Google search returns a lot of results, but I decided to click the links from stackoverflow and landed on this question. I followed the link mentioned in the answer by Dimitri Kouvdis which is the Github Repo. I tested it and ran into problems very similar to Dimitri Kouvdis . But he already decided now, thanks to his comments, I made it work. But during my search for the perfect Vagrant Box with multiple virtual support, I searched and tested several repositories from Github until I found the right option for me and I found it. The reason I chased these repositories is because I still don't know how to use Puppet and Chef to provide my own Dev server, why.

I found another github tutor who worked for me

Thanks to this repo

onema / vagrant-lamp-development

https://github.com/onema/vagrant-lamp-development

Testing the Github Repo Dimitri Kouvdis mentioned, I ran into several problems, and during that time I stopped working on it and decided to look for similar repositions from Github. I found several and tested some of them, including Nino Paolo Repo ( https://github.com/paolooo/vagrant-lamp ). I recently encountered several problems, especially during vagrant up . I decided to find another one again until I find and can set up an onema repo. Finally, I decided to use and integrate this solution into my current workflow in my web development environment. I started to love onema repo because:

  • It is easy to set up, as the instructions are easy to follow, especially for beginners and self-employed like me.
  • It has several documents and an example setup.
  • Most of all, adding new Vhosts is easy compared to the others I tested.
  • You can select and configure any folder on your local drive as the source / project folder.
  • This is just without the unnecessary (in my case) add-ons (node.js, less, etc.). I just need the LAMP stack, plus support for vhost and phpmyadmin.

How to set it up - for starters and self-employed, as for themselves

As I mentioned above, the setup is simple (especially for beginners and self-employed like me) by reading and following the instructions found on this Github Repo page. - https://github.com/onema/vagrant-lamp-development . You can use the downloaded zip file or use git clone https://github.com/onema/vagrant-lamp-development to copy Vagrant files to a local drive.

This is how I installed it (in my machine * nix, Ubuntu 12.04 x64);

  • Download the files to your local drive using the downloaded zip or git files and perform basic configuration of Vagrant and VirtualBox. Read the instructions on the Github page, and then follow these steps.

  • With my setup, I edited Vagrantile . In line: 70 the orig Vagranfle file, I disabled NFS by posting a comment # in

    config.vm.synced_folder "~/Sites", "/vagrant", nfs: true

    So now it looks like this ...

    #config.vm.synced_folder "~/Sites", "/vagrant", nfs: true

    and then commenting ...

    #config.vm.synced_folder "~/Sites", "/vagrant"

    line: 140 from orig Vagrantfile

    So now it looks like this ...

    config.vm.synced_folder "~/Sites", "/vagrant"

    I do this because on my machine, during vagrant up it throws up several NFS-related errors that I don’t understand.

  • Now, for the sake of this example, and from the example from its Repo page, create a folder, and you should name it Sites . This should be located in your root directory of the user account or in the home folder .

    /home/your-user-account-home-folder/Sites

    In my case (pay attention to this capital S)

    /home/gary/Sites

    • A.

      Create a sample dev-site / vhost and create a new folder called wordpress.dev and do it as the document root of your vhost wordpress.dev Then add your project files here. See the example below:

      /home/gary/Sites/wordpress.dev

    • B.

      Now create a simple splash page for your newly created vhost so that you can confirm that your configuration redirects you to the root vhost destination folder when you visit the dev site from your browser. Of course, when your configurations are correct, you will see a popup page. Here's how I made my splash page.

      I created the index.php file and put some codes into it;

      <?php echo "Success!!! Your wordpress.dev looks fine"; ?>

      So, when you have successfully reached your vhost, you will be greeted by the message Success!!! Your wordpress.dev looks fine Success!!! Your wordpress.dev looks fine

  • Now add your Vagrant Box IP address to your hosts and map your dev wordpress.dev website to it, for example;

    192.168.50.4 wordpress.dev

    Note. 192.168.50.4 is the default IP address of the Vagrant Box, you can change it to your liking and update the hosts .

    In my case , I put it that way

    • A

      10.10.10.10 wordpress.dev - in the file of my hosts, and

    • B

      config.vm.network "private_network", ip: "10.10.10.10"

      in my vagrantfile.

      You can find these settings by looking inside your Vagrantfile and moving just below this line

      # Host-Only networking required for nfs shares

      Then change the ip: settings and update the hosts so that it matches the IP.

  • Edit Vagrantfile and add your vhost settings to point to the folder of your dev site, add this code block, for example:

     :wordpress => { :name => "wordpress", :host => "wordpress.dev", :aliases => ["wordpress.dev"], :docroot => "/wordpress.dev" } 



    When you added the code to orig Vagrantfile , it should look like this:

      :vhost => { :localhost => { :name => "localhost", :host => "localhost", :aliases => ["localhost.web", "dev.localhost-static.web"], :docroot => "" }, :wordpress => { :name => "wordpress", :host => "wordpress.dev", :aliases => ["wordpress.dev"], :docroot => "/wordpress.dev" } 


    Thus, your Vagrantfile will now look like this; notice the comma , right above w :wordpress and the right to close the braces } .

    There should be a comma when you add another ghost, you must add another comma to the right of the closing brace } wordpress.

      Vagrant.configure("2") do |config| config.vm.box = "precise32" config.vm.box_url = "http://files.vagrantup.com/precise32.box" config.vm.host_name = "localhost" config.vm.provision "chef_solo" do |chef| chef.cookbooks_path = "cookbooks" chef.add_recipe "vagrant_main" ##################################### # MONGODB # https://github.com/edelight/chef-cookbooks ##################################### chef.add_recipe "mongodb::10gen_repo" chef.add_recipe "mongodb::default" ##################################### # REDIS # https://github.com/phlipper/chef-redis ##################################### chef.add_recipe "redis" chef.json.merge!({ :mysql => { :server_root_password => "root", :server_debian_password => "root", :server_repl_password => "root" }, ##################################### # YOU WILL NEED TO ADD THESE DOMAINS # TO THE LIST OF HOSTS IN YOUR LOCAL # ENVIRONMENT FOR THESE TO BE PROPERLY # ROUTED ##################################### :vhost => { :localhost => { :name => "localhost", :host => "localhost", :aliases => ["localhost.web", "dev.localhost-static.web"], :docroot => "" }, :symfony => { :name => "symfony", :host => "symfony.web", :aliases => ["symfony"], :docroot => "/symfony/web" }, :wordpress => { :name => "wordpress", :host => "wordpress.dev", :aliases => ["wordpress"], :docroot => "/wordpress.dev" } } }) end config.vm.network "forwarded_port", guest: 80, host: 8080 config.vm.network "forwarded_port", guest: 3306, host: 3307 ########################################################################## # UNCOMMENT IF NFS IS DISABLED ########################################################################## config.vm.synced_folder "~/Sites", "/vagrant" ########################################################################## # NFS # Enable if you have performance issues with large projects. # see the following links for more info: # http://forum.symfony-project.org/viewtopic.php?t=52241&p=167041#p147056 # http://docs.vagrantup.com/v2/synced-folders/nfs.html # http://www.phase2technology.com/blog/vagrant-and-nfs/ ########################################################################### # Host-Only networking required for nfs shares config.vm.network "private_network", ip: "10.10.10.10" #config.vm.synced_folder "~/Sites", "/vagrant", nfs: true config.vm.provider :virtualbox do |vb| # # Don't boot with headless mode # vb.gui = true # # # Use VBoxManage to customize the VM. For example to change memory: vb.customize ["modifyvm", :id, "--memory", "512"] end end 
  • Now you are ready to start your stray box, open a terminal window

    ctrl + alt + t and type


    cd vagrant-lamp-development to change the directory to the vagrant-lamp-development folder and enter it in


    vagrant up

    so that you can start the Vagrant Box VM and then wait for it to fully load. FIRST INITIAL BOOT UP will be required several times. . After a successful download, open your browser and go to

    http://wordrpress.dev

    You should see a web splash made earlier in Step 3 B.

  • To add new Vhosts , just create a new folder inside /home/your-home-folder/Sites/new-project-folder and then ...

    • Repeat Steps 3B, 4A, 5

    • If you made changes or added Vhosts to your Vagrantfle , and VM Box - Startup , enter ..

      vagrant provision

      in your terminal for the changes to take effect.

    • If you made changes or added vhosts to the Vagrantfile and the VM Box is OFF , enter ...
      vagrant up --provision

      in your terminal for the changes to take effect.

      NOTE. . Vagrantfile used in this guide will download the 64-bit Precise Pangolin Basebox Base Box , you can change it to the 32-bit Precise Pangolin Basebox by changing the configuration from Vagrantfile .

      I did this in my case because I already loaded my 32-bit base box. So I changed it to 32-bit, so I don't need to download again.

      Edit ...

       Vagrant.configure("2") do |config| config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" 


      to

       Vagrant.configure("2") do |config| config.vm.box = "precise32" config.vm.box_url = "http://files.vagrantup.com/precise32.box" 

      DONE!


The other Vagrant LAMP Repos that I tested worked - but do not necessarily support multiple vhosts

Other roaming LAMP repositories

If you want to use the R8 Vagrant-LAMP Repo - for Multi Vhosts purposes

r8 / vagrant-lamp

Here's how to add new vhosts

  • Create a new .json file that matches your desired development site name, for example: wordpress.dev in
    vagrant-lamp/data_bags/sites

    So what it will look like ...
    vagrant-lamp/data_bags/sites/wordpress.json

  • Edit the newly created wordpress.json file and add the following (for example only);

     { "id": "wordpress", "host": "wordpress.dev", "aliases": [ "www.wordpress.dev" ] } 
  • Create a new folder called wordpress.dev inside vagrant-lamp/public
    So it will look ...
    vagrant-lamp/public/wordpress.dev

  • Edit the hosts to add and display 192.168.33.10``wordpress.dev
    So it will look like this ... 192.168.33.10 wordpress.dev

  • And you're good to go ... Run the tramp and enter vagrant up --provision if the window is off
    If the window was turned on during the procedure, enter vagrant provision instead.

  • After that, launch your browser and check your configuration, go to http://wordpress.dev .
    Make sure you put some index files there.

Update: Added a new repository from Github.

Guys, my Linux Mint 13 (Ubuntu 12.04 based) dev box has broken. That's why I had to reinstall my OS (my bad ... using Fake RAID and not have a backup) from scratch. But this time I used Linux Mint 17, based on Ubuntu 14.0.4 LTS.

So, I installed everything again from scratch and quickly set up the Web Dev environment. But it turned out that my previous working setup with a stroller no longer works. So I was looking for a solution on how to set up another web development environment that would work with Ubuntu 14.04 LTS. And, fortunately, I found a working installation using another Github repository called CPT Server

Customization

So this is how you set it up.

  • Clone this repo: cptserver
    Or upload a zip file
  • Find where you cloned or downloaded the repo (extract zip file)
  • Open config / config.yaml and configure as you like. In my case, I did not touch any default configurations, I just added my vhost.
  • Now from your terminal, go to the place where you downloaded or cloned the repo, and vagrant up

What is it! The first download will take a long time.

Adding a new virtual host is easy

Just edit the config / config.yaml file and go to the bottom of most of the file. Find the vhost: line and insert your new virtual host as follows:

  ServerName: mydevsite.dev ServerAlias: mydevsite.dev DocumentRoot: /var/www/mydevsite.dev ServerAdmin: webmaster@localhost 

Then create a new folder inside www and name it according to the ServerName or DocumentRoot mydevsite.dev

If you added a new host while roaming, run it; vagrant provision If you change the top of config.yaml while the firewall is running, do it; vagrant reload --provision

Do not forget to update the hosts file of your host computer, point your vhost to a roaming ip.

So what is it.

+15
source

You can also use this:

 https://github.com/paolooo/vagrant-lamp 

You can check it out.

0
source

All Articles