I have done this, but instead of PHP, I have used Server Includes, which is a performant and simple way to add repeating headers and footers etc without extra dependecies. Nginx, Apache and Caddy all supports Server Includes, but with different syntax. I have used Caddys templating language, which I am most comfortable with.
It actually works great for slightly more complex stuff to, like converting markdown to HTML etc. Caddys documentation is made using Server Includes for example.