Skip to content

Latest commit

 

History

History
65 lines (48 loc) · 1.79 KB

File metadata and controls

65 lines (48 loc) · 1.79 KB
title Running WordPress with FrankenPHP (HTTPS, HTTP/3, hot reload)
description How to run WordPress with FrankenPHP, including a minimal install, a production Caddyfile, and enabling hot reload via Mercure.

WordPress

Run WordPress with FrankenPHP to enjoy a modern, high-performance stack with automatic HTTPS, HTTP/3, and Zstandard compression.

Installing WordPress with FrankenPHP

  1. Download WordPress

  2. Extract the ZIP archive and open a terminal in the extracted directory

  3. Run:

    frankenphp php-server
  4. Go to http://localhost/wp-admin/ and follow the installation instructions

  5. Enjoy!

For a production-ready setup, prefer using frankenphp run with a Caddyfile like this one:

example.com

php_server
encode zstd br gzip
log

Hot reload for WordPress

To use the hot reload feature with WordPress, enable Mercure and add the hot_reload sub-directive to the php_server directive in your Caddyfile:

localhost

mercure {
    anonymous
}

php_server {
    hot_reload
}

Then, add the code needed to load the JavaScript libraries in the functions.php file of your WordPress theme:

// wp-content/themes/<your-theme>/functions.php
function hot_reload() {
    ?>
    <?php if (isset($_SERVER['FRANKENPHP_HOT_RELOAD'])): ?>
        <meta name="frankenphp-hot-reload:url" content="<?=$_SERVER['FRANKENPHP_HOT_RELOAD']?>">
        <script src="proxy.php?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fnpm%2Fidiomorph"></script>
        <script src="proxy.php?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fnpm%2Ffrankenphp-hot-reload%2F%2Besm" type="module"></script>
    <?php endif ?>
    <?php
}
add_action('wp_head', 'hot_reload');

Finally, run frankenphp run from the WordPress root directory.