Skip to content

🛠️ Tools & IDE Setup ​

Comprehensive guide to setting up your development environment for optimal Laravel development with automated standards enforcement.

📦 Required Tools Installation ​

PHP & Composer ​

bash
# Ubuntu/Debian
sudo apt update
sudo apt install php8.2 php8.2-cli php8.2-fpm php8.2-mysql php8.2-xml php8.2-mbstring php8.2-curl

# macOS (using Homebrew)
brew install [email protected]
brew install composer

# Verify installation
php --version
composer --version

Node.js & NPM ​

bash
# Ubuntu/Debian
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs

# macOS
brew install node@20

# Verify installation
node --version
npm --version

🔧 Code Quality Tools ​

Installation ​

bash
# Navigate to your Laravel project
cd your-laravel-project

# Install all development dependencies
composer require --dev \
    friendsofphp/php-cs-fixer \
    phpstan/phpstan \
    larastan/larastan \
    laravel/pint \
    barryvdh/laravel-debugbar \
    barryvdh/laravel-ide-helper

# Install Telescope for development
composer require laravel/telescope --dev
php artisan telescope:install
php artisan migrate

PHP CS Fixer Configuration ​

Create .php-cs-fixer.php in project root:

php
<?php

$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__)
    ->exclude(['bootstrap', 'storage', 'vendor', 'node_modules'])
    ->name('*.php')
    ->notName('*.blade.php')
    ->notPath('public')
    ->ignoreDotFiles(true)
    ->ignoreVCS(true);

return (new PhpCsFixer\Config())
    ->setRules([
        '@PSR12' => true,
        'strict_param' => true,
        'array_syntax' => ['syntax' => 'short'],
        'ordered_imports' => ['sort_algorithm' => 'alpha'],
        'no_unused_imports' => true,
        'not_operator_with_successor_space' => true,
        'trailing_comma_in_multiline' => true,
        'phpdoc_scalar' => true,
        'unary_operator_spaces' => true,
        'binary_operator_spaces' => true,
        'blank_line_before_statement' => [
            'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
        ],
        'phpdoc_single_line_var_spacing' => true,
        'phpdoc_var_without_name' => true,
        'class_attributes_separation' => [
            'elements' => [
                'const' => 'one',
                'method' => 'one',
                'property' => 'one',
                'trait_import' => 'none',
            ],
        ],
        'method_argument_space' => [
            'on_multiline' => 'ensure_fully_multiline',
        ],
        'single_trait_insert_per_statement' => true,
    ])
    ->setFinder($finder)
    ->setRiskyAllowed(true)
    ->setUsingCache(true);

PHPStan Configuration ​

Create phpstan.neon in project root:

neon
includes:
    - vendor/larastan/larastan/extension.neon

parameters:
    level: 6
    paths:
        - app
        - config
        - database
        - routes
    excludePaths:
        - app/Console/Kernel.php
        - app/Http/Middleware/TrustProxies.php
        - app/Providers/BroadcastServiceProvider.php
    checkMissingIterableValueType: false
    checkGenericClassInNonGenericObjectType: false
    reportUnmatchedIgnoredErrors: false

Laravel Pint Configuration ​

Create pint.json in project root:

json
{
    "preset": "laravel",
    "rules": {
        "simplified_null_return": true,
        "braces": false,
        "new_with_braces": {
            "anonymous_class": false,
            "named_class": false
        }
    }
}

Package.json Scripts ​

Update package.json:

json
{
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "lint:php": "./vendor/bin/pint",
    "lint:php:test": "./vendor/bin/pint --test",
    "analyze": "./vendor/bin/phpstan analyse",
    "analyze:baseline": "./vendor/bin/phpstan analyse --generate-baseline",
    "test": "php artisan test",
    "test:coverage": "php artisan test --coverage",
    "fix": "npm run lint:php && npm run analyze",
    "ide-helper": "php artisan ide-helper:generate && php artisan ide-helper:models && php artisan ide-helper:meta"
  }
}

💻 VS Code Setup ​

Required Extensions ​

json
// .vscode/extensions.json
{
  "recommendations": [
    "bmewburn.vscode-intelephense-client",
    "MehediDracula.php-namespace-resolver",
    "amiralizadeh9480.laravel-extra-intellisense",
    "onecentlin.laravel-blade",
    "onecentlin.laravel5-snippets",
    "mikestead.dotenv",
    "editorconfig.editorconfig",
    "esbenp.prettier-vscode",
    "dbaeumer.vscode-eslint"
  ]
}

VS Code Settings ​

json
// .vscode/settings.json
{
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll": true,
    "source.organizeImports": true
  },
  "php.suggest.basic": false,
  "php.validate.enable": false,
  "intelephense.telemetry.enabled": false,
  "intelephense.format.enable": true,
  "intelephense.diagnostics.undefinedTypes": false,
  "intelephense.diagnostics.undefinedFunctions": false,
  "intelephense.diagnostics.undefinedConstants": false,
  "intelephense.diagnostics.undefinedMethods": false,
  "intelephense.diagnostics.undefinedProperties": false,
  "[php]": {
    "editor.defaultFormatter": "bmewburn.vscode-intelephense-client",
    "editor.tabSize": 4,
    "editor.insertSpaces": true
  },
  "[blade]": {
    "editor.defaultFormatter": "onecentlin.laravel-blade",
    "editor.tabSize": 4
  },
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "editor.tabSize": 2
  },
  "[json]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "editor.tabSize": 2
  },
  "files.associations": {
    "*.blade.php": "blade"
  },
  "emmet.includeLanguages": {
    "blade": "html"
  },
  "blade.format.enable": true,
  "php.executablePath": "/usr/bin/php",
  "php-cs-fixer.executablePath": "${workspaceFolder}/vendor/bin/php-cs-fixer",
  "php-cs-fixer.onsave": true,
  "php-cs-fixer.config": "${workspaceFolder}/.php-cs-fixer.php"
}

VS Code Tasks ​

json
// .vscode/tasks.json
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Run PHPUnit Tests",
      "type": "shell",
      "command": "php artisan test",
      "group": "test",
      "presentation": {
        "reveal": "always",
        "panel": "new"
      }
    },
    {
      "label": "Run PHPStan Analysis",
      "type": "shell",
      "command": "./vendor/bin/phpstan analyse",
      "group": "build",
      "presentation": {
        "reveal": "always",
        "panel": "new"
      }
    },
    {
      "label": "Fix Code Style",
      "type": "shell",
      "command": "./vendor/bin/pint",
      "group": "build"
    }
  ]
}

VS Code Snippets ​

json
// .vscode/php.code-snippets
{
  "Laravel Controller": {
    "prefix": "lcontroller",
    "body": [
      "<?php",
      "",
      "declare(strict_types=1);",
      "",
      "namespace App\\Http\\Controllers\\Api\\V1;",
      "",
      "use App\\Http\\Controllers\\Controller;",
      "use Illuminate\\Http\\JsonResponse;",
      "",
      "class ${1:Name}Controller extends Controller",
      "{",
      "    public function index(): JsonResponse",
      "    {",
      "        ${0}",
      "    }",
      "}"
    ]
  },
  "Laravel Service": {
    "prefix": "lservice",
    "body": [
      "<?php",
      "",
      "declare(strict_types=1);",
      "",
      "namespace App\\Services;",
      "",
      "class ${1:Name}Service",
      "{",
      "    public function __construct(",
      "        ${2:dependencies}",
      "    ) {}",
      "",
      "    ${0}",
      "}"
    ]
  }
}

🎨 PHPStorm Setup ​

  1. Laravel Idea (Premium but worth it)
  2. PHP Inspections (EA Extended)
  3. PHP Annotations
  4. .env files support
  5. Makefile support

PHPStorm Configuration ​

Code Style ​

  1. Go to Preferences → Editor → Code Style → PHP
  2. Click Set From... → PSR-12
  3. Enable Add a comma after last element in multiline array

PHP CS Fixer Integration ​

  1. Preferences → Tools → External Tools → +
  2. Name: PHP CS Fixer
  3. Program: $ProjectFileDir$/vendor/bin/php-cs-fixer
  4. Arguments: fix $FilePathRelativeToProjectRoot$
  5. Working directory: $ProjectFileDir$

PHPStan Integration ​

  1. Preferences → PHP → Quality Tools → PHPStan
  2. Configuration: $ProjectFileDir$/phpstan.neon
  3. Level: 6

Laravel Plugin Configuration ​

  1. Preferences → PHP → Laravel
  2. Enable Laravel Plugin
  3. Set views path, routes file, etc.

🔗 Git Hooks ​

Pre-commit Hook ​

Create .git/hooks/pre-commit:

bash
#!/bin/bash

echo "Running code quality checks..."

# Get list of PHP files
FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.php$')

if [ -z "$FILES" ]; then
    echo "No PHP files to check"
    exit 0
fi

# Run PHP CS Fixer
echo "Running PHP CS Fixer..."
./vendor/bin/php-cs-fixer fix --dry-run --diff $FILES
if [ $? -ne 0 ]; then
    echo "❌ PHP CS Fixer found issues. Run: ./vendor/bin/pint"
    exit 1
fi

# Run PHPStan
echo "Running PHPStan..."
./vendor/bin/phpstan analyse $FILES --no-progress
if [ $? -ne 0 ]; then
    echo "❌ PHPStan found issues"
    exit 1
fi

# Run tests
echo "Running tests..."
php artisan test
if [ $? -ne 0 ]; then
    echo "❌ Tests failed"
    exit 1
fi

echo "✅ All checks passed!"
exit 0

Make it executable:

bash
chmod +x .git/hooks/pre-commit

Husky Setup (Alternative) ​

bash
npm install --save-dev husky
npx husky install
npx husky add .husky/pre-commit "npm run lint:php:test && php artisan test"

🐳 Docker Setup ​

docker-compose.yml ​

yaml
version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8000:8000"
    volumes:
      - .:/var/www/html
    environment:
      - APP_ENV=local
      - APP_DEBUG=true
    depends_on:
      - mysql
      - redis

  mysql:
    image: mysql:8.0
    environment:
      MYSQL_DATABASE: laravel
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_USER: laravel
      MYSQL_PASSWORD: secret
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql

  redis:
    image: redis:alpine
    ports:
      - "6379:6379"

volumes:
  mysql_data:

Dockerfile ​

dockerfile
FROM php:8.2-fpm

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

# Get Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Set working directory
WORKDIR /var/www/html

# Copy application
COPY . .

# Install dependencies
RUN composer install --no-interaction --optimize-autoloader

# Set permissions
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache

CMD php artisan serve --host=0.0.0.0 --port=8000

📋 Makefile ​

Create Makefile in project root:

makefile
.PHONY: help install dev test lint fix analyze

help: ## Show this help
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

install: ## Install dependencies
	composer install
	npm install
	cp .env.example .env
	php artisan key:generate

dev: ## Start development server
	php artisan serve

test: ## Run tests
	php artisan test

test-coverage: ## Run tests with coverage
	php artisan test --coverage

lint: ## Check code style
	./vendor/bin/pint --test

fix: ## Fix code style
	./vendor/bin/pint

analyze: ## Run static analysis
	./vendor/bin/phpstan analyse

ide-helper: ## Generate IDE helper files
	php artisan ide-helper:generate
	php artisan ide-helper:models
	php artisan ide-helper:meta

fresh: ## Fresh migration with seeding
	php artisan migrate:fresh --seed

optimize: ## Optimize application
	php artisan optimize
	php artisan config:cache
	php artisan route:cache
	php artisan view:cache

clear: ## Clear all caches
	php artisan optimize:clear

✅ Setup Verification ​

Run this checklist: ​

bash
# 1. PHP version
php --version  # Should be 8.2+

# 2. Composer
composer --version

# 3. Node & NPM
node --version
npm --version

# 4. Code quality tools
./vendor/bin/pint --version
./vendor/bin/phpstan --version

# 5. Laravel artisan
php artisan --version

# 6. Run tests
php artisan test

# 7. Check code style
./vendor/bin/pint --test

# 8. Run static analysis
./vendor/bin/phpstan analyse

# 9. IDE helper
php artisan ide-helper:generate

🎓 Team Onboarding Checklist ​

Print this for new team members:

  • [ ] Install PHP 8.2+
  • [ ] Install Composer
  • [ ] Install Node.js 20+
  • [ ] Clone repository
  • [ ] Run composer install
  • [ ] Run npm install
  • [ ] Copy .env.example to .env
  • [ ] Generate app key: php artisan key:generate
  • [ ] Run migrations: php artisan migrate
  • [ ] Install IDE extensions
  • [ ] Configure IDE settings
  • [ ] Run tests to verify setup
  • [ ] Read coding standards documentation
  • [ ] Join team communication channels

🛠️ Keep Tools Updated: Regularly update your development tools and IDE extensions for the best development experience and latest features.

Built with VitePress