{"id":22776,"library":"vite-plugin-php","title":"Vite Plugin PHP","description":"A Vite plugin that enables processing PHP files within Vite's build pipeline, leveraging Vite's fast dev server, HMR, and build tooling for PHP-heavy projects. Currently at v2.0.4, actively maintained with regular bug fixes and performance improvements. Key differentiators: integrates PHP directly into Vite's module graph, supports multiple PHP entry points, provides browser auto-refresh on PHP changes, and works alongside traditional frontend assets. Unlike other solutions, it does not require a separate PHP server during development for asset handling.","status":"active","version":"2.0.4","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/donnikitos/vite-plugin-php","tags":["javascript","vite","vite-plugin","load php","use php","vite php","compile php","php","php-loader","typescript"],"install":[{"cmd":"npm install vite-plugin-php","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-php","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-php","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency to function as a Vite plugin","package":"vite","optional":false}],"imports":[{"note":"Default import only, not named export.","wrong":"import { vitePluginPhp } from 'vite-plugin-php'","symbol":"vitePluginPhp","correct":"import vitePluginPhp from 'vite-plugin-php'"},{"note":"Type import for TypeScript users, available since v2.","wrong":"","symbol":"VitePluginPhpOptions","correct":"import type { VitePluginPhpOptions } from 'vite-plugin-php'"},{"note":"ESM-only; CJS require is not supported.","wrong":"const php = require('vite-plugin-php')","symbol":"php","correct":"import php from 'vite-plugin-php'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport php from 'vite-plugin-php';\n\nexport default defineConfig({\n  plugins: [\n    php({\n      entry: './src/index.php',\n      phpBinary: process.env.PHP_BINARY ?? 'php',\n      server: {\n        port: 3000,\n        strictPort: false\n      }\n    })\n  ]\n});\n\n// index.php - Basic PHP entry point\n<!DOCTYPE html>\n<html>\n<head>\n  <?= vite('src/main.js') ?>\n</head>\n<body>\n  <h1><?= 'Hello from PHP!' ?></h1>\n  <?php\n    $data = ['name' => 'Vite', 'version' => '5'];\n    echo '<p>Data: ' . json_encode($data) . '</p>';\n  ?>\n</body>\n</html>","lang":"typescript","description":"Minimal Vite config with PHP plugin and a PHP entry point showing vite() helper integration."},"warnings":[{"fix":"Update your config: rename phpPath to phpBinary, and adjust nested options per documentation.","message":"v2.0.0 changed the plugin API: options object restructured, phpBinary option renamed from 'phpPath'.","severity":"breaking","affected_versions":">=2.0.0 <2.0.0"},{"fix":"Use import syntax instead of require.","message":"Plugin no longer supports CommonJS requires; only ESM imports are valid.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Set phpBinary explicitly or ensure PHP is in PATH.","message":"PHP binary must be available on the system PATH or specified via phpBinary option; otherwise the plugin fails silently.","severity":"gotcha","affected_versions":"*"},{"fix":"Always use the <?= vite('entry.js') ?> pattern.","message":"The vite() function in PHP files requires the plugin to output the correct asset URLs; does not work with absolute or relative paths manually.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install PHP or set phpBinary in plugin config: php({ phpBinary: '/usr/bin/php' })","cause":"PHP not installed or not in system PATH, and phpBinary option is not set.","error":"Error: The PHP executable could not be found. Please install PHP or set the 'phpBinary' option."},{"fix":"Fix the PHP syntax error. The plugin expects valid PHP code in entry files and files included via vite() helper.","cause":"Syntax error in PHP file that the plugin tries to process.","error":"[plugin:vite-plugin-php] ParseError: syntax error, unexpected '}' in ..."},{"fix":"Change import to: import php from 'vite-plugin-php'","cause":"Incorrect import: used named import instead of default import.","error":"TypeError: php is not a function"},{"fix":"Ensure the PHP file is in the plugin's entry list and the plugin is added to vite.config.","cause":"Vite tried to process a PHP file without the plugin configured correctly, or the file is not included in the plugin's entry.","error":"Module parse failed: Unexpected token (1:0)\nYou may need an appropriate loader to handle this file type."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}