Installing Laravel & Creating a Project
Setting up your first Laravel project requires PHP 8.2+, Composer, and a database (MySQL, PostgreSQL, or SQLite). Laravel provides two installation methods: the Laravel installer (global CLI tool) and Composer's create-project command. Both produce an identical result. This topic walks you through the complete setup process — from installing prerequisites to running your first Laravel application in the browser.
Prerequisites & Installation
# Step 1: Verify PHP version (8.2+ required)
php -v
# Step 2: Install Composer (if not installed)
# Download from https://getcomposer.org/download/
# Step 3: Create a new Laravel project
composer create-project laravel/laravel my-first-app
# OR using the Laravel installer (faster for repeated use)
composer global require laravel/installer
laravel new my-first-app
# Step 4: Navigate to project directory
cd my-first-app
# Step 5: Start the development server
php artisan serve
# Application running at http://127.0.0.1:8000Laravel Sail — Docker Development Environment
Laravel Sail is a built-in Docker development environment that removes the need to install PHP, MySQL, Redis, or any other software locally. It's the recommended approach for beginners and teams who want consistent environments. Run: curl -s 'https://laravel.build/my-app' | bash to create a new project with Sail. Then cd my-app && ./vendor/bin/sail up to start all services (PHP, MySQL, Redis, Mailpit). Sail maps port 80 so your app is available at http://localhost. Under the hood, Sail uses Docker Compose with pre-configured containers. You can customize which services to include (PostgreSQL instead of MySQL, Meilisearch, MinIO, etc.) by editing the docker-compose.yml file.
Laravel follows the MVC pattern with elegant routing and middleware
Post-Installation Checklist
- Copy .env.example to .env — this file holds your environment-specific configuration (database credentials, API keys, debug mode)
- Generate application key: php artisan key:generate — this sets APP_KEY used for encryption. Without it, sessions and encrypted data won't work
- Configure your database: set DB_CONNECTION, DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD in .env
- Run initial migrations: php artisan migrate — this creates the default tables (users, password_resets, failed_jobs, etc.)
- Visit http://127.0.0.1:8000 — you should see the Laravel welcome page confirming everything works
- Never commit your .env file to version control — it contains secrets. The .gitignore already excludes it by default
Tip
Tip
Practice Installing Laravel Creating a Project in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Practice Task
Note
Practice Task — (1) Write a working example of Installing Laravel Creating a Project from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Installing Laravel Creating a Project is skipping edge case testing — empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready laravel code.
Key Takeaways
- Setting up your first Laravel project requires PHP 8.
- Copy .env.example to .env — this file holds your environment-specific configuration (database credentials, API keys, debug mode)
- Generate application key: php artisan key:generate — this sets APP_KEY used for encryption. Without it, sessions and encrypted data won't work
- Configure your database: set DB_CONNECTION, DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD in .env