PHP and Composer .gitignore Configuration
Proper .gitignore for PHP projects using Composer. Covers vendor directory, Laravel and Symfony framework files, environment configs, and IDE metadata.
Detailed Explanation
PHP projects revolve around Composer for dependency management and typically use frameworks like Laravel, Symfony, or WordPress. A well-structured .gitignore keeps vendor code, environment secrets, and framework caches out of version control.
Composer patterns:
vendor/— The Composer dependency directory, equivalent tonode_modules/. Contains all third-party packages and the autoloader. Regenerated bycomposer install.composer.phar— The Composer binary itself if downloaded locally. Use the global installation instead.
Always commit composer.lock for applications. It ensures deterministic installs across all environments. For library packages, some maintainers choose to ignore it (similar to the Rust Cargo.lock convention for library crates).
Laravel-specific patterns:
.env
storage/*.key
storage/framework/cache/*
storage/framework/sessions/*
storage/framework/views/*
bootstrap/cache/*
public/hot
public/storage
.env— Laravel uses dotenv for configuration. The.env.examplefile is committed as a template for new developers.storage/subdirectories — Framework cache, compiled Blade views, and session files. These are runtime artifacts.bootstrap/cache/— Cached configuration and route files generated byphp artisan config:cache.public/hot— Vite/Mix hot-reload indicator file used during local development.
Symfony-specific patterns:
var/
.env.local
.env.*.local
public/bundles/
var/— Symfony stores cache, logs, and sessions in this directory.public/bundles/— Symlinks or copies of bundle assets generated by Symfony.
WordPress patterns:
WordPress is different — the entire application IS in the repository for many deployments. Typically ignore:
wp-content/uploads/— User-uploaded media files.wp-config-local.php— Local database configuration override.wp-content/cache/andwp-content/upgrade/— Cache and update working directories.
Testing and quality tools: Ignore .phpunit.result.cache, .php-cs-fixer.cache, and phpstan.neon.local — these are tool caches that speed up repeat runs but are machine-specific.
Use Case
A Laravel team with frontend assets compiled via Vite needs a .gitignore that handles Composer vendor, compiled assets, environment files, and storage directories.