How to use Hypernode Vagrant as a local staging environment
Table of contents
- 1 What is Vagrant?
- 2 Setting up Vagrant
- 3 Want to use PHP 7 in Vagrant?
- 4 Import your shop in Vagrant
What is Vagrant?
Vagrant is a technique that enables you to set up virtual staging servers locally. Vagrant downloads an image file and uses this “box” file to set up a virtual machine according to the instructions given by the Vagrantfile. It offers you a quick way to boot a staging environment that is configured exactly the same as your live Hypernode.
Setting up Vagrant
The following steps describe how to set up a Hypernode staging environment with Vagrant using the commandline.
Step 1 – Create a local checkout
If you don’t already have a checkout of the Vagrant box or want to start fresh you need to clone the repository from GitHub.
To create a checkout of the hypernode-vagrant repository on your local machine, open your terminal and run the following commands:
git clone https://github.com/ByteInternet/hypernode-vagrant cd hypernode-vagrant
If you already have a checkout, make sure you update to the latest version with the following command:
git pull origin master
Step 2 – Install the dependencies
To get the Vagrant box up and running you need to have some things installed first. You can find these in the README.md of the hypernode-vagrant repository you just cloned, or follow the steps below:
- Install Virtualbox 4.3.18 or later.
- Install Vagrant 1.6.4 or later.
- Install the vagrant-vbguest and vagrant-hostmanager plugins with the following commands:
vagrant plugin install vagrant-vbguest vagrant-hostmanager
Want to use PHP 7 in Vagrant?
If you want to boot a Hypernode Vagrant box running php7 follow the steps below:
Copy the example local.yml if you don’t have one already:
cp local.example.yml local.yml
Open the file in your favorite editor and make sure the PHP version is set to 7.0:
php: version: 7.0
Start the Vagrant with the following command:
Already have a Vagrant set-up in PHP 5.x?
If you’ve previously booted a php 5 version of the hypernode-vagrant box, you need to destroy it first. Note: this deletes all the data in the box.
vagrant destroy -f
When the php 5 version vagrant is destroyed, set up a new one after editing the local.yml (as explained above).
Import your shop in Vagrant
Step 1 – First make sure your SSH-agent is running
To log on to your live Hypernode from the Vagrant Hypernode you’ll need a key. If you don’t already have a keypair, please create one by following the instructions in: Use SSH Keys on Hypernode. Your keypair needs to be stored in an ssh-agent. If you haven’t added your keypair(s) to your agent yet, follow the instructions on how to do so here: Use an SSH-agent.
Step 2 – Start the Vagrant box and log in
Start the Vagrant box with the following command:
Log in with ssh
ssh email@example.com -oStrictHostKeyChecking=no -A
Check if your key is forwarded to your agent with the following command. This command should display the fingerprint of the key you have authorized for your live Hypernode
Step 3 – Copy your shop
Use the hypernode-importer to copy your live shop to your local environment, using the following commands:
hypernode-importer --host APPNAME.hypernode.io --port 22 --user app --path /data/web/public --set-default-url
Depending on the size of your shop, this can take a while.
If all went well, you can now access your shop locally. In your browser go to: https://hypernode.local