Using Local by Flywheel for Local Laravel Development

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.

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

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

  • In Terminal, change to the “Laravel” directory you just created.
  • 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:

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=127.0.0.1
DB_PORT=3306
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

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 SSH”. If you change to the laravel/appdirectory, you’ll be able to run these commands.

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

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

Leave a Reply

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