{"id":14631,"library":"intelephense","title":"Intelephense PHP Language Server (CLI)","description":"Intelephense is a high-performance PHP language server that provides robust IDE features such as code completion, parameter hints, diagnostics, formatting, and symbol navigation. It supports PHP 7 and 8, offering comprehensive static analysis and accurate type inference for modern PHP projects. While widely recognized as a VS Code extension, the `intelephense` npm package specifically distributes the command-line interface (CLI) of the language server. This CLI enables integration with various Language Server Protocol (LSP) clients beyond VS Code or facilitates its use in automated workflows like CI/CD pipelines for linting and diagnostics. Currently at version 1.16.5 on npm, the project is actively developed, ensuring regular updates to support new PHP features and maintain compatibility with evolving editor integrations. Its primary differentiators include its speed, detailed static analysis tailored for PHP, and a rich feature set that significantly enhances PHP development experience.","status":"active","version":"1.16.5","language":"javascript","source_language":"en","source_url":"https://github.com/bmewburn/intelephense-docs","tags":["javascript","php","intellisense","completion","parameters","diagnostics","format","autocomplete","symbols"],"install":[{"cmd":"npm install intelephense","lang":"bash","label":"npm"},{"cmd":"yarn add intelephense","lang":"bash","label":"yarn"},{"cmd":"pnpm add intelephense","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Intelephense is a PHP language server and requires a PHP executable (version 7 or later) to function correctly for analysis.","package":"PHP","optional":false}],"imports":[{"note":"Intelephense is primarily a CLI tool and does not export JavaScript/TypeScript modules for direct import. Its functionality is accessed by spawning its executable.","wrong":"import { intelephense } from 'intelephense';","symbol":"runIntelephense","correct":"import { spawn } from 'node:child_process'; const intelephenseProcess = spawn('intelephense', ['--version'], { stdio: 'inherit' });"},{"note":"To integrate Intelephense diagnostics into a Node.js workflow, execute the `diagnostics` command via `child_process.exec` or `spawn`. Use `--json` for programmatic output.","wrong":"intelephense.diagnostics('/path/to/project');","symbol":"runDiagnostics","correct":"import { exec } from 'node:child_process'; exec('intelephense diagnostics /path/to/project --json', (error, stdout, stderr) => { if (error) console.error(`Error: ${error.message}`); console.log(stdout); });"},{"note":"When installed via npm, the `intelephense` executable is typically located in the `node_modules/.bin/` directory relative to your project root.","wrong":"import { getPath } from 'intelephense';","symbol":"resolveExecutablePath","correct":"import { resolve } from 'node:path'; import { existsSync } from 'node:fs'; const intelephenseBin = resolve(process.cwd(), 'node_modules', '.bin', 'intelephense'); if (existsSync(intelephenseBin)) console.log(`Intelephense executable found at: ${intelephenseBin}`);"}],"quickstart":{"code":"import { execSync } from 'node:child_process';\nimport { writeFileSync, existsSync, mkdirSync } from 'node:fs';\nimport { join } from 'node:path';\n\nconst projectRoot = './tmp_php_project';\nconst phpFilePath = join(projectRoot, 'index.php');\n\nif (!existsSync(projectRoot)) {\n  mkdirSync(projectRoot);\n}\n\n// Create a sample PHP file for diagnostics\nconst phpContent = `<?php\n\nclass MyClass {\n    public function greet(string $name): string {\n        return 'Hello, ' . $name;\n    }\n}\n\n$obj = new MyClass();\n// Missing semicolon here intentionally for diagnostics\necho $obj->greet('World')\n\n// Undefined variable to demonstrate diagnostics\n$undefinedVar = $nonExistentVar;\n`;\n\nwriteFileSync(phpFilePath, phpContent);\n\nconsole.log('Running Intelephense diagnostics on the sample PHP file...');\n\ntry {\n  // Run diagnostics and capture output\n  const output = execSync(`intelephense diagnostics ${projectRoot} --json`, { encoding: 'utf8' });\n  const diagnostics = JSON.parse(output);\n\n  console.log('Intelephense Diagnostics Report:');\n  if (diagnostics.length > 0) {\n    diagnostics.forEach(diag => {\n      console.log(`- [${diag.severity}] ${diag.message} at ${diag.uri}:${diag.range.start.line + 1}:${diag.range.start.character + 1}`);\n    });\n  } else {\n    console.log('No diagnostics reported (might indicate no issues or configuration problem).');\n  }\n} catch (error) {\n  console.error('Failed to run Intelephense diagnostics:', error.message);\n  if (error.stderr) console.error(error.stderr);\n  console.error('Make sure PHP is installed and in your PATH, and intelephense is installed via `npm i -g intelephense` or `npm i intelephense`.');\n}\n\n// Clean up (optional)\n// require('node:fs').rmSync(projectRoot, { recursive: true, force: true });","lang":"typescript","description":"This quickstart demonstrates how to install Intelephense locally, create a sample PHP file, and then programmatically run diagnostics on it using Node.js's `child_process` module to capture and parse the output."},"warnings":[{"fix":"Purchase a premium license from the official Intelephense website (intelephense.com) and configure it in your editor or via the server's configuration files if applicable.","message":"The full feature set of Intelephense (including certain advanced diagnostics, refactoring, and other premium LSP capabilities) requires a paid license. While basic functionality is available, premium features will be locked without a valid license, even when using the CLI.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure PHP (version 7 or higher) is installed on your system and its executable directory is included in your system's PATH environment variable. Verify by running `php -v` in your terminal.","message":"Intelephense requires a PHP executable to be installed and accessible in your system's PATH. If PHP is not found or the version is incompatible, the server will fail to start or provide accurate diagnostics.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Check the Intelephense documentation for recommended stub configurations and ensure the `storagePath` is set to a writable directory for caching and indexing. For VS Code users, these are typically configured in `settings.json`.","message":"Performance issues or incorrect diagnostics can sometimes stem from missing or misconfigured PHP stub files (`intelephense.stubs`) or an incorrect `intelephense.storagePath` pointing to a non-writable directory.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"It is highly recommended to use Intelephense versions 1.0 or higher for stability and modern PHP support. Consult the changelog for specific migration steps if upgrading from pre-1.0 versions.","message":"Prior to version 1.0, some configuration options and command-line arguments might have differed. While the core LSP functionality remained, direct CLI usage and specific settings could require adjustments.","severity":"breaking","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"If installed globally (`npm i -g intelephense`), ensure npm's global bin directory is in your PATH. If installed locally, run `npx intelephense` or add `node_modules/.bin` to your PATH for script execution.","cause":"The Intelephense CLI executable is not in your system's PATH.","error":"command not found: intelephense"},{"fix":"Install PHP (version 7 or later) and verify it's added to your system's PATH. You can test by running `php -v` in your terminal.","cause":"Intelephense could not locate a PHP executable on the system.","error":"No PHP executable found. Please install PHP and add it to your PATH."},{"fix":"Ensure the directory specified by `intelephense.storagePath` (or the default storage location) has write permissions for the user running Intelephense. You might need to change directory permissions or specify a different storage path.","cause":"Intelephense attempts to write to a directory for caching or indexing but lacks the necessary file system permissions.","error":"Error: EACCES: permission denied, open '/path/to/.intelephense/somefile'"},{"fix":"Verify your `intelephense.stubs` setting includes all necessary PHP extensions you are using (e.g., `['php', 'json', 'pcre', 'standard', 'wordpress']`). Ensure your PHP installation and extensions are up-to-date and correctly configured.","cause":"This can be due to an outdated PHP version, incorrect `intelephense.stubs` configuration, or issues with PHP extensions.","error":"Diagnostics for PHP files are inaccurate or not appearing."}],"ecosystem":"npm"}