Localhost developing multiple instances of Vanilla with one set of source code
I have to develop against a lot of different installations of Vanilla. To do this I used to just keep a bunch of config files in my /conf directory and renamed them whenever I wanted to switch to a different installation. This started to become cumbersome and prone to mistakes so I developed a way of automating the process.
What the setup looks like.
I have two setups for localhost development. One setup looks at the current domain and uses a separate config file for that. The other setup uses the vanilla.dev domain where the first folder represents the site. I'm going to describe the second setup because it only has to be configured once and then you'll have an infinite number of localhost sites you can develop against.
In order to set up your localhost you'll have to do three things.
- Add an nginx configuration file that matches the request and sets up appropriate server variables.
- Add a boostrap.before.php file that will choose the appropriate configuration path.
- Add
vanilla.devto your hosts file.
Adding an nginx file.
You'll need to add or modify your nginx file that serves Vanilla in order to make it work with the multisite setup. I've posted the file I use here, but you'll probably have to make some modifications.
- I specify
vanilla.devas my host. You can change this. - I specify
/var/www/vanillaas my document root, but yours might be different. - I specify my php server as
php-fpmand that's defined in another file because I want to be able to reuse it across multiple php installations. The upstream is defined like this:
# PHP upstream
upstream php-fpm {
server 127.0.0.1:9003;
}
Adding the bootstrap.before file.
I've posted the boostrap.before.php that I use here. Put this file in your /conf directory. You shouldn't have to make any modifications, but the code is fairly straightforward so you might want to add features for yourself.
Add vanilla.dev to your hosts file.
Add the following entry to your /etc/hosts file:
127.0.0.1 vanilla.dev
Using the vanilla.dev setup.
Here is how to test to see if your setup is working:
- Browse to
http://vanilla.dev/foo. - You should see the Vanilla setup page. Go ahead and set up Vanilla and see if clicking around works.
- Browse to
http://vanilla.dev/bar. - You should see the Vanilla setup page again. Go ahead and set up Vanilla again and see if it works as a separate installation.
You should now have two separate installations of Vanilla running off the same source code.
Issues
This setup is great, but it's not without issues.
- Although the separate installations use different configuration files they share the same cache and uploads folder. This is usually okay for most localhost development, but may cause issues if you want everything completely separate. It is possible to modify the boostrap.before.php to override every directory though. In the future we may modify core to make overriding just the paths easier.
- You are developing within a subfolder while most hosted Vanilla installations are in the root directory. To me this is actually a feature as it will help you to not add bugs where Vanilla doesn't work properly in a subfolder.
Comments
-
Also note that you cannot be logged on multiple instances at the same time with that setup (Because they are on the same domain).
I broke an ongoing migration because I logged in another instance.0 -
If you want to use subdomains, instead of subdirectories, you can use the following bootstrap.before.php: https://gist.github.com/initvector/b8406b177c1ec4132f5a
You should update your httpd config to pass NODE_SLUG (name of the subdomain) as a $_SERVER var, if possible. E.g.
SetEnvIf Host "^([^\.]*)\.vanillaforums\.dev$" NODE_SLUG=$1
0