1

I always preview HTML files on my local Firefox before uploading them to production website.

Similarly, I have a ".php" file which is 99% HTML and 1% PHP, and I would like to preview it on Firefox. The PHP code has zero visual impact (statistics & email notifications).

PROBLEM: Firefox does not open the file, it just makes me download it.

How to make Firefox render it?

Creating a symlink f.php.htmlf.php does not even solve the problem... right now I copy and rename the file, which is risky as it might get uploaded if I forget to removed it.

Ubuntu 2014.04, Firefox 29.0


Why not use a PHP test server? I don't want to put the code on a test server, because it would generate erroneous statistics entries and notifications. And also because I have less than 3 minutes for the whole project, so even moving it to /var/www takes too much time. (that's right asking this question took me more than 3 minutes, but I am asking so that I know the trick next time)

5
  • you coud make your server interpret .html files with php, this way you can have .html files with php code in them
    – Gotschi
    May 28, 2014 at 7:35
  • @Gotschi: That's a bit extreme :-) It would mean changing links everywhere, including on servers I don't have access too. May 28, 2014 at 7:36
  • What OS are you working on?
    – Gotschi
    May 28, 2014 at 7:40
  • @Gotschi, sorry added! May 28, 2014 at 7:44
  • Generally you put them in a folder of a web server and access them through that using a URL. Another option is using an IDE that supports preview in browser (it runs the PHP and displays the results in your chosen browser). I have used PhpStorm but there are others.
    – Brian
    May 28, 2014 at 12:47

2 Answers 2

3

This seems to be a long story for many people -> 14 years lasting bug

There are plugins for something like you are looking for, e.g. open in browser. But all of them (as far as I saw) are suitable only for HTTP transfers.

For you (as linux user) the solution can be to make a hardlink ($ ln f.php f.php.html) instead of symlink ($ ln -s f.php f.php.html), for me it seems to trick the browser.

2
  • I am not really sure what the answer in this answer is...? May 28, 2014 at 11:35
  • A hardlink works, but a major drawback is that many text editors break it.
    – Scz
    Jul 12, 2020 at 22:02
0

This is not possible. You cannot render .php file as if it was .html . This is a built in functionality of the browsers and it is there for the reason. If there would be a method to confuse browser into rendering .php files this would result into complete mess. I recommend you to install a local server and do all your tests on the localhost before you upload files onto the production website. This way .php will remain .php and .html will remain .html. What is meant to be rendered will be rendered and what is meant to be interpreted will be interpreted.

If you are encountering the problem when you need to render .php file as if it was .html you should first of all ask yourself that maybe you are doing something wrong and your methods are not the most effective. Having a test server where you can play around with code before publishing it to live server is a very common practice and I recommend it to you.

If you still need to render .php as if it was .html, then renaming the file manually is the right way to do it. And the fact that this method is uncomfortable is there just to remind you that you shouldn't be doing it ))

1
  • First sentence: Yes I can. The PHP code is minimal and has zero graphical impact. Rest of your post: I know it would be better with a test server, but my question asks for a way to avoid that, precisely. Jun 25, 2014 at 5:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .