Setting Up and Configuring a Laravel Development Environment in VS Code

Before writing a single line of Laravel code, your machine needs a few things in place. This guide walks through everything from scratch — PHP, Composer, Laravel itself, and VS Code configuration — so your environment is clean, professional, and ready for real development.


What You Need Before Starting

Tool Purpose
PHP 8.2+ Laravel 11 requires PHP 8.2 minimum
Composer PHP's package manager — installs Laravel and dependencies
VS Code Your editor
XAMPP or standalone PHP Provides PHP and MySQL locally
Node.js + npm For frontend asset compilation (Vite)

Step 1 — PHP Setup

If you have XAMPP, PHP is already installed. Just make sure it's in your PATH as covered earlier. Verify in terminal:

php --version

Expected:

PHP 8.2.x (cli)

If your XAMPP ships with an older PHP version, download a newer standalone PHP from windows.php.net/download and point your PATH to that instead.


Step 2 — Install Composer

Composer is non-negotiable for Laravel. It manages every dependency the framework needs.

Windows

Download and run the installer from:

https://getcomposer.org/Composer-Setup.exe

The installer automatically adds Composer to your PATH.

macOS / Linux

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
sudo mv composer.phar /usr/local/bin/composer

Verify installation:

composer --version
Composer version 2.7.x

Step 3 — Install Laravel

Option A — Via Laravel Installer (Recommended)

composer global require laravel/installer

After installation, create a new project:

laravel new my-project

During setup, Laravel 11 will ask you a few questions:

Which starter kit would you like to install?
> No starter kit

Which testing framework do you prefer?
> Pest

Would you like to initialize a Git repository?
> Yes

For a clean backend-focused setup, choose no starter kit.

Option B — Via Composer Directly

composer create-project laravel/laravel my-project

Both approaches produce the same result. Option A is faster for repeated use.


Step 4 — Open Project in VS Code

cd my-project
code .

Your project structure will look like this:

my-project/
├── app/
│   ├── Http/
│   │   ├── Controllers/
│   │   └── Middleware/
│   └── Models/
├── bootstrap/
├── config/
├── database/
│   ├── migrations/
│   └── seeders/
├── public/
├── resources/
│   ├── views/
│   └── js/
├── routes/
│   ├── web.php
│   └── api.php
├── storage/
├── tests/
├── .env
├── artisan
├── composer.json
└── vite.config.js

Step 5 — Configure the .env File

The .env file controls your entire local environment — database, mail, cache, and more. Open it and configure the database section:

APP_NAME=MyProject
APP_ENV=local
APP_KEY=base64:...
APP_DEBUG=true
APP_URL=http://localhost:8000

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my_project
DB_USERNAME=root
DB_PASSWORD=

For XAMPP, the default MySQL username is root with no password. Create the database manually via phpMyAdmin or terminal:

mysql -u root -e "CREATE DATABASE my_project;"

Step 6 — Run Migrations

Once the database is created and .env is configured:

php artisan migrate
INFO  Running migrations.

  2014_10_12_000000_create_users_table ............. 12ms DONE
  2014_10_12_100000_create_password_reset_tokens_table .. 8ms DONE
  2019_08_19_000000_create_failed_jobs_table ........ 6ms DONE
  2024_01_01_000000_create_cache_table .............. 5ms DONE

Laravel's default migrations are now applied to your database.


Step 7 — Start the Development Server

php artisan serve
INFO  Server running on [http://127.0.0.1:8000].

Open your browser and visit http://127.0.0.1:8000. You should see the Laravel welcome page. Your server is running.


Step 8 — Essential VS Code Extensions

This is where your editor transforms from a basic text editor into a proper Laravel IDE.

Must-Have Extensions

Laravel Extension Pack — installs a curated bundle of Laravel-specific tools in one click:

Publisher: onecentlin
ID: onecentlin.laravel-extension-pack

Or install individually:

Extension Publisher Purpose
Laravel Blade Snippets Winnie Lin Blade syntax highlighting and snippets
Laravel Snippets Winnie Lin PHP/Laravel code snippets
Laravel Artisan Ryan Naddy Run artisan commands from VS Code command palette
Laravel Blade formatter Shuhei Hayashibara Auto-formats Blade files on save
PHP Intelephense Ben Massen PHP intellisense, go-to-definition, type inference
PHP DocBlocker Neil Brayfield Auto-generates PHPDoc blocks
DotENV mikestead Syntax highlighting for .env files
Prettier Prettier Formats JS, CSS, JSON files
GitLens GitKraken Enhanced Git history and blame

PHP Intelephense Setup

After installing Intelephense, disable VS Code's built-in PHP language features to avoid conflicts:

  1. Open Command Palette — Ctrl + Shift + P
  2. Search "Extensions: Show Built-in Extensions"
  3. Find PHP Language Features
  4. Click Disable

Keep PHP Language Basics enabled — it handles syntax coloring. Only disable PHP Language Features since Intelephense handles that better.


Step 9 — VS Code Workspace Settings

Create a .vscode/settings.json file inside your project root:

{
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "editor.tabSize": 4,
    "editor.insertSpaces": true,
    "[php]": {
        "editor.defaultFormatter": "bmewburn.vscode-intelephense-client",
        "editor.formatOnSave": true
    },
    "[blade]": {
        "editor.defaultFormatter": "shufo.vscode-blade-formatter",
        "editor.formatOnSave": true
    },
    "files.associations": {
        "*.blade.php": "blade"
    },
    "intelephense.environment.phpVersion": "8.2.0",
    "intelephense.files.exclude": [
        "**/vendor/**"
    ],
    "emmet.includeLanguages": {
        "blade": "html"
    }
}

This gives you auto-formatting on save for PHP, Blade, and JS files separately, correct file type associations, and Emmet support inside Blade templates.


Step 10 — Configure Xdebug (Optional but Recommended)

Debugging with dd() and var_dump() only gets you so far. Xdebug gives you real breakpoints inside VS Code.

Install Xdebug

For XAMPP on Windows, Xdebug is often already included. Check your php.ini:

php -m | grep xdebug

If not installed, download the correct .dll from xdebug.org/wizard — paste your phpinfo() output and it tells you exactly which file to download.

Configure php.ini

Add to the end of your php.ini (found at C:\xampp\php\php.ini):

[xdebug]
zend_extension=xdebug
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.client_host=127.0.0.1

VS Code Launch Configuration

Create .vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "${workspaceFolder}": "${workspaceFolder}"
            }
        }
    ]
}

Install the PHP Debug extension by Xdebug, press F5 to start listening, then set breakpoints by clicking the gutter next to any line number. When a request hits that code, VS Code pauses execution and lets you inspect every variable in scope.


Step 11 — Frontend Assets With Vite

Laravel 11 uses Vite for frontend asset bundling. Install Node dependencies first:

npm install

Run Vite in development mode (keep this running alongside php artisan serve):

npm run dev

For production builds:

npm run build

You'll typically have two terminals open during development — one running php artisan serve, one running npm run dev.


Daily Development Workflow

Once everything is set up, your typical workflow looks like this:

# Terminal 1 — PHP server
php artisan serve

# Terminal 2 — Vite assets
npm run dev

Common artisan commands you'll use constantly:

php artisan make:model Post -mcr
php artisan make:controller PostController
php artisan make:migration create_posts_table
php artisan migrate
php artisan migrate:rollback
php artisan route:list
php artisan cache:clear
php artisan config:clear
php artisan tinker

VS Code with the Laravel Artisan extension lets you run these from the command palette (Ctrl + Shift + P → "Artisan") without leaving the editor.


The Bottom Line

A proper Laravel setup in VS Code comes down to three layers — the right PHP version and Composer at the system level, a correctly configured .env and database at the project level, and the right extensions and workspace settings at the editor level. Get all three right once and your environment stays out of your way, letting you focus entirely on building.

No comments:

Post a Comment

Interesting Facts About PHP You Must Know

PHP powers a massive chunk of the internet and has been doing so for over three decades. Most developers use it daily without knowing its ba...