How to Disable PHP Execution in Certain Directories

From Brian Nelson Ramblings
Revision as of 15:32, 13 May 2018 by Brian (Talk | contribs) (Created page with "===How to Disable PHP Execution in Certain Directories=== Having cleaned numerous WordPress hacks, in my experience most backdoor access files disguise themselves in /wp-incl...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

How to Disable PHP Execution in Certain Directories

Having cleaned numerous WordPress hacks, in my experience most backdoor access files disguise themselves in /wp-includes/ folder or in your /wp-content/uploads/ directory. Usually these are .php files with names that some what seems like WordPress core files, but they are not. One of the measures that you can take to improve your WordPress security is disabling PHP execution in certain WordPress directories. In this article, we will show you how you can use .htaccess file to disable PHP execution in a specific directory.

Create the .htaccess file in the following locations and upload the code below

vim /var/www/html/wp-content/uploads/.htaccess
vim /var/www/html/wp-includes/.htaccess
<Files *.php> 
deny from all
</Files>

Now upload this file in your /wp-content/uploads/ folder. You should also upload it in your /wp-includes/ folder.

Code Explanation: This code checks for any PHP file and denies access to it. This article is in response to one of the Quora questions, a user asked if it was possible to harden your site’s security with .htaccess file. One of the tips we mentioned was disabling PHP execution in the uploads directory.

Note: This is not a FIX for a hack. This is just a security hardening tip.