Jump to content


Photo

*SOLVED* .php files won't show in browsers


  • Please log in to reply
9 replies to this topic

#1 Super Sam

Super Sam
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 20 February 2006 - 11:39 AM

I'm having a problem with .php files - every time I try to view them in an Internet browser (I've tried Internet Explorer and Firefox), it asks me to download it (with MIME type "application/octec" or similar), rather then viewing it. I can see .php files on the Internet fine, but locally (such as C:/file.php), I'm asked whether I want to download or open the file (choosing to open the file in IE or Firefox results in the download or open message again). I presume this is because my .php associations have been overwritten at some point.

I've created test files (with plain text, HTML code, and PHP code) with .php extensions, and all of them suffer the same problem, whether I access them from my hard drive (C:/), localhost or my IP. Any ideas what the problem could be?

#2 zendak

zendak
  • New Members
  • Pip
  • Newbie
  • 1 posts
  • LocationGermany

Posted 20 February 2006 - 11:50 AM

Have you set up a web server locally? If you have, you should browse to your php pages a la http://localhost/myfile.php , your php will be processed by the server and generate a web poage in the expected manner. Of course, MIME types should be set up properly on the server, and make sure that a PHP interpreter is running :)

If you haven't set up a web server or if you browse to the file like file:///c:/file.php, your operating system will want to know what to do with the file ("open", "save as" etc), as the php is not being processed by the interpreter. That's quite normal.


#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 February 2006 - 07:13 PM

Becuase PHP is a server sided programming language it can only be run on a server. You can run your php scripts locally as zendak mentioned. You need to have a server installed on your computer which you can do for free by getting:
- Apache (the server)
- PHP (the interpretor, the program that parses your php scripts)
- MySQL (optional, if you dont want to use a database).

You can install these manually which is straight forward you can install a package called WAMP or XAMPP both are free.

#4 Super Sam

Super Sam
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 21 February 2006 - 09:03 AM

I have PHP, MySQL and IIS 5.1. It still doesn't work, whether on file:///C:/index.php, [a href=\"http://localhost:444/index.php\" target=\"_blank\"]http://localhost:444/index.php[/a] or http://(ip address):444/index.php. The odd thing is that it used to work a week or so ago, then it just stopped working.

#5 jcavard

jcavard
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 21 February 2006 - 07:09 PM

i would try to download xampp at apachefriends.com or easyPHP.org

and what if you try only [a href=\"http://localhost/index.php?\" target=\"_blank\"]http://localhost/index.php?[/a]? without the port ... also, I think localhost is port 80 (well, at least for me)

#6 Super Sam

Super Sam
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 22 February 2006 - 05:23 AM

I changed the port number back to the default, and now for [a href=\"http://ipaddress/index.php\" target=\"_blank\"]http://ipaddress/index.php[/a] and [a href=\"http://localhost/index.php\" target=\"_blank\"]http://localhost/index.php[/a] it says the following:

Error in CGI Application

The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

Also, I don't have any MIME types set up on the server for .php.

#7 Super Sam

Super Sam
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 10 March 2006 - 02:03 PM

Okay, I've re-installed everything from scratch. I've got the latest version of Apache and PHP installed. Now, when I browse to a php file from localhost (or my IP), it doesn't ask me to download the file, but instead it just displays the code.

[a href=\"http://220.237.65.152/One80%20Wiki/index.php\" target=\"_blank\"]Example Page[/a]

For me, it just shows up as the source code. Does anybody else experience this and/or is there way for me to fix it?

#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 10 March 2006 - 03:13 PM

Have you configured Apache correctly? Ie have added the following line in to the httpd.conf file:
AddType application/x-httpd-php .php

How you setup Apache to parse php files as a Apache module (which I recommend) or a ScriptAlias (CGI)

#9 Super Sam

Super Sam
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 11 March 2006 - 07:47 AM

I did what you said, but now I'm getting the first problem - it asks me to download the file.

Then, in a step I should've done way earlier, I followed the link in your sig to Installing PHP and Apache. The problem is now fixed. (whacks head)

Thanks for everybody who tried to help. :-)

#10 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 11 March 2006 - 08:03 AM

PHP is not a server side programming language, it is a server-side scripting language. A language which can be run by command-line interpreter on the local system without the use of an httpd. All you have to do is configure the system to associate the .php or whatever other extension you want with the php interpreter. I would not recommend this, but it is none the less possible.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users