Skip to content


Folders and files

Last commit message
Last commit date

Latest commit



18 Commits

Repository files navigation

a blue Lambourghini with the licence "USEPHP"

🏎️ usePHP 💨

A React hook for running PHP? Why not?

It runs in a Netlify Edge Function and uses php-wasm to execute the PHP. It runs asynchronously, so you need a renderer that supports async components.

View the demo

deploy to netlify


/** @jsx h */
import { h, renderToString } from "";
import { usePHP } from "";

export default async function handler(request: Request) {
  const php = await usePHP(request, h);
  return new Response(
    await renderToString(
          <title>Use PHP</title>
          {await php`
              <?php phpinfo(); ?>
      headers: {
        "content-type": "text/html; charset=UTF-8",

export const config = {
  path: "/*",
  excluded_paths: "/public/*",


usePHP(request: Request, renderer?: JSXRenderer)

Pass in the request object and an optional JSX renderer and it will return tagged template that you can use to execute PHP. If you pass a JSX render function to the hook (e.g. h or React.createElement), then the template will return a JSX element. If you omit the renderer it will return an HTML string instead.

Try it yourself:

deploy to netlify


  • Why?
    • Why not? That Lambo won't buy itself.
  • How can I deploy this to production?
    • 🤦🏻‍♂️


MIT Licence. © 2023 Matt Kane