{
    "slug": "gitignore_php",
    "term": ".gitignore for PHP Projects",
    "category": "style",
    "difficulty": "beginner",
    "short": "A well-structured PHP .gitignore excludes vendor/, generated files, IDE configs, .env secrets, and OS artifacts from version control.",
    "long": "A PHP project's .gitignore should exclude: vendor/ (reinstallable via composer install — never commit), .env (contains secrets — commit .env.example instead), .env.local, .env.*.local. Build outputs: /public/build/, /public/hot, /storage/*.key. IDE files: .idea/, .vscode/, *.suo, .DS_Store, Thumbs.db. Cache and logs: /var/cache/, /var/log/, /storage/logs/, /storage/framework/cache/. Test artefacts: .phpunit.result.cache, /coverage/. Generated files: bootstrap/cache/*.php (Laravel), var/ (Symfony). Commit composer.lock (ensures reproducible installs) but not composer.phar. Use a global ~/.gitignore_global for IDE-specific patterns so they don't pollute per-project .gitignore with personal tooling preferences.",
    "aliases": [
        ".gitignore PHP",
        "PHP gitignore",
        "ignore vendor"
    ],
    "tags": [
        "style",
        "git",
        "php",
        "devops"
    ],
    "misconception": "The vendor/ directory can be committed to speed up CI. Committing vendor/ bloats the repository history, causes enormous merge conflicts, and means dependency updates are not tracked semantically. composer.lock achieves reproducibility without committing thousands of dependency files.",
    "why_it_matters": "A proper .gitignore prevents committing sensitive files (.env, credentials), generated files (vendor/, cache/), and IDE metadata — keeping the repository clean and secrets out of version control.",
    "common_mistakes": [
        "Not ignoring .env — database passwords and API keys committed to version control.",
        "Not ignoring vendor/ — bloats the repository; should be installed via composer install.",
        "Not ignoring IDE files (.idea/, .vscode/) — pollutes the repo with developer-specific settings.",
        "Not ignoring generated files (storage/, cache/, *.log) that change constantly and produce noisy diffs."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "composer",
        "editorconfig",
        "changelog",
        "twelve_factor_app"
    ],
    "prerequisites": [
        "configuration_management",
        "developer_experience",
        "docker_multistage"
    ],
    "refs": [
        "https://www.toptal.com/developers/gitignore/api/php,composer,phpstorm"
    ],
    "bad_code": "# Missing .gitignore entries — common PHP mistakes:\n# .env committed with DB_PASSWORD=secret123\n# vendor/ tracked — 50MB of dependencies in git history\n# storage/logs/*.log tracked — log files in version control\n\n# Correct .gitignore:\n.env\nvendor/\nstorage/\n*.log\n.idea/\n.vscode/\n*.cache",
    "good_code": "# .gitignore for PHP projects\n\n# Dependencies\n/vendor/\n\n# Environment\n.env\n.env.local\n.env.*.local\n\n# Build artifacts\n/public/build/\n/public/hot/\n*.phar\n\n# Framework caches\n/bootstrap/cache/\n/storage/\n!/storage/.gitkeep\n\n# IDE\n.idea/\n.vscode/\n*.swp\n\n# OS\n.DS_Store\nThumbs.db\n\n# Test artifacts\n/coverage/\n.phpunit.result.cache\n\n# Logs\n*.log\n\n# NEVER ignore:\n# composer.lock  — always commit this\n# .env.example   — commit template, never the real .env",
    "quick_fix": "Use GitHub's PHP gitignore template as a starting point — the essential rules: /vendor/, .env (never /.env.example), /storage/, /cache/, *.log, .phpunit.cache",
    "severity": "low",
    "effort": "low",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/gitignore_php",
        "html_url": "https://codeclaritylab.com/glossary/gitignore_php",
        "json_url": "https://codeclaritylab.com/glossary/gitignore_php.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[.gitignore for PHP Projects](https://codeclaritylab.com/glossary/gitignore_php) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/gitignore_php"
            }
        }
    }
}