PHP Script to Secure the WordPress Folders by Setting Correct File Permissions


The wordpress folders and files should be set the correct permissions. If you have multiple blogs on the same server, you can use the following script to ensure the correct recommended file access permissions are set.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  // define a list of wordpress root folder.
  $wp = array(
    '/var/www/justyy.com/',
    '/var/www/helloacm.com/',
    '/var/www/codingforspeed.com/'
  );
  
  foreach ($wp as $site) {
    echo "Processing $site ...\n";
    chmod($site, 0755);
    chmod($site . 'wp-includes', 0755);
    chmod($site . 'wp-admin', 0755);
    chmod($site . 'wp-admin/js', 0755);
    chmod($site . 'wp-admin', 0755);
    chmod($site . 'wp-content/themes', 0755);
    chmod($site . 'wp-content/plugins', 0755);
    chmod($site . 'wp-content', 0755);
    chmod($site . 'wp-content/uploads', 0755);
    chmod($site . 'wp-config.php', 0444);
    chmod($site . '.htaccess', 0444);
  }
  
  echo "Done.\n";
  // define a list of wordpress root folder.
  $wp = array(
    '/var/www/justyy.com/',
    '/var/www/helloacm.com/',
    '/var/www/codingforspeed.com/'
  );
  
  foreach ($wp as $site) {
    echo "Processing $site ...\n";
    chmod($site, 0755);
    chmod($site . 'wp-includes', 0755);
    chmod($site . 'wp-admin', 0755);
    chmod($site . 'wp-admin/js', 0755);
    chmod($site . 'wp-admin', 0755);
    chmod($site . 'wp-content/themes', 0755);
    chmod($site . 'wp-content/plugins', 0755);
    chmod($site . 'wp-content', 0755);
    chmod($site . 'wp-content/uploads', 0755);
    chmod($site . 'wp-config.php', 0444);
    chmod($site . '.htaccess', 0444);
  }
  
  echo "Done.\n";

Please noted that the PHP chmod function takes the second parameter as the Octal number so you have to use a leading 0 to denote it is a Octal number.

Github

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
219 words
Last Post: How to Add Menu in the WordPress Top Admin Bar?
Next Post: C/C++ Coding Exercise - Nim Game

The Permanent URL is: PHP Script to Secure the WordPress Folders by Setting Correct File Permissions

One Response

Leave a Reply