Search code examples
phpfirebasefirebase-hosting

Is there a way to serve a .php file as html on Firebase hosting?


I'm trying to convert an existing PHP site to static hosting on Firebase, so I fetched the whole site as HTML files and deployed to firebase hosting.

All download files got the orignal name, so, for example, the files.php page was downloaded into the files.php file, but it contains the rendered HTML, not PHP code, so it's a HTML file.

The problem is when I try to open the /files.php url on my firebase hosted site then it does not show the HTML, the browser offers me to download the file instead.

Why is that? Firebase hosting does not support PHP, so why does it care if the url ends with .php? Why doesn't it render the HTML in it?


Solution

  • .php is not a normal extension for HTML content, and Firebase Hosting is probably not telling the browser that the content is HTML to display in the browser. You could try configuring Firebase Hosting to do exactly that, though. You will want the response to say that the file has the content type "text/html" by setting the header, as described in the documentation for firebase.json configuration.

    "hosting": {
      "headers": [ {
        "source": "*.php",
        "headers": [ {
          "key": "Content-Type",
          "value": "text/html"
        } ]
      ] }
    }