WordPress hardening methods
Block PHP execution in untrusted folders
You need to paste the following code in your .htaccess file.
<Files *.php>
deny from all
</Files>
For openlitespeed
RewriteCond %{REQUEST_URI} ^.*(\/|php)$ [NC]
RewriteRule .* - [F,L]
Disable file editor
in wp-config.php
define( 'DISALLOW_FILE_EDIT', true );
Change security keys
For busniess websites only
Disallow plugin installations
There are occasions when a user or a client might install a plugin without checking its compatibility or credibility, as thoroughly as you may do. This can lead to a number of problems on your website, so it is best to remove the ability for them to do so altogether.
You can disable plugin and theme updates and installations in two ways:
By adding a line of code to your wp_config php file
Follow the same method as detailed in the previous section, you need to add the following line:
define('DISALLOW_FILE_MODS’,true);
Deny access to wp-config.php
Denying access is a much more concrete measure, and if you do this, you won’t have to move the file at all. Go to your .htaccess file and add the following code, right at the top:
<files wp-config.php>
order allow,deny
deny from all
</files>
automation
find /home/*/public_html/ -type d -name "wp-includes" -o -name "wp-admin" -o -name "wp-content" | xargs -I {} cp -v .htaccess "{}"
Here's what this command does step by step:
find /home/*/public_html/ \( -type d -name "wp-includes" -o -path "*/wp-content/uploads" \) | xargs -I {} cp -v .htaccess "{}"
find /home/*/public_html/
: This part of the command starts the search from "/home/*/public_html/".\( -type d -name "wp-includes" -o -path "*/wp-content/uploads" \)
: This condition uses the-type d
flag to search for directories and combines the search for "wp-includes" with the-path "*/wp-content/uploads"
condition, which matches "wp-content/uploads" directories anywhere within the "public_html" directory structure.|
: This is the pipe operator, which takes the output of thefind
command on the left and uses it as input for thexargs
command on the right.xargs -I {} cp -v .htaccess "{}"
: This part of the command takes each directory path found byfind
one at a time and copies the ".htaccess" file from the current directory (where this command is executed) into each of those directories. The{}
is a placeholder that represents the path of each directory found by thefind
command, and-I {}
specifies the placeholder.
With this modified command, it will search for both the "wp-includes" folder and the "wp-content/uploads" folder within "/home/*/public_html/" and copy the ".htaccess" file into each of them.
In this script:
- The
replace_string
no longer starts with a newline character, so it will not add extra newlines. - The
replace_string
directly containsdefine('DISALLOW_FILE_EDIT', true);
.
This should ensure that the define('DISALLOW_FILE_EDIT', true);
line is added without extra newlines in the wp-config.php
files.
Comments
Post a Comment