Choose a plan

File permissions: 644, 755 and what you never set

What 644 and 755 mean, why 777 is an invitation to attackers, how to protect wp-config.php and how to block PHP in the images folder.

  • Updated
guide · security
Steps
12
Reading time
5min
Sections
6
Start the guide

Every file and folder on the server has three digits that say who can read, change or run it. With the right digits, the website works and an attacker has less room to move. With the wrong ones, either the website shows “403 Forbidden”, or any script can overwrite your files.

What you'll achieve

  • understand what 644, 755 and 777 mean;
  • check and fix permissions from Enhance;
  • protect wp-config.php and the image folder of a WordPress website.

What the numbers mean

The three digits are, in order, for the owner (your website's user), the group and others. Each digit is a sum: 4 = read, 2 = write, 1 = execute (for folders: enter the folder).

DigitsUsed forWhat it means
644filesyou read and write; everyone else can only read
755foldersyou enter, read and write; everyone else can enter and read
640 or 600files with passwords, for example wp-config.phponly you (and the group, with 640) can read them
777—anyone can read, write and execute. Never use it

On NBT Host, files uploaded from Enhance or via FTP usually get 644 and 755 automatically. Problems appear after a plugin that changes permissions, after an archive extracted from another server, or after the “set it to 777 and it works” advice found on a forum.

Before you start

  • Back up the website: in Enhance, on the website page, the “Backups” tab » “Create backup” (with the language set to “English (US)”, “Backup now”).
  • We use the English names from the Enhance interface, exactly as they appear on screen. If the panel opens in another language, switch it to English from the top right: “My account” » “Language”.

The steps

A. Check the permissions

  1. In Enhance, open “Websites”, then the website and the “Files” tab.
  2. Right-click a file or folder » “Get info”: you see the permissions, the owner and the modification date.
  3. Check especially public_html, wp-config.php, .htaccess and the wp-content and wp-content/uploads folders.

B. Fix the permissions

  1. Right-click the file or folder » “Permissions (CHMOD)”.
  2. Set 644 for files and 755 for folders.
  3. For a folder, check “Apply recursively” only if you know that everything in it should have the same digits. Don't apply 755 recursively to a folder with files: the files would get execute permission for no reason.
  4. Open the website and check that it works.

C. Protect wp-config.php

wp-config.php holds the database password and the WordPress security keys.

  1. Set its permissions to 640. Open the website: if it works, you can also try 600. If an error appears, go back to 644 and write to us.
  2. Add the rule below to the .htaccess in public_html. It refuses any direct browser request for the file, without interfering with WordPress:

    <Files wp-config.php>
      Require all denied
    </Files>

    You edit the .htaccess file from the “Files” tab: right-click » “Edit”, then “Save” (the steps are in Redirect to HTTPS and www).

D. Stop PHP from running in the image folder

Uploaded photos and documents go into wp-content/uploads. PHP code should never run there, but an attacker who manages to upload a file puts it exactly there.

  1. In the “Files” tab, go into wp-content/uploads.
  2. Create the .htaccess file with “New file”, open it with “Edit” and put this in it:
    <FilesMatch "\.(?i:php|phtml|phar)$">
      Require all denied
    </FilesMatch>
  3. Save and check that the images on the website still show. Images are not affected: the rule only blocks PHP files.

Some plugins keep their PHP files in uploads. If a plugin stops working after you add the rule, remove it and send us the plugin's name.

What not to do

  • Don't set 777, not even “just for a minute”. If a plugin needs 777 to work, that's a problem with the plugin.
  • Don't change the files' owner with tools found on the internet. On the hosting, files belong to your website's user, and PHP runs as that same user.
  • Don't leave old copies in public_html (backup.zip, site-vechi.sql, wp-config.php.bak): anyone who guesses their names can download them from a browser.

If something doesn't work

Support

Stuck? We'll do it together.

Tell us which step isn't working and, if you can, send a screenshot. We reply during business hours.

Phone and WhatsApp+40 775 396 021
HoursMonday–Friday, 9:00–18:00 Romanian time (EET/EEST)

Never send us your password on WhatsApp or by email. What information helps us solve it on the first try: how to ask for help.