vite-plugin-php

Use Vite's speed, HMR and ecosystem to build with PHP.


// vite.config.js
import { defineConfig } from 'vite';
import usePHP from 'vite-plugin-php';

export default defineConfig({
plugins: [usePHP()],
});

Vite-powered PHP

Keep writing PHP while Vite handles assets, transforms, environment variables and hot module replacement.

Start building
📐

Flexible configuration

Point to a custom PHP binary, define multiple entry points, rewrite URLs and control PHP error reporting.

Explore options
🌐

Multi-page routing

Use globs to register many PHP pages and let the plugin route requests and build each entry correctly.

See routing
🔌

Pipeline integration

Run additional Vite plugins before or after PHP processing via transformIndexHtml hooks.

Learn the pipeline

What is vite-plugin-php?

vite-plugin-php bridges PHP and Vite. You keep your index.php entry file, server-side logic and includes, while Vite processes scripts, styles, images and environment variables just like it would for a static HTML project.

During development the plugin starts a PHP development server behind the scenes, proxies requests through Vite and streams PHP errors into the Vite console. During production builds it feeds your PHP files through the standard Vite pipeline and writes each entry to the output directory.

Where to go next

  • Get Started — install the plugin and render your first PHP page.
  • Configuration — every option explained with copy-paste snippets.
  • Routing — how entry files map to URLs and build outputs.
  • Vite Pipeline — integrate other plugins before or after PHP.
  • Examples — multi-entry apps, React + PHP, external assets and more.
  • Limitations — things to know about inline modules and dynamic assets.