Using Local by Flywheel for Local Laravel Development

Note: This post has been updated to work with the new version of Local. I’ll try to keep things updated if the development environment changes in the future. (last updated: March 2, 2022)

While I mostly build with WordPress, I’m going to be working with a few projects coming up that will require a more custom application approach. So, I’m (most likely) going to use Laravel. Step one for any project is to get set up locally. If you’re like me, you like keeping things organized and try to keep things from getting redundant.

For local development, this means using one solution as best I can to make getting setup and going on new projects as simple as possible. While I’ve used ScotchBox, VVV and WP Local Docker before, I’m using Local by Flywheel all the time now. It’s easy to get rolling, consistent for our team to use, and if you want to try out something like Laravel or Craft, you can easily sub those frameworks in. 

Here’s how I’m doing that with Laravel…

Adding a site to Local

First, you set up a site like you normally would on Local:

  1. Click that big “+” button
  2. Give the site a name (let’s say “Laravel”)
  3. Select the environment your want (the Preferred nginx will work just fine with Laravel)
  4.  Enter your WP username and password (these will be deleted shortly)
  5. Click add site.
  6. Once the site is created, update the PHP version to the latest 8.0.x (as of today, Local only goes up to PHP 8.0.0, but hopefully this will be resolved soon).

You can also add in an SSL certificate quickly if you like. Is usually do that, since all websites and apps will be secured when launched to production.

Install Laravel and a New Laravel Project

This step requires that you have Composer installed globally on your system. You can find instructions for that here. Do that first.

Once Composer is installed, you can follow the installation instructions to install Laravel globally as well. Those are found here, but the basic command will be: 

composer global require laravel/installer

Note: You need to run the above command (and all php artisancommands) from the Local machine. Do do this, in the Local app, right click on your new Laravel site, and select “Open Site Shell”. If you change to the laravel/appdirectory, you’ll be able to run these commands.

Once you have Larvel installed globally you can do the following:

  • In Site Shell Terminal, change to the “Laravel” directory you just created (cd ../.. most likely) .
  • Delete the currentapp folder (either in your Finder/Explorer window or via command line)
  • Then run the following command from the new site directory:
laravel new app

This will create a new Laravel project within the app directory, and will include the public folder where Local will normally look for it.

At this point, you should be able to click “View Site” in the Local app, and it should show you the Laravel welcome page at htts://laravel.local, for instance. If you’re getting a 502, 404, or some other error, you may need to restart the server:

Laravel on Local

If you get a minimum PHP version requirement

Temporary fix!: Hopefully I will be deleting this soon, but Local only includes PHP support to 8.0.0, but Laravel’s current dependencies require PHP 8.0.2.

So, on the homepage, if you see a fatal error that says Your Composer dependencies require a PHP version ">= 8.0.2", you can do one of two things:

1. According to the Composer docs here, you should emulate your PHP environment like so in your composer.json file:


{
    "config": {
        "platform":{
            "php":"8.0.2"
        }
    }
}

This adds a spoof to your platform so that even though you’re not really running PHP 8.0.2, it will install dependencies as such.

2. Remove the vendor directory and run:


composer install --ignore-platform-reqs

Obviously, this is a temporary solution to get you going, but once Local has higher PHP 8 support, I’ll remove this. Watch this thread for the latest: https://community.localwp.com/t/add-support-for-php-8-1-in-local/29352/8

Connecting the Database

In your .envfile, you can replace the following credentials (assuming you haven’t changed the default Local by Flywheel settings:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_SOCKET="/Users/yourusername/Library/Application Support/Local/run/somethinglikethis12312123/mysql/mysqld.sock"
DB_DATABASE=local
DB_USERNAME=root
DB_PASSWORD=root

The above will connect to the Local DB. If you open your database using SequelPro, you can go in and delete the standard wp_ tables. 

Finally, you can seed your Laravel database with the command: 

php artisan migrate

After running the above command, you can refresh your database in Table+ or SequelPro and see the default seeded database.

And just like that, you’re off and running with Laravel on Local by Flywheel!