Forum Moderators: phranque

Message Too Old, No Replies

Can't get set up right

index.php request file download

         

martinstan

12:06 pm on Jan 29, 2006 (gmt 0)

10+ Year Member



Hi all
I'm trying to get my laptop setup so I can learn Apache and PHP but I've hit a block straight away which is now becoming very frustrating. I hope someone can help. I'll start from the beginning.
I've installed xp pro, apache 2.0, php 5.1.2.2 and Mysql. I've installed all the software and edited the httpd.conf file in Apache using notepad as follows..

DirectoryIndex index.html index.html.var index.phtml index.php

AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php "/php-exe-location/php.exe"
ScriptAlias /php-exe-location/ "c:/php"

AddType text/plain .txt
AddType application/x-tar .tgz

I've created a folder in htdocs called test and in here I've placed a file called index.php
My problem is when I try to call the index.php file in any browser [localhost:8080...] rather than this file opening I get the following message?you are downloading the file: test from localhost, would you like to open, save,cancel?
If I replace the index.php file with index.html then this opens fine so I think the install has gone OK but there is obviously something wrong with the PHP configuration. I've been trying for days to find an answer to this so that I can get to grips with the difficult stuff. I really hope someone can help.
Thanks
Martin

simon2263

12:40 pm on Jan 29, 2006 (gmt 0)

10+ Year Member



Do you have this directive anywhere in your httpd.conf?

# configure the path to php.ini
PHPIniDir "C:/php5"

(tailored for your own PHP installtion, obviously).

Simon

extras

1:28 pm on Jan 29, 2006 (gmt 0)

10+ Year Member



You should use "Action" in this line.
AddType application/x-httpd-php "/php-exe-location/php.exe"

jdMorgan

2:14 pm on Jan 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It appears that you have explicitly told your server to send a MIME-type which will force a download:

AddType application/x-httpd-php .php

Any file marked with an "application" MIME-type header is downloaded by the browser, which assumes that it's to be executed or handled by a client-side application. If you are using php in the usual way to build html pages for display in the browser, I think you'll be happier with:

AddType text/html .php

There may be some confusion here between AddType [httpd.apache.org], which sets the file's MIME-type header for the browser, and AddHandler [httpd.apache.org], which controls server-side handling (parsing) of .php files.

Jim

martinstan

3:17 pm on Jan 29, 2006 (gmt 0)

10+ Year Member



Superb..I'm doing cartwheels. It works now. I can't tell you how grateful I am for this. It's been bugging me for days and I almost gave up. I've been on a few other forums but no one seemed to be able to nail it. this did the trick
AddType text/html .php

However I'm interested in the other replies too. Simon, do I need this line?
PHPIniDir "C:/php5" as it's not in my code and if I do need it where shall I put it? and 'Extras', I'm not qite sure what you mean by "action"? I'm completely new to all this.
Thanks for all your help. No doubt I'll be back here often
Martin

jdMorgan

3:21 pm on Jan 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you've "spent days on forums," you might save some time with the next problem by going directly here [httpd.apache.org]. :)

Jim

martinstan

3:59 pm on Jan 29, 2006 (gmt 0)

10+ Year Member



Hi Jim
Thanks for the link. yeh it's a great site but I suppose my problem, being so new to this, is that I didn't even know how to even start looking for a solution. I'm doing a PHP tutorial and was just following along..which is kind of worrying as I've already hit this problem so it makes me wonder if the tutorial is any good.It all worked for him...

Thanks
Martin

extras

4:12 pm on Jan 29, 2006 (gmt 0)

10+ Year Member



Oh...they were AddType.
I was reading as AddHandler.

But I'm guessing php is already configured somewhere else (apache2.conf?)
and you don't need any of these, including "AddType text/html .php"

jdMorgan

4:17 pm on Jan 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> [...] didn't even know how to even start looking for a solution.

It's a good practice to look up each of the Apache directives that you use or are told to use. Most of them are 'server configuration directives' and can affect important aspects of your server's operation. So, don't take anybody's word for anything -- dissect their suggested configuration directives or code using the appropriate documentation, and dig until you understand what they're doing. This sometimes takes awhile, but it can prevent disastrous results or side-effects of a pure cut-n-paste approach. (A fair analogy for modifying your server configuration is editing your Windows Registry -- and look at all the warnings you find posted about doing that!)

> It all worked for him.

Possibly because his server was already configured to parse php files and return the correct MIME-type.

Anyway, glad you got it working!

Jim

martinstan

4:28 pm on Jan 29, 2006 (gmt 0)

10+ Year Member



Thanks for the advice...looks like a bit of a mountain at the minute.