Create a local development environment – Part 2

developmentLast post we’ve setup the basic of our local development environment. If any of the mentioned software is new to you, I recommend reading up a bit on it to get a better feel of what does what exactly.

Since our company uses the Laravel framework, Homestead is the obvious choice for the local development environment. Mind you though, that this is certainly not the only option you have. There are many, many to choose from. Start your search here if you like.

Anyway, let’s set up your first project.

The last command of our previous post, bash init.sh, created the Homestead.yaml file, which we’re using for all our configuration. Let’s set it up like below:

---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
- ~/.ssh/id_rsa

folders:
- map: ~/Code
to: /home/vagrant/code

sites:
- map: projectname.test
to: /home/vagrant/code/projectname/public
php: "7.2"

databases:
- homestead

Now we can provision the box and SSH into it:

$ cd ~/Homestead
$ vagrant up --provision
$ vagrant ssh

Databases

Homestead uses its own database where we can add all our testing databases. When the homestead box is running, add the databases to Sequel Pro:

  • Host: 127.0.0.1
  • Username: homestead
  • Password: secret
  • Port: 33060

Test and login. Add a database in the dev_projectname fashion and import your test or acc database to it. If your don’t have such an environment, you can of course just create a new database.

Note with existing databases: when URLs are hard coded in the database, change them to your local URL like http://projectname.test.

Finally, don’t forget to add these database credentials to the file you normally use to store these, such as .env, db.php, wp-config.php, etc.

Test development environment

Add your site to your hosts file, via terminal, Gas Mask, or whatever:

192.168.10.10 projectname.test

You can now browse to http://projectname.test.

Often the project needs some extra config or modules. From your homestead box:

$ cd /home/vagrant/code/projectname
$ npm install
$ gulp
etc.

It varies per project what you’ll need, but you’ll now of course. Just don’t forget it.

After every edit to your Homestead.yaml you should re-provision your boxes:

$ cd ~/Homestead
$ vagrant halt
$ vagrant up --provision

Surf to http://projectname.test again to see your changes (when applicable).

Complete series: part 1 and part 2. Plus a little addendum.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.