Learn how to set up Laravel, a powerful PHP framework for web development. Start by installing Composer and creating a new Laravel project. Configure your .env
file with database credentials, run migrations, and launch the development server. With just a few commands, your Laravel app will be ready. Perfect for beginners and professionals alike.
Prerequisites
Make sure you have the following installed:
-
PHP ≥ 8.1
-
Composer – PHP dependency manager
-
MySQL / MariaDB – For database
-
Node.js & NPM (for frontend asset compilation)
-
Laravel Installer (optional)
You can check with:
Put this comment in your project terminal:
php -v
composer -V
mysql -V
node -v && npm -v
Step-by-Step Laravel Setup
1. Create a New Laravel Project
You can use either:
Option A: Using Composer
Put this comment in your project terminal:
composer create-project laravel/laravel myApp
cd myApp
Option B: Using Laravel Installer (if installed)
Put this comment in your project terminal:
laravel new myApp
cd myApp
2. Set Up Environment File
Rename .env.example
to .env
(if not done already):
cp .env.example .env
Generate application key:
Put this comment in your project terminal:
php artisan key:generate
3. Configure Database
In .env
file, set your database info:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_password
Make sure the database exists in MySQL.
4. Run Migrations (Optional)
If your project has migrations:
Put this comment in your project terminal:
php artisan migrate
5. Start Development Server
Put this comment in your project terminal:
php artisan serve
Now open:
http://127.0.0.1:8000