What To Do With A New Laravel Project

During the process of learning Laravel, I taken up the habit of creating many test applications for new features and ideas. With each new Laravel install, I find myself having to take the time to set up the same thing in each application. This process is becoming tedious as I have to dig through the documentation every time. I decided to document this process to save me some time with each new Laravel install.

This guide was created so I can have quick reference to these steps to save time searching the documentation.

Almost all of this information is found within the Laravel documentation.

#1 Install Laravel

I prefer to use composer’s create-project command when installing Laravel. You can install the Laravel installer globally if you prefer. Either way works just fine.

$ composer create-project --prefer-dist laravel/laravel <application name>

#2 Configure SQLite for local development

This requires two parts; Setting up the local .env database variable and creating a database.sqlite file.

While developing locally, I use php’s built in server via php artisan serve and SQLite for my database. This let’s me get around having to set up a web server and database.

To specify SQLite as the database, open the .env file and set DB_CONNECTION to sqlite. Commenting out the other database fields is also recommended.

# DB_PORT=3306
# DB_DATABASE=homestead
# DB_USERNAME=homestead
# DB_PASSWORD=secret

By default, the sqlite configuration is looking for the non-existant database/database.sqlite file to use with the SQLite driver.

Create a database.sqlite file within the database directory. Now SQLite has a place to store the data.

$ touch database/database.sqlite

#3 Configure SQLite for unit tests

Laravel makes testing incredibly easy out of the box, but I like to tweak the phpunit.xml file to use in-memory SQLite during my tests. It provides some speed and doesn’t require another database to be setup for testing. In fact, I actually recently wrote about this popular trick.

Add a DB_DATABASE environment variable set to :memory: to force the testing instance to use memory when running tests.

    <env name="APP_ENV" value="testing"/>
    <env name="CACHE_DRIVER" value="array"/>
    <env name="SESSION_DRIVER" value="array"/>
    <env name="QUEUE_DRIVER" value="sync"/>
    <env name="DB_DATABASE" value=":memory:"/>

#4 Set up authentication

Laravel comes with a basic authentication system out-of-the-box. It’s simple and easy to use. Setting it up requires just one command.

$ php artisan make:auth

#5 The final step

One final command before starting. Run a quick database migration and you are ready to go.

$ php artisan migrate

Open to new ideas

Have any tips? I am completely open to new ideas and workflows for setting up new Laravel applications.

Published by


Product developer at WPEngine and runner from Hampshire, Illinois. I work with php a lot; Spending most of my time digging into source code to see how it all works. You can find me on Twitter @rfmeier.

Leave a Reply

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