Forum Moderators: phranque

Message Too Old, No Replies

PHP file without .php extension

can't get apache to process a PHP file without the .php extension

         

csmike

6:22 pm on Jun 13, 2005 (gmt 0)

10+ Year Member



Hello,

I'm moving a client from an old server (setup by another admin who's not available to help) to a new server and am having a problem. One particular section of the site uses a PHP file without an extension, named simply 'send', as follows:

www.example.com/download/send/file_path/filename.exe

On the server, the send file is just in the /download directory and is supposed to take the request, log it to a file, then provide the file in question from the /download/files/ directory for download. I can provide the PHP code if requested, it's short and simple. Problem is, I can't get the new server to do it, I just get a 404. Adding to the problem is that the old server is setup sort of oddly, and I can't for the life of me find the httpd.conf file for this site. I believe the old admin named it something different and he setup the structure of the old server strangely, so I have no idea where it is. However, there is another site on the old server that uses PHP files without extensions, and that site does have an httpd.conf file and he's doing the following to provide for it:

<Location /apply>
ForceType application/x-httpd-php
</Location>

where apply is the PHP file. I've tried the "ForceType application/x-httpd-php" in the Directory section of the httpd.conf file on the new server, with no luck.

Any help would be appreciated. Thanks.

dcrombie

10:46 am on Jun 14, 2005 (gmt 0)



I had the opposite problem a while back:

[webmasterworld.com...]

;)

csmike

10:35 pm on Jun 15, 2005 (gmt 0)

10+ Year Member



Well, I've sort of circumvented that particular problem, but still have a bunch of files on the site that are extensionless, for example:

www.domain.com/confirm

where confirm is a php script in the root directory of www.domain.com. There are about 15 of these extensionless files. Now, the old server's httpd.conf file has the following:

<Location /confirm>
ForceType application/x-httpd-php
</Location>

So, I put this in the httpd.conf file for the appropriate site, and no luck. I get a "do you want to save this file?" dialog box, calling it an unknown file type. I tried changing it to:

<Files confirm>
ForceType application/x-httpd-php
</Files>

And I tried this, as suggested here: [us4.php.net...]

<Files ~ "^[^\.]+$">
ForceType application/x-httpd-php
</Files>

Which gave me the same result. I'm kinda at a loss, as I'm not really an apache/linux expert, just sort of moderately-experienced with them. Anyone have any ideas?

Thanks in advance.

coopster

2:13 pm on Jun 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Did you add the PHP module (LoadModule) in your Apache configuration?

csmike

3:39 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



No, I don't have a LoadModule line for php. The server came pre-configured and ready to run, so Apache and PHP and everything were already setup, and PHP works fine if there's a .php extension on the filename. Anyway, on the LoadModule thing, there are 2 httpd.conf files, a main one and one that's included at the end of the main one. This is in the main one:

<IfDefine vwh_php4_module>
<IfModule sapi_apache2.c>
php_admin_flag safe_mode on
AddType application/x-httpd-php .php .phtml .php4 .php3
</IfModule>
</IfDefine>

And this is in the included one:

<IfModule mod_php4.c>
# Don't allow mod_php
php_admin_flag engine off
</IfModule>
<IfModule sapi_apache2.c>
php_admin_flag engine off
</IfModule>
Action php-script /interpreters/php-script
AddHandler php-script .php .php4 .php3 .phtml

Those are the sections that have to do with PHP. Am I missing something?

Thanks.

coopster

6:12 pm on Jun 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Hard to tell. I guess the first place to start might be your logs. Anything hints showing up there?

csmike

6:20 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



not really, here's what all the entries look like for that particular file:

71.109.164.*** - - [15/Jun/2005:17:42:26 -0500] "GET /confirm HTTP/1.1" 200 6834 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"

Which looks fine, and nothing's showing up in the error log.

coopster

6:26 pm on Jun 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



And what is returned in the browser? Turn up PHP error_reporting() [php.net], too and throw that into the top of your script to see what, if anything, is being reported.

csmike

6:36 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



Unfortunately, nothing is returned to the browser. It's a valid PHP file, if I add a .php to the file it works just fine, so for example, if I add the .php extension and go to:

www.domain.com/confirm.php

it runs just fine. But, if I go to:

www.domain.com/confirm

which is the original filename, I immediately get the "do you want to save this file?" dialog box with choices to save as or cancel, so the browser doesn't return anything, it's like the server still doesn't know it's a php file and is just trying to present the file for download or something.

coopster

7:44 pm on Jun 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Then it is not recognizing the MIME-type. I'm not sure why but try copying this line

AddType application/x-httpd-php .php .phtml .php4 .php3

right below the rest of your other config info, so it looks like this.

<IfModule mod_php4.c> 
# Don't allow mod_php
php_admin_flag engine off
</IfModule>
<IfModule sapi_apache2.c>
php_admin_flag engine off
</IfModule>
Action php-script /interpreters/php-script
AddHandler php-script .php .php4 .php3 .phtml
AddType application/x-httpd-php .php .phtml .php4 .php3

I'm not sure how you are setup there, PHP as module or CGI, etc. But I can tell you that your MIME-type is not being recognized. Don't forget to restart Apache after making the change.

csmike

8:11 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



I added that line and restarted Apache, but it didn't seem to have any effect. I'm running PHP as CGI on this server.

Thanks for your help so far coopster. Any other ideas?

coopster

8:59 pm on Jun 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Not really. I'm not even sure where to point you right now. I know another member had a similar issue once and it was related to the short_open_tag configuration directive but I don't think that is your issue.

[webmasterworld.com...]

It seems something is botching the handling of the MIME-type and I can't quite visualize what it may be. You said you already checked MultiViews out as mentioned in the earlier post, correct?