81

I'm using WordPress on centos 6.

I try to install a plugin. But I got this error:

Installing Plugin: bbPress 2.5.9 Downloading install package from https://downloads.wordpress.org/plugin/bbpress.2.5.9.zip

Unpacking the package…

Could not create directory.

How can I resolve this?

P/S: I run this command:

sudo -u root touch /var/www/html/wordpress/wp-content/plugins/test.txt

and it works. But I still get that error.

1
  • test.txt is not a directory well it might be stupid what I write right now, but check if you can create a directory here. (just to make sure).
    – MindRoller
    May 11, 2016 at 8:47

21 Answers 21

131

You only need to change the access permissions for your WordPress Directory:

chown -R www-data:www-data your-wordpress-directory

Best practices:

sudo find /var/www/html/wordpress/ -type d -exec chmod 755 {} \;
sudo find /var/www/html/wordpres/ -type f -exec chmod 644 {} \;

or

find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;

Where . is the path of WordPress directory.

5
  • 18
    your-wordpress-directory = "wp-content"
    – mallik1055
    Oct 22, 2018 at 10:20
  • 3
    In my case since I'm on a Mac it was chown -R _www:_www wp-content, actually sudo chown -R _www:_www wp-content. Nov 27, 2018 at 21:33
  • "your-wordpress-directory" does not tell me which directory is needed for plugins. Changing ownership of every directory in my Wordpress installation is unsafe, overkill, and may break other things.
    – felwithe
    Jan 30, 2019 at 17:05
  • felwithe, the directory needed for plugins changes when the wordpress directory changes. your-wordpress-directory signifies the place where you placed wordpress on your server.
    – kevr
    Apr 13, 2020 at 0:32
  • this is a bad practice and should be avoid. Apr 30, 2022 at 16:07
88

You can fix this by using the following commands. You should first be in the root folder of Wordpress.

sudo chown -R www-data:www-data wp-content/plugins/
sudo chmod 775 wp-content

sudo chown -R www-data:www-data wp-content/
6
  • 6
    This should be the answer, because it tells us which directories to fix and how to fix them.
    – felwithe
    Jan 30, 2019 at 17:03
  • 1
    It worked for me. If you purged apache2 and wordpress on ubuntu , you have re-apply those permissions
    – Kemal Atik
    Dec 8, 2019 at 18:55
  • 1
    THIS ANSWER IS WORKED FOR ME
    – gsm
    Jan 19, 2021 at 4:44
  • 1
    Thanks! Worked for me. I'm using a WordPress docker container in Windows 10 WSL2.
    – sybozz
    Mar 24, 2021 at 19:50
  • 1
    It's working for me.. Upvote from my side.. Jul 4 at 9:59
21

The user that is running your web server does not have permissions to write to the directory that Wordpress is intending to create the plugin directory in. You should chown the directory in question to the user that is running Wordpress. It is most likely not root.

In short, this is a permissions issue. Your touch command is working because you're using it as root, and root has global permissions to write wherever it wants.

4
  • 7
    Obviously, but that doesn't tell us which directory to fix.
    – felwithe
    Jan 30, 2019 at 16:58
  • 2
    @felwithe it's not obvious to OP, obviously.
    – kevr
    Jul 21, 2019 at 0:27
  • 1
    it doesn't matter who you think it's obvious to or not (even though the error message literally says "couldn't create directory"), it doesn't answer the question.
    – felwithe
    Jul 23, 2019 at 14:16
  • Fair enough. I was more trying to explain what the problem was so he could understand how to fix things like this in the future.
    – kevr
    Aug 22, 2019 at 6:09
17

A quick solution would be to change the permissions of the following:

  • /var/www/html/wordpress/wp-content
  • /var/www/html/wordpress/wp-content/plugins

Change it to 775.

After installation, don't forget to change it back to the default permissions.. :D

2
  • Great quick fix for users without root access Mar 19, 2019 at 8:59
  • In my case it changed permissions for wp-content but it its not allowing to change for plugins for wp-content Oct 1, 2019 at 14:22
11

I had to give ownership of /plugins and /upgrade to the server, nothing else.

$ cd /var/www/wordpress/wp-content
$ sudo chown www-data:www-data /plugings
$ sudo chown www-data:www-data /upgrade

Running Apache server on Ubuntu 18.04. Maybe more dirs will need to be changed later. Anyways, I plan to restore permissions once I finish editing, as suggested in this anwser.

2
  • If other answers do not solve the problem, try this one! /upgrade directory is suspicious!
    – shintaroid
    Oct 5, 2020 at 1:48
  • bad practice indeed. Apr 30, 2022 at 16:08
11

If you have installed wordpress using apt, the config files are split in multiple directories. In that case you need to run:

sudo chown -R -h www-data:www-data /var/lib/wordpress/wp-content/
sudo chown -R -h www-data:www-data /usr/share/wordpress/wp-content/

The -h switch changes the permissions for symlinks as well, otherwise they are not removable by user www-data

1
  • how i can change permission on cents os server
    – Mr Coder
    Jul 23, 2020 at 14:04
8

To solve permission issue on plugins and themes on localhost or production quickly, you just run this

sudo chmod 757 wp-content/themes
sudo chmod 757 wp-content/plugins

if take care permission on production, you can run

sudo chown -R www-data:www-data wp-content/themes
sudo chown -R www-data:www-data wp-content/plugins
0
6

If you are mac user , using XAMP

Go to the htdocs folder and open the terminal on the folder , as shown in the screenshot

enter image description here

Then Type the following command on the Terminal

**sudo chmod -R 777 <your wordpress folder Name>/**

E.g sudo chmod -R 777 wordpress/

1
  • This is very very dangerous Jul 4, 2022 at 10:18
6

CentOS7 or Ubuntu 16


1.

WordPress uses ftp to install themes and plugins.
So the ftpd should have been configured to create-directory

vim /etc/pure-ftpd.confg

and if it is no then should be yes

# Are anonymous users allowed to create new directories?
AnonymousCanCreateDirs       yes

lastly

sudo systemctl restart pure-ftpd

2.

Maybe there is an ownership issue with the parent directories. Find the Web Server user name and group name if it is Apache Web Server

apachectl -S

it will print

...
...
User: name="apache" id=997
Group: name="apache" id=1000

on Ubuntu it is

User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used

then

sudo chown -R apache:apache directory-name

3.

Sometimes it is because of directories permissions. So try

sudo chmod -R 755 directory-name

in some cases 755 does not work. (It should & I do not no why) so try

sudo chmod -R 777 directory-name

4.

Maybe it is because of php safe mode. So turn it off in the root of your domain

vim php.ini

then add

safe_mode = Off

NOTE:
For not entering FTP username and password each time installing a theme we can configure WordPress to use it directly by adding

define('FS_METHOD','direct');

to the wp-config.php file.

4

You need to change the permission of the directory

  1. At first change the user HTML folder (replace yourcomputerusername)

    sudo chown yourcomputerusername:yourcomputerusername /var/www/html

  2. Next change the permission for the user

    cd /var/www/html

    sudo chmod -R goa=rwx wordpress

    or

    sudo chmod -R 777 wordpress/wp-content

3

If anyone using shared hosting and get same problem it may be disk space issue. In that case contact with your hosting support and ask them to increase disk space of your acocunt.

1
2

I was on XAMPP for linux localhost and this worked for me:

sudo chown -R my-linux-username wp-content

2

What I end up doing is every time I create a WordPress project. in /www/html

I run below command

sudo chown www-data:www-data  wordpress_folder_name -R

hope this will help someone.

1

For me the problem was FTP server that WP is using to upload update. It had writting disabled in configuration, so just enabling it fixed the problem.

Shame on WordPress for providing such misleading error message.

1

You could try

sudo chmod goa=rwx -R /var/www/html
2
0

None of the above work for me except this one.

sudo chown daemon:daemon /opt/bitnami/apache/htdocs/

Don't forget to change /opt/bitnami/apache/htdocs/ to your directory

1
  • This is because every answer is for apache. You are using another distribution or server. Apr 30, 2022 at 16:09
0

Webserver user must have write access to directories to perform such operations, so you can try to change owner of files to webserver user (apache in this example, but can be differ from yours)

chown -R apache YOUR_BLOG_DIRECTORY
1
  • Could you add some explanation as to what this does?
    – camille
    Oct 20, 2021 at 16:12
0

If you are using some app that wraps http, you have to set these user in the command.

sudo chown -R [desireduser]:[desireduser] wp-content/

By example, if you are using lampp, the users that init httpd is "daemon" and the command that works will be:

sudo chown -R [desireduser]:[desireduser] wp-content/

You can search in your httpd.conf file enter image description here

-3

To solve permission issue on ubuntu server, you just run this

sudo chmod 777 -R 'wordpress wp-content file location' 

for example.

sudo chmod 777 -R /usr/share/wordpress/wp-content
3
  • 1
    This is a bad idea, 777 gives access to all users and processes to write these files.
    – Pelle
    Dec 5, 2019 at 9:49
  • this is your call how you use chmod, i just given the solution Dec 12, 2019 at 9:01
  • 1
    If the issue happens on your local, it's fine to use 777. Nov 11, 2020 at 16:10
-4

wordpressProject is the project name.

/var/www/html/wordpressProject sudo chmod -R 777 wp-content

Thanks. It will work.

1
  • 1
    never set 777 permissions unless u want to get hacked even by bots. Feb 28, 2020 at 1:34
-9

Absolutely it must be work!

  • Use this chown -Rf www-data:www-data /var/www/html
1
  • You shouldn't give the webserver full control of the files in webroot.
    – andho
    Jan 1, 2019 at 16:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.