How to Install Laravel Spark

So you want to setup your own SaaS? Laravel Spark is a fantasic boilerplate to help get you started, but getting started is the hard part. I've personally found that getting it to install correctly first time is somewhat of an art. I've always ran into errors such as: Class 'App\Providers\SparkServiceProvider' not found. Or composer complaining that i don't have the right dependencies and i need to downgrade my version of Cashier etc.

Help on the Internet seems to be lacking and i've had to dig deep to find anything comprehensive. This post aims to solve that.

2020 Update

Having tried to fire up a new Spark install with some new updates, i was STILL running into the SparkServiceProvider not found! It turns out that having everything up-to-date is the problem here. This time around it was my version of Composer. I was running 1.6.3 and the latest at the time of writing is 1.9.2

Updating Composer solved my issue. Instructions on how to do so are below.

Install Laravel Spark

I'm going to reference the Spark Docs a lot here as it does offer great advice, you just need to understand where things go in order to make it all work! So fire the docs up in another tab and let's get started.

Step 1. Install or update Composer

As mentioned above in the 2020 update paragraph, my version of Composer was out of date. The installation will go a lot smoother if you're running the latest version.

Start by removing composer and then re-installing it:

sudo rm -f /usr/local/bin/composer
sudo curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Step 1. Downloading the Laravel Installer

You may or may not have the Laravel installer on your machine, but you should start off here. Even if you do, it's worth doing to make sure you have the latest version. It turns out that i only had v1.4~ and it's currently up to v2+!  No doubt this had something to do with all the errors i was getting.

In your root / home directory (just type cd in your terminal) Running:

composer global require laravel/installer

Should install or update your laravel installer to the latest version.

Step 2. Download the Spark Installer

Still in your home directory, download the Spark Installer:

git clone https://github.com/laravel/spark-installer.git

Next cd into the spark-installer directory and run:

composer install

This will pull in all the dependencies.

Step 3. Add the spark installer to your systems $PATH

This bit catches people out, myself included! I had to Google this one when i first started.

I'm using ZSH for my terminal so i'll be editing my ~/.zshrc file, but if your using the standard terminal, you probably want ~/.bash_profile or ~/.bashrc.

Open up the file in your favourite editor and then at the end of the file add the following:

export PATH=$HOME/spark-installer:$PATH

Assuming you downloaded the spark installer into your home diretory, if not update the path to the file here. Save the file and then source it.

source ~/.zshrc

Step 4. Register your API token

At this point you can just follow the Spark docs. It's also the first time you'll be using the spark command in your terminal. If you can register your API token with no problems, it means you've sucessfully added the spark installer to your systems $PATH. If not, go back into your zshrc or bash_profile and double check the paths to the spark installer. You may also have to close down your terminal and open it back up again for it to pick up the changes.

Step 5. Create a new Spark project

Assuming all has gone well so far, it's time to create your project. cd to the directory of your choice and run:

spark new project-name

This will pull down the latest version of Laravel and then install Spark into the project. With a bit of luck it will all run smoothly!

The problems i faced were that my laravel installer was out of date and the path to the Spark installer was pointing to an old version as well as the wrong folder. Its easy to overlook these things, but also easy to fix!


More Posts

Laravel Queue Delays Not Working

Using Laravel 5.7 queues along with Redis I found that whilst the events were being dispatched and handled by the...