Press enter to see results or esc to cancel.

Fix WordPress File Permissions On Ubuntu

I am sitting here in the darkness of my room at 3 AM and trying to fix WordPress file permissions on Ubuntu. Even as an experienced developer, it’s a challenge to remember command line commands to solve it.

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.

Where to execute the commands?

Execute all the commands from this article from the root folder of your WordPress installation. E.g., If you use Apache, you will probably put your WordPress into /var/www/<project-name> folder.

To navigate to this folder in your command line type: cd /var/www/<project-name>

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.

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

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?

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.