Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mrbungle

macrumors newbie
Original poster
Oct 10, 2011
3
0
I used to be able to view local php files (containing mostly html) in WinXP without a php server installed - it worked in all browser (IE, Firefox, etc.).

Now on my Macbook Air (2011), I keep getting a pop-up prompt in Firefox - and in Safari it displays the source code instead of rendering the page.

How can I preview PHP pages/files on a Mac without a php server installed?
 
You can't. PHP is a server-side language so it must be executed by a server before the output is sent to a browser. A PHP server of some type is required.

I'm not sure what you think you were doing on your Windows machine, but you weren't rendering php files in the browser without a server. PHP just doesn't work that way.

Perhaps you had WAMP installed? You can install MAMP on your Mac.
 
I understand what you mean, but ask any windows user and they'll tell you that you don't need a php server installed to preview html pages (named .php) which contain php code.
 
It's a browser based setting and that's the way it should be, rename it to .html if it doesn't contain php and then it will display correctly.

Also Installing MAMP takes all of 2 min :)

Also you could force the MIME Type to be txt/html for PHP but that seems illogical, should work though.
 
Last edited:
Yes, renaming the file to .html does solve the problem - but it's a inconvenient solution for previewing a whole site (interlinked with .php navigation links).
 
I understand what you mean, but ask any windows user and they'll tell you that you don't need a php server installed to preview html pages (named .php) which contain php code.

I am a Windows user, and I can tell you that what you describe doesn't work. Even if I right-click a php file and choose "open with->Internet Explorer", it gives me a download dialog. So you had something set up in a non-standard way on your Windows machine.

I'll say it again... PHP is a a server-side language. It requires a webserver to parse the code and send the results to your browser. A browser alone cannot do this. This is true for Windows, Mac, Linux, whatever.
 
Yes, renaming the file to .html does solve the problem - but it's a inconvenient solution for previewing a whole site (interlinked with .php navigation links).

Setting the .php mime type for the browser to mirror html will work too as I mentioned.
 
Just install MAMP or XAMPP and be done with it. You'll need it anyway if you want to continue working on those php files right?
 
Setting the .php mime type for the browser to mirror html will work too as I mentioned.

Even if you do this, you will not be able to debug or see if the php code is producing correct results.
 
I understand what you mean, but ask any windows user and they'll tell you that you don't need a php server installed to preview html pages (named .php) which contain php code.

OK, hopefully this will help break the "no you can't / yes you can" thread that's going to start any minute.

What you're got are a bunch of files that end in .php - these files contain a mix of both HTML and PHP code.

Under Windows XP, you were able to open those files up in a browser. The browser *ignored* the PHP embedded in the files and just displayed the HTML.

The people saying "You can't do that!" mean that a browser won't interpret PHP code - you need a PHP-enabled webserver to do that (hence the various calls for you to install MAMP, etc). They're correct in saying you need the server if you want to view the output of your files/code accurately, because otherwise the PHP won't run.

But, if you're just interested in what the embedded html looks like, then yes you are correct - a browser can view the file and ignore the code surrounded by <?php ?> tags.

Now, the reason it isn't working for you is that the browser doesn't recognize your PHP files as containing valid text/html (rightly so - the MIME type is incorrect)... so Safari just displays the source.

As others have suggested, probably the easiest thing to do is set the MIME type for .php files to text/html. If you're using FireFox, there are a number of plugins that allow you to add/edit MIME types.

You may also want to look into text editors with live HTML/PHP preview capabilities. Panic's Coda editor for example (http://www.panic.com) will allow you to open and edit your PHP files with a live preview - and can even run the PHP in your files via a local copy of the PHP interpreter. Code isn't free, but it's a nice package. There are several other editors w/live preview modes out there as well - but you'll have to do some digging, their names escape me at the moment.
 
I'm a huge fan of Coda - probably the best web development software there is (I'd honestly rather use it than Dreamweaver).

If you do plan on just using whatever other software you're using such as Dreamweaver, and want to preview the pages within your browser, I'd recommend either installing PHP/MySQL manually, or installing something such as MAMP, which gives you an Apache, PHP and MySQL server to play with locally.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.