Jump to content

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


Super Sam

Recommended Posts

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?
Link to comment
Share on other sites

Have you set up a web server locally? If you have, you should browse to your php pages a la [b]http://localhost/myfile.php[/b] , 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 [b]file:///c:/file.php[/b], 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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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)
Link to comment
Share on other sites

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:

[code]Error in CGI Application

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

Also, I don't have any MIME types set up on the server for .php.
Link to comment
Share on other sites

  • 3 weeks later...
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?
Link to comment
Share on other sites

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

How you setup Apache to parse php files as a Apache module (which I recommend) or a ScriptAlias (CGI)
Link to comment
Share on other sites

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. :-)
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.