Press enter to see results or esc to cancel.

Fix WordPress File Permissions On Ubuntu

WordPress relies on a specific file permission structure to function properly. If these permissions are incorrect, you may encounter issues such as errors when uploading themes or plugins, or even a completely inaccessible website.

In this guide, we’ll walk you through the steps to fix WordPress file permissions on your Ubuntu server.

We don’t need any unique tool to fix file permissions for this, but only one we already have built-in in Ubuntu. The only two commands we need are chown and chgrp.

Understanding File Permissions

Before we dive into the commands, let’s briefly understand file permissions in Unix-based systems like Ubuntu.

Each file and directory on your server has an associated set of permissions that determine who can access it and how they can interact with it.

These permissions are divided into three categories:

  1. User: This refers to the owner of the file or directory.
  2. Group: This refers to a group of users on the system.
  3. Others: This refers to everyone else on the system.

Each category can be granted three types of permissions:

  1. Read: Allows the user to view the contents of the file or directory.
  2. Write: Allows the user to modify the contents of the file or directory.
  3. Execute: Allows the user to run the file if it’s a script.

Fixing WordPress File Permissions

Now that we have a basic understanding of file permissions, let’s fix the permissions on your WordPress installation.

The following steps assume that you have access to your Ubuntu server through SSH and that you know your WordPress directory path. If you’re unsure about your WordPress directory path, you can usually find it in the wp-config.php file located in the root directory of your WordPress installation.

  1. Connect to your Ubuntu server via SSH.
  2. Navigate to your WordPress directory using the cd command. For example, if your WordPress is installed in the /var/www/html/my-website directory, you would use the following command:
cd /var/www/html/my-website
  1. Run the following commands to set the correct permissions for files and directories:
sudo chown -R www-data:www-data .

This command changes the ownership of all files and directories within your WordPress directory (represented by the .) to the user and group www-data. The www-data user is the default user under which Apache, the web server software that powers WordPress, runs on Ubuntu.

sudo chmod -R 644 .

This command sets the permissions for all files within your WordPress directory to 644. This means that the owner (www-data) can read and write to the files, the group (www-data) can only read the files, and others have no permissions.

  1. Grant execute permissions to specific directories: Certain directories within your WordPress installation require execute permissions for proper functionality. Run the following command to grant execute permissions to these directories:
sudo chmod +x wp-admin wp-includes
  1. Save the changes and exit the SSH session.

By following these steps, you should have successfully fixed the file permissions on your WordPress installation.

Which tools do we need?

Here are two “tools/commands” you need to fix your file and directory permissions:

CommandDescription
chownThis command is an abbreviation of change owner; I use it to change the file system files and directories owner.
chgrpThis command is an abbreviation of change group; I use it to improve the group associated with a file system object to one of which they are a member.

What do we want to do?

We want to set proper file and folder permissions for our WordPress website. Generally, we want to protect our files and folders by limiting access and setting permission rules.

Verifying File Persmissions

Once you’ve made the changes, it’s a good practice to verify the file permissions to ensure they were applied correctly. You can use the ls -l command to view the permissions of your WordPress files and directories.

For example, the following command would list the permissions for all files and directories within your WordPress directory:

ls -l .

The output will display information about the owner, group, and permissions for each file and directory.

Solution

CommandDescription
sudo chown -R <username>:<username> *Changes ownership of all files and folders to your user account and user group.
sudo chown www-data:www-data -R wp-content/Changes ownership of all files and folders in wp-content folder to www-data user and group. Www-data is the default Apache user and group.
find . -type d -exec chmod 755 {} \;Set all directories permissions to 755
find . -type f -exec chmod 644 {} \;Set all files permissions to 644
Table with the proper WordPress file permission commands

File and folder permissions

You are probably asking what the hell are those numbers “755” and “644” 🙂

It’s a straightforward model. There are three kinds of actions users, groups, and everybody else can do with our files:

  • Read
  • Write
  • Execute

File permissions are organized as three numbers:

  1. User permission
  2. Group permission
  3. Everybody’s permission

And the last thing is the levels of the permission we can grant:

  • 0 – No access at all
  • 1 – Execute
  • 2 – Write
  • 3 – Write, and execute
  • 4 – Read
  • 5 – Read, and execute
  • 6 – Read, and write
  • 7 – Read, write and execute

Let’s translate the numbers we gave to files and folders in our WordPress file structure.

We set 755 to all folders, which implies that the user (first number) can read, write and execute (7) whatsoever in that folder, the user group (second number) can read and execute and everybody else (third number) also read and execute in these folders. The same pattern applies to files, you get the point. Right?

Conclusion

I hope I will never again forget those commands when I write them and explain them in detail. Also, I hope you learn how to Fix WordPress file permissions on Ubuntu from this article or at least add it in the bookmarks as a resource for copy/paste magic when needed 🙂

When starting with Ubuntu as a beginner, you often have many simple questions to ask. I covered some of those in my new article.

After you fix the file permissions on your WordPress website, maybe you want to increase the speed of your WordPress website. I wrote an article on improving WordPress website speed without plugins with just the four simple steps you have to implement.