DevBlog

Coding my way

10 months ago in PHP, Laravel · 2 MIN READ

Using older versions of Laravel Homestead

Recently I had to take time with an old project that used MongoDB as a secondary database for storing abstract data structures like ever changing JSON schemas with a few key elements we could search for.

MongDB is great for stroring abstract data layouts with only a few key componets that can be used identification or easy searching. We stored variable length documents, some were a few Bytes others were 3-5 kB some even reached 30 kB in size.

So the problem was, that the old project uses php 5.6 with the default Mongo driver. Of course this isn't a problem in itself, but if you take it into account that with the coming of php 7 this driver was deprecated with no drop-in replacement. Well it's tougher to migrate... but... So this came to my knowledge through the hard way.

I've checked out the project from git, ran the usual composer and yarn commands, opened http://homestead.app, and BAM: Class 'MongoInt32' not found. Great! Thankfully Google was forthcoming, and I remembered a recent Laravel newsletter article about using older versions of homestead.

This was almost the solution I needed, but there were a few things missing... Of course the knowlegde gained from the artice was invaluable!

We use per project homestead instances, if you installed homestead globally, some problems (like full dev data loss) could occur if you follow through.

First steps

Determine which box you need to use. In my case php 5.6 was a must, so I went with the vagrant box version 0.3.0 for homestead. You can set this in your Homestead.yaml fle, like this:

ip: "192.168.10.10"
memory: 2048
cpus: 1
hostname: old-app
name: old-app
provider: virtualbox
version: 0.3.0

Second step

Get the proper version of homestead into your vendor folder, it's fairly easy to do this in your composer.json file:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
        "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1",
        "laravel/homestead": "2.2.1"
    },
}

As you can see, we used version 2.2.1 of laravel/homestead for this instance.

Be sure to run composer update after editing composer.json!

Third step

All the dependecies and settings are ready to go, so fire up your terminal/console/... go to your project folder and happy vagrant up, a coffee and/or a bed is recommended in case of slow internet speeds.

Fourth step (in case of MongoDB)

Installing MongoDB, is an easy task, thanks to Chris Fidalo's (a.k.a. fideloper) Vaprobash scripts. Just 1 command will install, configure and start MongoDB for you:

sudo curl -sS https://raw.githubusercontent.com/fideloper/Vaprobash/master/scripts/mongodb.sh | sudo sh

You just need to be patient, even if it seems to hang for a while...

···

Miklós Galicz

I'm a hobbyist who managed to become a professional web developer who specializes in Laravel and Vue.js, also the Spice must flow.
comments powered by Disqus


© 2017 DevBlog