Skip to main content
This guide walks you through setting up the Laravel Blog API on your local development environment.

Prerequisites

Before you begin, ensure you have the following installed:
  • PHP ^7.1.3 or higher
  • Composer (PHP dependency manager)
  • MySQL 5.7+ or MariaDB 10.2+
  • Git (for cloning the repository)
You can verify your PHP version by running php -v in your terminal.

Installation steps

1

Clone the repository

Clone the Laravel Blog API repository to your local machine:
git clone <repository-url>
cd laravel-blog-api
2

Install PHP dependencies

Use Composer to install all required dependencies:
composer install
This will install the following key packages:
  • Laravel Framework 5.7.*
  • Firebase PHP JWT 3.0.0
  • Fideloper TrustedProxy
  • Laravel Tinker
3

Create environment file

Copy the example environment file to create your own .env configuration:
cp .env.example .env
The .env file contains all your application’s environment-specific configuration and should never be committed to version control.
4

Generate application key

Generate a unique application encryption key:
php artisan key:generate
This command sets the APP_KEY in your .env file, which is used for encrypting user sessions and other sensitive data.
5

Configure environment variables

Open the .env file and configure your application settings. See the Environment configuration section below for details.
6

Set up storage directories

Create the required storage directories and set proper permissions:
# Create storage symlink for public access
php artisan storage:link

# Set permissions (Linux/macOS)
chmod -R 775 storage bootstrap/cache
The storage and bootstrap/cache directories must be writable by your web server. Improper permissions will cause the application to fail.
7

Configure your database

Create a MySQL database for the application and update your .env file with the database credentials. See the Database migrations guide for detailed instructions.
8

Run database migrations

Execute the migrations to create the database schema:
php artisan migrate
9

Start the development server

Launch the built-in PHP development server:
php artisan serve
Your API will be available at http://localhost:8000

Environment configuration

The .env file contains all environment-specific settings. Here’s a detailed breakdown of each configuration option:

Application settings

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
  • APP_NAME: Your application name (used in notifications and emails)
  • APP_ENV: Current environment (local, staging, or production)
  • APP_KEY: Encryption key (automatically generated by php artisan key:generate)
  • APP_DEBUG: Enable detailed error messages (true for development, false for production)
  • APP_URL: Your application’s base URL

Logging configuration

LOG_CHANNEL=stack
Defines how Laravel handles logging. The stack channel allows you to aggregate multiple log channels.

Database settings

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Update these values to match your local MySQL configuration. The database must exist before running migrations.

Cache and session drivers

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
  • CACHE_DRIVER: Where to store cached data (file, database, redis, memcached)
  • SESSION_DRIVER: Session storage mechanism (file, cookie, database, redis)
  • SESSION_LIFETIME: Session lifetime in minutes
  • QUEUE_CONNECTION: Queue driver (sync for synchronous, database, redis, sqs)

Redis configuration

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
Optional Redis configuration for caching and queues. Leave as default if not using Redis.

Mail settings

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
For local development, use Mailtrap or MailHog to test email functionality without sending real emails.

Broadcasting with Pusher

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
Optional Pusher configuration for real-time broadcasting features. Only required if using WebSocket features.

File permissions

Proper file permissions are critical for Laravel to function correctly:

Linux/macOS

# Storage and cache directories must be writable
chmod -R 775 storage bootstrap/cache

# Ensure your web server user owns the files
sudo chown -R www-data:www-data storage bootstrap/cache

Development with Docker

If using Docker, ensure the container user has write permissions:
chmod -R 777 storage bootstrap/cache
777 permissions should only be used in development environments. Never use 777 in production.

Storage directory structure

The storage directory contains the following subdirectories:
storage/
├── app/           # Application-generated files
├── framework/     # Framework cache, sessions, and views
│   ├── cache/
│   ├── sessions/
│   ├── testing/
│   └── views/
└── logs/          # Application log files
All subdirectories within storage/framework/ must be writable by your web server.

Troubleshooting

”No application encryption key has been specified”

Run php artisan key:generate to generate the APP_KEY.

”Permission denied” errors

Ensure storage directories have proper permissions:
chmod -R 775 storage bootstrap/cache

“Class not found” errors

Regenerate the Composer autoload files:
composer dump-autoload

Database connection errors

Verify your database credentials in .env and ensure the database exists:
mysql -u root -p -e "CREATE DATABASE your_database_name;"

Next steps

Database migrations

Learn about the database schema and how to work with migrations

Deployment

Deploy your API to a production server

Build docs developers (and LLMs) love