stevenvh
stevenvh

Reputation: 3159

local PHP file doesn't open in browser

I just installed XAMPP on my Windows 7 PC, and wanted to test it with a local PHP file. Double-clicking the file opens a new tab in my browser (Firefox 16.0.1) but the file doesn't open. Instead the tab's label flashes between "connecting" and "new tab" about once per second, and I have a hard time closing the tab again.

I stopped Apache and even ended XAMPP, but no joy. Even reducing the file to the bare minimum doesn't help:

<!DOCTYPE HTML>
<html>
<head>
    <title>php test</title>
</head>
<body>
    Lorem Ipsum...
</body>
</html>

Firefox does open the file if I rename it to a .htm file.

Any ideas what's going on and how to fix it?

Upvotes: 1

Views: 42758

Answers (3)

Seffu
Seffu

Reputation: 11

i spent hours trying to fix this just to realize that the folder hadn't been given permissions...if you're using Linux make sure have.

Upvotes: 0

Havelock
Havelock

Reputation: 6966

You can't just "open" (per double click, as you described) a .php file in your browser. At the very least, because the browser can't interpret PHP.
You need to send a proper (HTTP) request to the server, which will then pass the PHP code to the interpreter, get the results of it and forward it to the browser - in an (for the browser) understandable (e.g. HTML) form over a proper (HTTP) response.

To be able to initially play around with PHP, create an index file (php or html) on which just set links to your .phpfiles, so you can see them in your browser.

Add
Just saw your comment, then you should be able to see the file in your browser, going to http://localhost/your-subfolder/file.php.

The difference: now you're requesting the file through it's URL (http://some.domain/some-file.php) as it usually happens for websites. What you tried first was to open it through it's location on the file system (when you see file:///path/to/some-file.php in the address bar of your browser).

Upvotes: 2

jtheman
jtheman

Reputation: 7491

You cant load the file in browser by doubleclicking in the explorer window, you load it through http protocol:

http://localhost:8080/folder/file.php 

Where - 8080 should be your XAMPP port if not 80 - folder is the subfolder to htdocs if any - file.php is your script

Upvotes: 2

Related Questions