I have a static HTML site that I want to deploy through Cloudflare Pages.
I heard we can run PHP during build time in Cloudflare Pages and I don’t want to edit the headers/footers of all pages one by one so I made headers.php and footers.php and included them in index.php as below:
Other codes here
It is working well on my local server. But while I try to deploy it to Cloudflare pages - it isn’t working.
I have been googling for many hours but I didn’t find how to do it. Please tell me how I can deploy a static site like this.
You can use PHP to build a static site, but if your site would execute a
It is downloading PHP file when I enter ‘domain.tld/index.php’ and says not found when I enter ‘domain.tld’
You can’t run PHP on the server. You would need to render the output to
index.html rather than
Can you please tell me how can I render the output to index.html? My index.php is as follows. I have HTML codes inside header.php, body-index.php and footer.php
I’m not really sure what the best way to do that in PHP would be, and if you don’t know, you probably should start with a static site generator that’s already written for you. The ones that are supported out of the box on Pages are listed here.
If you want to do the PHP yourself you would probably have to write a script to do it file-by-file and put the output into the build folder. This doesn’t sound fun, but there’s nothing Cloudflare-special about it so whatever you find about generating static HTML files from PHP should work.
Ok, thanks. I might as well use WInHTTRACK to generate copy I guess.