logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: execute index.php but not other .php
Author
jwzumwalt



Joined: 25 Sep 2012
Posts: 4
Location: usa

PostPosted: Tue 25 Sep '12 18:19    Post subject: execute index.php but not other .php Reply with quote

I have a section on my server with public php snippets.
I would like to have index.php execute but not other
php files. I have attempted to set Unix file permissions
but since php files are read only 644 anyway this is
not the solution. I have tried various combinations of
the .htaccess settings shown here and get four different
results.

1) all php files are download
2) all php files are forbidden
3) all php files execute
4) index executes but other php files are forbidden


What I am hoping for is to have all but index.php
shown as a text file. Thanks for the help

<FilesMatch "\.(htm|html|php)$">
SetHandler application/x-httpd-php
</FilesMatch>


<FilesMatch "\.php$">
Order Allow,Deny
Deny from all
</FilesMatch>


<FilesMatch "index\.php$">
Order Allow,Deny
Allow from all
</FilesMatch>
Back to top
BLuFeNiX



Joined: 21 Sep 2012
Posts: 4

PostPosted: Tue 25 Sep '12 21:49    Post subject: Re: execute index.php but not other .php Reply with quote

jwzumwalt wrote:

<FilesMatch "\.php$">
Order Allow,Deny
Deny from all
</FilesMatch>


I'm not an expert with apache, but it looks like this might be your issue. Remove this block of code and try it again.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Wed 26 Sep '12 9:57    Post subject: Reply with quote

remove the three blocks above

short and way simpler.

Code:

<IfModule mod_mime.c>
   <Files "index.php">
      AddHandler application/x-httpd-php .php
   </Files>
</IfModule>


The thing is that php files are not executed with mod_php. An interpreter just parses the files. It is not like cgi.
Back to top
jwzumwalt



Joined: 25 Sep 2012
Posts: 4
Location: usa

PostPosted: Thu 27 Sep '12 3:31    Post subject: Reply with quote

Thanks for trying to help. After trying this, all php files were downloaded including index.php Sad
Back to top
VoodooMill



Joined: 11 Jan 2007
Posts: 60

PostPosted: Thu 27 Sep '12 16:50    Post subject: Reply with quote

Hello,

I was able to get James' configuration working in both the server config and htaccess file. However, to make it work with htaccess I had to 'AllowOverride All' and comment out AddType application/x-httpd-php .php in the Apache config file.
Back to top
jwzumwalt



Joined: 25 Sep 2012
Posts: 4
Location: usa

PostPosted: Sun 30 Sep '12 1:45    Post subject: Reply with quote

Would you be so king as to provide a complete copy of your config file?
Thx
Back to top
jwzumwalt



Joined: 25 Sep 2012
Posts: 4
Location: usa

PostPosted: Tue 02 Oct '12 15:16    Post subject: SOULTION-FOUND! Reply with quote

Thanks for all the help, everyone.

The solution to my problem was given by Pr0t0n. I received the following message from another message board I posted this to...

http://forums.digitalpoint.com/showthread.php?t=2562761#post18070811

I'm not sure what you exactly wanted AFTER not allowing php files to run, to run a download on those scripts and have the visitor download each php/html except index.php file, OR actually just forbid the execution. So here are both options.

To have index.php execute on the server, and all other php and html files download to client browser:

Code:
---------
<FilesMatch "\b(?!.*index\.php$)(.+)\.(htm|html|php|php4|php5)$">
SetHandler application/octet-stream
</FilesMatch>
---------
To have index.php execute, and all other php files return "403 Forbidden":

Code:
---------
<FilesMatch "\.(php|php4|php5)$">
Order Allow,Deny
Deny from all
</FilesMatch>
<FilesMatch "index\.php$">
Order Allow,Deny
Allow from all
</FilesMatch>
---------
Some further testing should be applied to both snippets... but I believe it should be working fine.

Cheers!
***************
Back to top
VoodooMill



Joined: 11 Jan 2007
Posts: 60

PostPosted: Tue 02 Oct '12 17:06    Post subject: Re: SOULTION-FOUND! Reply with quote

Excellent! Sorry I didn't get back sooner on your request for the config contents but it's been a crazy few days with upgrade testing, etc.
Back to top


Reply to topic   Topic: execute index.php but not other .php View previous topic :: View next topic
Post new topic   Forum Index -> Apache