Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nad27's avatar
Level 4

Spark & Homestead

I've been running a site with Laravel 4.2 for a while. My local development environment is in Homestead running on a iMac. I've got a new project that I want to start with Spark.

I'm struggling to get Spark to install correctly... And I think it boils down to not knowing what to do where (inside the VM vs on the host, iMac, machine). Any pointers?

  • Where should I be installing the spark-installer? (inside homestead vm or on the iMac?)
  • Where should I run "spark new"? (inside homestead vm or on the iMac?)

Somewhat related... Do I need to manually installed the Laravel 5.2 installer in homestead or is it already there? Or if I'm running some of these commands on the iMac...do I need to install the Laravel installer on the iMac?

So far, I've been trying to do everything inside the homestead vm (which is where I thought things should be done). Spark new fails when I try to run the NPM dependencies (errors below). Then gulp won't run (probably due to the npm issue).

Many thanks!

npm ERR! Linux 3.19.0-25-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v5.4.1
npm ERR! npm  v3.3.12
npm ERR! path /home/vagrant/code/test/node_modules/.cli-table.DELETE/node_modules/colors
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename

npm ERR! enoent ENOENT: no such file or directory, rename '/home/vagrant/code/test/node_modules/.cli-table.DELETE/node_modules/colors' -> '/home/vagrant/code/test/node_modules/cli-table/node_modules/colors'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     /home/vagrant/code/test/npm-debug.log

gulp errors:

Would you like to run Gulp? (yes/no) [yes]:
 > y

Running Gulp...
module.js:327
    throw err;
    ^

Error: Cannot find module 'laravel-elixir'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/vagrant/code/test/gulpfile.js:1:76)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
0 likes
11 replies
garethdaine's avatar

Hey,

Install everything locally on your machine, not in Homestead. This includes the Laravel installer.

I would also have your npm modules and gulp stuff run outside of the VM too.

Cheers

nad27's avatar
Level 4

Good info, thanks. I might have been doing things wrong for a while... I needed a nudge in the right direction!

I found this post with some helpful info: https://laracasts.com/discuss/channels/elixir/l5-problem-installing-nodejs-gulp-and-laravel-elixir-on-homestead-20

plus the addition of

npm install -g gulp

I also remove all my old Homestead stuff...vagrant...etc (saved database sql's first for easy recovery). Then a fresh install of vagrant & Homestead (in the process I migrated over to vmware, as well).

Things are looking much better now!

nad27's avatar
Level 4

Install appears clean now, but struggling with a couple things. Is php artisan migrate a command that should run from the host (iMac) or inside the Homestead vm?

When running from the Homestead vm I'm getting

 [Symfony\Component\Debug\Exception\FatalThrowableError]
  Class 'Laravel\Spark\Providers\SparkServiceProvider' not found

When running from the host (iMac) I get a connection error (which I am not surprised by since the default credentials are configured for connected within the vm).

nad27's avatar
Level 4

Took a stab at it... I changed the folder mapping to "nfs" type and that appears to have resolved my latest issue.

nad27's avatar
Level 4

Ok, I'm duplicating my setup on another machine...so I thought I'd take good notes of the process.

Here's my original setup... I've been developing with Laravel 4.2 for a while. Homestead, vagrant, virtual box are all old. I wanted to clean that up (and get more comfortable with the process). So part of my work is removing the old Homestead, vagrant, and virtual box...and installing the latest and greatest Homestead, vagrant, and vmware fusion pro (which I already use for other VMs). So the first few steps might not be needed for everyone, but someone might benefit from it.

Backups

I used Sequel Pro to grab sql dumps for all my databases before wiping out the VMs. I also created backups of the VMs (virtual box) in case I needed to revert. Your call on how much backing up to do in case you need to recover.

Conventions

You’ll see me use the host$ prompt when operating on my host machine (mac) and homestead$ when running a command on my vagrant VM.

Remove Virtual Box

  • host$ sudo rm -rf /Applications/VirtualBox.app/
  • host$ rm -rf ~/VirtualBox\ VMs/

Remove Homestead

  • host$ rm -rf ~/.homestead
  • host$ composer global remove laravel/homestead Note that the current installation instructions don’t reference using composer to install laravel/homestead, so I’m going the currently documented method

Remove vagrant

Reference https://www.vagrantup.com/docs/installation/uninstallation.html

  • host$ rm -rf /Applications/Vagrant
  • host$ rm -f /usr/local/bin/vagrant
  • host$ rm sudo pkgutil --forget com.vagrant.vagrant
  • host$ rm -rf ~/.vagrant.d/

Reboot

I found a reboot was needed here to ensure the VirtualBox network adapters go away

Install VMware Fusion

I took the opportunity here to upgrade to VMware Fusion Pro 8. No detailed steps here.

Install Vagrant

Download from https://www.vagrantup.com/downloads.html and install Install vmware plugin (per instructions that are emailed after purchase of the plugin)

Install Homestead

Pulled mostly from https://laravel.com/docs/5.2/homestead

  • host$ vagrant box add laravel/homestead
  • host$ cd ~
  • host$ git clone https://github.com/laravel/homestead.git Homestead
  • host$ cd Homestead
  • host$ bash init.sh
  • host$ nano ~/.homestead/Homestead.yaml Update provider: vmware_fusion Update the folders section…I found it absolutely necessary to use the nfs type else I had serious errors revolving around symbolic links
folders:
    - map: ~/code
      to: /home/vagrant/code
      type: "nfs"
  • Update the sites section as needed for your applications
  • Update etc/hosts to include entries to 192.168.10.10 pointing to your app names

Install Brew, Node, Bower, Gulp

Many notes taken from here: https://laracasts.com/discuss/channels/elixir/l5-problem-installing-nodejs-gulp-and-laravel-elixir-on-homestead-20

Install Laravel Installer

  • host$ composer global require "laravel/installer"
  • Ensure your host path includes .composer/vendor/bin, such as adding to ~/.bash_profile export PATH="~/.composer/vendor/bin:$PATH"

Update ~/.bash_profile on host

Include the following to create some aliases for common tasks:

# homestead
alias hu="homestead up"
alias hh="homestead halt"
alias hs="homestead ssh"

function homestead() {
    ( cd ~/Homestead && vagrant $* )
}

Fire up vagrant

  • I found I needed to do one more reboot, then…
  • If you sent up the aliases I suggested, run host$ hu.
  • Since we set up NFS, we’re prompted for a sudo password
  • I found that it take another “reboot” of the virtual machine so that the NFS files start syncing so run…
  • host$ hh
  • host$ hu
  • You can verify that NFS is syncing by SSHing (use host$ hs) and see if files are syncing in your code directory

Restore Databases

Use Sequel Pro to restore the sql dumps to the vm

Install Spark on the host

Mostly from https://spark.laravel.com/docs/1.0/installation

Create New Spark Application

  • host$ cd ~/code
  • host$ spark new mycoolapp
  • mycoolapp should match the entry in your /etc/hosts file and the site entry in Homestead.yaml that you modified earlier
  • Ensure that you can run php artisan without errors in vm by…
  • host$ hs
  • homestead$ cd code/mycoolapp
  • homestead$ php artisan
  • You should now be able to browse to mycoolapp.app (or whatever you named in) in your hosts web browser and see the new Spark installation

That’s as far as I’ve gotten for now. I know there’s database stuff, migrations, etc to keep going. I hope it’s easier from here on out. My notes above put together information on what gets executed where (host vs homestead vm) and found an issue where I had to have NFS syncing turned on or else things were really broke.

1 like
garethdaine's avatar

You should run the migrate command in the VM, as it needs to connect to your database.

1 like
thusfar's avatar

So basically everything should be installed locally and then run with Homestead, right?

jmny's avatar

I think you can run composer in either (if installed) but I run all artisan commands on the vm.

garethdaine's avatar

Use composer outside of the VM when possible. You can even run certain artisan commands outside of your VM, as long as they don't rely on database usage.

nad27's avatar
Level 4

One more note... I had an issue where the VM was very sluggish to web requests in a consistent and predictable way. Specifically, the first web request to the vm would encounter a 10 second delay while serving the page. Subsequent requests would be quick (under 1 second load times). If I waited 60 seconds or more to make another page request, I'd be hit with the 10 second delay again.

I had to add to ~/.homestead/Homestead.yaml on the host machine in the folders section this line:

mount_options: ['nolock,vers=3,udp,noatime,actimeo=1']

So here's a full snippet of my folders section in Homestead.yaml:

folders:
    - map: ~/code
      to: /home/vagrant/code
      type: nfs
      mount_options: ['nolock,vers=3,udp,noatime,actimeo=1']

I lost the original article that lead to this discovery...sorry to not give props... The article I found described this has to do with a file sync parameter between the VM and the host that's default at 60 seconds.

Please or to participate in this conversation.