9

for a certain folder on my local Apache-Server (running with Ubuntu) I'd like that all *php-files will be displayed as if they were plain text-files. I need this since I only want to see the source code of these files and NOT run them.

While searching, I found that most people have the opposite problem :-) and couldn't really find a solution for me.

What would I need to include in the .htacces-file of my folder?

THANKS!

1

5 Answers 5

14

THE ANSWER:

in .htaccess-file type

php_flag engine off 
#This will prevent apache from executing *.php-files

AddType text/plain php
#this wil display php-files in browser (if not, browser will want to download file!)

Thanks to Brad!

4
  • Of course, there are as always more than one solution. The above solution saves you having to rename dozens of files. Additionally, it might be good to set the default char-set in the htaccess. THANKS TO ALL WHO HELPED ME IN THIS THREAD!
    – mdthh
    Nov 24, 2010 at 19:28
  • To a nearly 2-year-old answer, thanks! Most other things I saw missed the php_flag engine off part, causing issues.
    – Tarka
    Jul 13, 2012 at 20:18
  • Thanks! (filler filler filler)
    – Rolf
    Jun 12, 2015 at 20:34
  • php_flag engine off -- crashes apache with a syntax error Mar 11, 2022 at 22:58
4

My Godaddy setup wont allow me to edit the httpd.conf files, and the php_flag command doesn't work due to how they've implemented php for me.

I was able to use this in my .htaccess file:

SetHandler default-handler
AddType text/plain php

I put this in the directory above where my FTP user is allowed to access, which forces all PHP files in that directory, as well as all sub-directories to show php as plain text.

This will work for other file types as well. All you need to do is add another line with whatever extension of file you want to be forced to display in plain text. AddType text/plain cgi for example

2

Look at your httpd.conf file for the AddType of .php extension, and change it fortext/plain, and php_flag engine to the offvalue just as sait by Sam Bisbee.

But prefer do these change in the httpd.conf, the .htaccess are useless if you have a dedicated server, and lowing your perfs.

But you can also just change the extensions of your PHP scripts...

0

Two solutions off the top of my head...

  1. Change their file name extensions to .phps. Ex., index.phps.

  2. Change the Content-type for them in the .htaccess file. AddType text/plain .php uses mod_mime to do this. More info at http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addtype

-2

Turn off the the PHP module in apache? (if you won't be needing php execution, of course)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.