can on a PHP enabled site PHP be disabled on part of the site

Discussion in 'Site & Server Administration' started by hans, Feb 24, 2006.

  1. #1
    as a result of yesterday's hacker attack on my site
    I would like to disable PHP for security reasons in certain folders of my site that otherwise uses PHP and php-SSI in many sections of the site.

    any solution for .htaccess file code to achieve such goal is welcome
     
    hans, Feb 24, 2006 IP
  2. UptimeAgent

    UptimeAgent Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi.

    .htaccess solution if suExec is not enabled:
    <Directory "/desiredfolder">
    php_admin_flag engine off
    </Directory>
    Code (markup):
     
    UptimeAgent, Feb 25, 2006 IP
  3. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #3
    I just tried your suggested solution
    and it caused a site-wide server error
    I am a php-illiterate
    may be I need more help for this problem
     
    hans, Feb 25, 2006 IP
  4. UptimeAgent

    UptimeAgent Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It looks like suExec is enabled on your server.

    You can try the following options:

    1. custom php.ini solution:
    Create a php.ini file in the folder where you would like to disable php and place the following code into it:
    engine 0
    Code (markup):
    Please note that it will work only for the folder where php.ini is. If you will need to disable php for subfolders as well then you will need to place the same php.ini into each subfolder.

    2. another .htaccess solution
    RewriteEngine On
    RewriteRule \.(php|php3)$ /noscripts.html [L]
    Code (markup):
    And place it into the folder of the site section for which you would like to disable php.
    It should work for subfolders as well.
     
    UptimeAgent, Feb 25, 2006 IP
  5. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #5
    got it
    will have to wait until tomorrow to test and observe,

    but the 2nd method seems better since it includes subfolders

    could you explain me the syntax pls so i know what it exactly does
    ( for example the "3" in php3 and the file name: noscripts.html ?)
     
    hans, Feb 25, 2006 IP
  6. UptimeAgent

    UptimeAgent Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    1. "the "3" in php3":
    .php and .php3 are the "default" php extensions. So if someone tries to access php or php3 your .htaccess code will prevent the user from doing that.
    You can add more extensions into the list (for example phtml, PHP, PHP3 (uppercase))

    2. "the file name: noscripts.html"
    That is a page which will be displayed for those who will try to access the php files on your site.
     
    UptimeAgent, Feb 25, 2006 IP
    hans likes this.
  7. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #7
    thanks a lot for your details
    i will test tomorrow and let you know of the hopeful success
     
    hans, Feb 25, 2006 IP
  8. UptimeAgent

    UptimeAgent Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Sure.

    Feel free to ask if you have the additional questions.
     
    UptimeAgent, Feb 25, 2006 IP
  9. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #9
    UptimeAgent

    tks
    I just implemented your proposed mode rewrite solution and it seems to work perfectly after repeated tests :)
    hence I have reopened my 5 forums after a few modifications
     
    hans, Feb 26, 2006 IP
  10. UptimeAgent

    UptimeAgent Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Hi.

    It's nice to hear that :)

    If you will have further questions feel free to ask.
     
    UptimeAgent, Feb 27, 2006 IP