0

How can I make php and py in a certain directory display as text?

I am working on a file hosting program, but I need to make php files either download, or display as text.

I haven't been able to find any information on this.

  • [SimpleHTTPServer](https://docs.python.org/2/library/simplehttpserver.html) – M. Leung Jan 25 '18 at 10:42
  • How does this relate to my question? Sorry im a bit confused. – user9148619 Jan 25 '18 at 11:05
  • How is this a PHP or Python question ? How is this a programming question at all actually ? It's all about your HTTP server configuration... You want to post this on a sysadmin site like serverfault. – bruno desthuilliers Jan 25 '18 at 11:42
  • The question is related. The answer to my question will help develop a php supported file hosting system. – user9148619 Jan 25 '18 at 11:49
  • @user9148619 this is __still__ unrelated (and OT here). Your question is not about programming, it's about system configuration, and the fact that you need this system configuration for a program you're writing doesn't change anything to it. – bruno desthuilliers Jan 25 '18 at 12:10

1 Answers1

1

It depend on HTTP server software that you used (nginx, apache, etc)

example for nginx config, just remove block that handle php interpreter:

# remove this lines until end block
--> location ~ [^/]\.php(/|$) {
--> ... Other code
--> }

All php files will displayed as text, if you still need to execute php file on index.php, then you need edit it instead of delete all block, like this:

location = /index.php {
... Other code
}

example for apache server, put on .htaccess file on directory (refer from this answer):

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!)
Mochamad Arifin
  • 418
  • 5
  • 9
  • "Questions on professional server- or networking-related infrastructure administration are off-topic for Stack Overflow unless they directly involve programming or programming tools. You may be able to get help on Server Fault." – bruno desthuilliers Jan 25 '18 at 11:44
  • 1
    The question is related. The answer to my question will help develop a php supported file hosting system. – user9148619 Jan 25 '18 at 11:48
  • 1
    When I run that, I get error 500. When I remove `php_flag engine off`, It gives error 403. when I remove `AddType text/plain php`, I get error 500. – user9148619 Jan 25 '18 at 11:55
  • 1
    try just put `php_flag engine off` – Mochamad Arifin Jan 25 '18 at 11:58
  • 1
    I have. Error 500. – user9148619 Jan 25 '18 at 11:59
  • I repeat : __"Questions on professional server- or networking-related infrastructure administration are off-topic for Stack Overflow unless they directly involve programming or programming tools. You may be able to get help on Server Fault."__ - and there's obviously __nothing__ "directly involving programming or programming tools" here. It's 101% sysadmin stuff. – bruno desthuilliers Jan 25 '18 at 12:11