- Part 1: Walk-through installing and configuring Laravel
- Part 2: Create the core models/tables, controllers, and views
- Part 3: Authorization/Login
- Part 4: Post CRUD
- Part 5: Comment CRUD
- Part 6: Validation
- Part 7: Testing
We are going to install Laravel using Sail. Sail is a robust tool that utilizes Docker to create all of the resources you need to develop with. Among other things it will handle creating containers for MYSQL and Redis while ensuring they can communicate to your laravel web container.
Follow the "Getting Started..." steps on laravel.com for your OS. I'm running Linux so my steps were as follows:
curl -s https://laravel.build/laravel-blog | bash
If you want to call your directory something other than "laravel-blog" you can the URL your request to anything. The utility uses the uri segment as the folder name.
Start it up!
This will take a while to start up the first time as Docker will need to download all of the images it needs to build the containers.
Move into the project directory
.env so that Laravel has a base configuration.
cp .env.example .env
Start the server
# Option 1: If port 80 and 3306 are open on your local machine ./vendor/bin/sail up # Option 2: If port 80 (web) or 3306 (mysql) is in use # on your local machine by something else APP_PORT=6001 FORWARD_DB_PORT=6002 ./vendor/bin/sail up
Generate an application key
The application key is used to encrypt data in Laravel, NOT for password hashing. Cookie values and signed URLs use this to encrypt the data being passed from the front-end to the back-end.
You can change this value after the application is running, however it will invalidate any user sessions and potentially other things utilizing it.
./vendor/bin/sail artisan key:generate
This will update the entry
.env to have something like
Test it out
Load it in a browser http://localhost:6001/
Set up the Database
You'll need a database to store posts, users, and comments in.
Configure Laravel to use the Database
We'll want to add the connection settings to the
docker-compose.yml service name is
mysql, so that is the host name within this docker network to use.
If you used the
FORWARD_DB_PORT=6002 when starting it up, you do not need to put
6002. Outside the Docker network it uses port
6002 to avoid conflicts, but within the docker network it is referenced on port 3306.
DB_HOST=mysql DB_PORT=3306 DB_DATABASE=laravel-db DB_USERNAME=dev-user DB_PASSWORD=password
That's it for now. Part 2 will go through creating models, controllers, and views to get us started down the path of making this into a blog.