How To Configure A New Laravel 5.5 Project

by Nick Basile
on Jan 18, 2018

The humble checklist is an incredible tool for quickly and accurately completing tasks that you don't do all of the time. Time and time again, checklists have saved me from making a critical error on some pretty important - and terribly mundane - tasks.

One of my all-time favorite checklists outlines how to set up and configure a new Laravel project. While the documentation does a great job of explaining how to get the ball rolling, there are still several things we need to do before we can really start working.

Without further ado, let's hop right into this checklist and configure a brand new Laravel project.

1. Create a Laravel Project

  • Run laravel new <project-name> from the directory where we want to store our project

2. Create a MySQL Database

  • From the command line, run mysql -uroot -p to log in to MySQL
  • Then, run create database <database-name>; to create the database

3. Update the .env

  • Out-of-the-box, Laravel provides us with an .env file to configure our project, which we'll need to update.
    • APP_NAME=“<app-name>”
    • APP_URL=http://<dev-url>
    • DB_DATABASE=<database-name>
    • DB_USERNAME=root
    • DB_PASSWORD=

4. Set Up Our Testing Environment

  • Think you can skip this? Think again! Just kidding, it's up to you, but I highly recommend it!
  • Inside of phpunit.xml in the root directory of our project, we can add the following lines in the <php></php> block at the bottom
    • <env name="DB_CONNECTION" value="sqlite"/>
    • <env name="DB_DATABASE" value=":memory:"/>

5. Scaffold Authentication

  • In my Laravel project, I use the default auth 99% of the time. If you don't need to, then great! Feel free to skip this step, otherwise continue onward.
  • From the command line, run php artisan make:auth

6. Migrate Database

  • From the command line, run php artisan migrate

7. Initialize Git

  • From the command line, run git init to initialize the project as a git repository
  • Then, run git add . to add all of the project files to the staging area
  • Finally, run git commit -m 'initial commit' to commit these files

8. Add the project to GitLab/GitHub/"Your Platform of Choice"

  • Create a new project on your platform
  • Follow the directions they provide for adding an existing local repository to a new project

9. Install JS Packages

  • From the command line, run yarn or npm install to install your project's initial JavaScript dependencies

10. Update Scss files

  • I like to use .sass files for my custom CSS, so at this point I'll make a few changes to do that. You don't have to this if you don't want to use Sass, but you might have to do some other work to use your CSS preprocessor of choice.
  • Delete _variables.scss file
  • Remove all of the content inside of app.scss
  • Rename app.scss to use .sass
  • Update the reference to app.scss inside of webpack.mix.js

11. Add Any Other Initial Project Dependencies

  • Now we can really start to customize our projects. To start, I'll typically add Tailwind CSS and then get coding.
  • To add Tailwind CSS, follow these steps
    1. From the command line, run yarn add tailwindcss --dev or npm install tailwindcss --save-dev to install the package
    2. Then run, ./node_modules/.bin/tailwind init to generate the config file
    3. Add @tailwind preflight and @tailwind utilities to app.sass in that order
    4. Add let tailwindcss = require('tailwindcss'); to the top of webpack.mix.js
    5. Replace the .sass() portion of the mix code with the following:
.sass('resources/assets/sass/app.sass', 'public/css').options({
    processCssUrls: false, postCss:[ tailwindcss(‘./tailwind.js') ],
});
  1. From the command line, run npm run production to make sure everything is working correctly and to generate your CSS file

12. Start Coding

  • That's it! You're ready to start coding.

The Wrap-Up

I hope this checklist can help you get a new Laravel project up and running, and show you how useful checklists can be. This isn't something that anyone does often, so having this checklist handy prevents us from making obvious mistakes that take time away from actually coding! As always, feel free to ask me any questions on Twitter. And until next time, happy coding!

P.S. Need more help? I offer free 30 minute coaching sessions to help you solve quick problems. For larger projects, I can help you plan, design, or develop the software you need.

A photo of Nick Basile.

Nick Basile

I'm a full-stack developer working with Vue.js, Laravel, and more. In my spare time, I read, tweet, blog, and put together a newsletter.

Never Miss a Beat

Get weekly digests full of design, code, and business articles delivered right to your inbox.