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
Install PHP dependencies
Use Composer to install all required dependencies:This will install the following key packages:
- Laravel Framework 5.7.*
- Firebase PHP JWT 3.0.0
- Fideloper TrustedProxy
- Laravel Tinker
Create environment file
Copy the example environment file to create your own
.env configuration:The
.env file contains all your application’s environment-specific configuration and should never be committed to version control.Generate application key
Generate a unique application encryption key:This command sets the
APP_KEY in your .env file, which is used for encrypting user sessions and other sensitive data.Configure environment variables
Open the
.env file and configure your application settings. See the Environment configuration section below for details.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.Environment configuration
The.env file contains all environment-specific settings. Here’s a detailed breakdown of each configuration option:
Application settings
- APP_NAME: Your application name (used in notifications and emails)
- APP_ENV: Current environment (
local,staging, orproduction) - APP_KEY: Encryption key (automatically generated by
php artisan key:generate) - APP_DEBUG: Enable detailed error messages (
truefor development,falsefor production) - APP_URL: Your application’s base URL
Logging configuration
stack channel allows you to aggregate multiple log channels.
Database settings
Update these values to match your local MySQL configuration. The database must exist before running migrations.
Cache and session drivers
- 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 (
syncfor synchronous,database,redis,sqs)
Redis configuration
Mail settings
Broadcasting with Pusher
File permissions
Proper file permissions are critical for Laravel to function correctly:Linux/macOS
Development with Docker
If using Docker, ensure the container user has write permissions:Storage directory structure
Thestorage directory contains the following subdirectories:
All subdirectories within
storage/framework/ must be writable by your web server.Troubleshooting
”No application encryption key has been specified”
Runphp artisan key:generate to generate the APP_KEY.
”Permission denied” errors
Ensure storage directories have proper permissions:“Class not found” errors
Regenerate the Composer autoload files:Database connection errors
Verify your database credentials in.env and ensure the database exists:
Next steps
Database migrations
Learn about the database schema and how to work with migrations
Deployment
Deploy your API to a production server