Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple projects with different databases and IP addresses #22

Closed
Dobby89 opened this issue Dec 18, 2014 · 9 comments
Closed

Multiple projects with different databases and IP addresses #22

Dobby89 opened this issue Dec 18, 2014 · 9 comments

Comments

@Dobby89
Copy link

Dobby89 commented Dec 18, 2014

I've installed the box in a directory called mysite and added 192.168.33.10 mysite.dev to my hosts file so I'm now able to see the site by going to http://mysite.dev. Good.

Now what approach is required for me to set up another project directory called another-site using scotchbox and the hosts file setting of 192.168.33.10 another-site.dev? Does scotch box always use the same IP address or can it be changed?

Basically, how do you set up vagrant and/or scotchbox to work on completely separate projects without IP addresses clashing? With that in mind, how would you set up different databases for each project directory or installation of scotchbox?

@Dobby89 Dobby89 changed the title Multiple projects Multiple projects and databases Dec 18, 2014
@Dobby89 Dobby89 changed the title Multiple projects and databases Multiple projects with different databases and IP addresses Dec 18, 2014
@Cethy
Copy link

Cethy commented Dec 19, 2014

The easy way :

    1. clone the scotch-box in another dir ;
    1. edit Vagrantfile, modify this line config.vm.network "private_network", ip: "192.168.33.10" to the ip address you want ;
    1. edit your host file
    1. And ... done. :)

@whatnickcodes
Copy link
Member

Cethy is spot on here. This is exactly how you would do it.

@Dobby89
Copy link
Author

Dobby89 commented Dec 20, 2014

Excellent. That's exactly what I was after. Thank you!

@unclepickles
Copy link

Thanks for that, I used it and it worked, however wouldn't running two vm's be a burden on the PC?
In Homestead you do provisioning and I guess it is a matter of using multiple hosts on the same VM, can't that be done?

@Eoler
Copy link

Eoler commented Jan 19, 2016

It's more a disk space hog (Vagrant can't run two VirtualBox VMs at the same time IIRC).
This branch contains Homestead-like .yaml provisioned multisite fork with automatic hosts handling:
https://github.com/Eoler/scotch-box/tree/multisite

@Cethy
Copy link

Cethy commented Jan 19, 2016

@unclepickles It's totally possible to host multiple hosts on the same VM (like any other machine), it's become a matter of apache/nginx/... configuration. But it was not what @Dobby89 wanted to achieve (good separation of his projects).

To answer your question on burden, VirtualBox is very good at handling multiple VMs (usually 3-4 on my mba'13 with no problem, besides the battery).
But then, you CAN optimize while keeping the separation between services with a project like Docker, but ... yeah, this thing is really scary :)

@unclepickles
Copy link

Thanks everyone for your wonderful responses, ncerminara 's in particular emplying Yaml is superb.
I love this box it makes life much easier, I used to have loads of problems with Homestead.

Wonder if we can discuss adding/upgrading apps in here too? or is this thread specific to the box only?

@unclepickles
Copy link

it's been applied, and it worked, for those who don't know and want a quick explanation it's as follows:
I learnt it from the page in ncerminara's post.
However, here's my setup:

hosts (file)
127.0.0.1 localhost
::1 localhost
192.168.33.10 main.dev
192.168.33.10 lara1.dev
192.168.33.10 lara2.dev
192.168.33.10 gsd.dev
and then the vagrant file:
Vagrant.configure("2") do |config|

config.vm.box = "scotch/box"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.hostname = "scotchbox"
config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]

# Optional NFS. Make sure to remove other synced_folder line too
#config.vm.synced_folder ".", "/var/www", :nfs => { :mount_options => ["dmode=777","fmode=666"] }

 config.vm.provision "shell", inline: <<-SHELL

        ## Only thing you probably really care about is right here
        DOMAINS=("lara1.dev" "lara2.dev", "gsd.dev")

        ## Loop through all sites
        for ((i=0; i < ${#DOMAINS[@]}; i++)); do

            ## Current Domain
            DOMAIN=${DOMAINS[$i]}

            echo "Creating directory for $DOMAIN..."
            mkdir -p /var/www/$DOMAIN/public

            echo "Creating vhost config for $DOMAIN..."
            sudo cp /etc/apache2/sites-available/scotchbox.local.conf /etc/apache2/sites-available/$DOMAIN.conf

            echo "Updating vhost config for $DOMAIN..."
            sudo sed -i s,scotchbox.local,$DOMAIN,g /etc/apache2/sites-available/$DOMAIN.conf
            sudo sed -i s,/var/www/public,/var/www/$DOMAIN/public,g /etc/apache2/sites-available/$DOMAIN.conf

            echo "Enabling $DOMAIN. Will probably tell you to restart Apache..."
            sudo a2ensite $DOMAIN.conf

            echo "So let's restart apache..."
            sudo service apache2 restart

        done

    SHELL

end

when I open lara1.dev I get the right place, and when I open gsd too I can see what I put in there, and the main file (scotchbox itself) that also works, but lara2.dev I get diverted to main, any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants