LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-24-2017, 09:43 AM   #1
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Disable php everywhere except /index.php


Hello

We have a Laravel project, and a question came up - can we make the public or htdocs folder writable for PHP scripts (www-data)? It's usually denied, but in this project, it would be nice if PHP could write .html and .js files in the public folder. Then those files don't have to go thru the the regular PHP/Laravel routes and will be cached by the browser.

So I thought it could be ok, except I would like to disable PHP execution everywhere except to the root - /index.php. There could be a bug somewhere, and if someone managed to put .php files in the public folder, the server will execute it. So I made this Apache rule:


Code:
<FilesMatch "!(^index\.php$)">
    php_flag engine off
</FilesMatch>
It worked. The project still works (/ or /index.php is executed) and other php files are not. But, when there are subdirectories like /foo or /foo/index.php the php is still executed.

I looked at DirectoryMatch and LocationMatch, but couldn't figure out a rule like that. Any ideas how to solve this?
 
Old 11-24-2017, 04:13 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,174
Blog Entries: 1

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
Hi,

You can use the If directive line this:
Code:
<If "%{REQUEST_URI} !~ m#^/index.php#">
    php_flag engine off
</If>
Using this code, client is prompted to open/save the php file(s) that don't match the condition above.
I personally don't like this approach. I would use mod_rewrite to redirect/forbid visiting any .php file except /index.php

Regards
 
1 members found this post helpful.
Old 11-27-2017, 02:22 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Original Poster
Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Thank you.

I already have some mod_rewrite rules installed by Laravel. But it seems it doesn't redirect if the files exist. Just adding your rule worked, and so does the Laravel project.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache 2.4 on Ubuntu 14 refuses to load index.php even though PHP loads GrowShall Linux - Server 1 11-22-2015 12:06 PM
Apache requires index.php. The requested URL /index.php was not found on this server chefarov Linux - Server 4 07-30-2014 02:29 AM
[SOLVED] PHP: www.domain.com/index.php?page=xxxxx security Snark1994 Linux - Security 3 12-14-2011 08:45 AM
Apache 404 index.php not Found but index.php exists at document root mark84 Linux - Server 20 07-27-2008 01:55 AM
You have chosen to open index.php which is a : PHP Script from: http://localhost cucolin@ Linux - Software 3 01-30-2007 03:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration