Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

WordPress "Could not create directory." when a plugin, theme or core update fails

Technical article
Hosting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

On the Plugins, Themes or Updates screen, an update or install stops with Update failed: Could not create directory. or Installation failed: Could not create directory. WordPress tried to make a folder under wp-content and the operating system refused. The WordPress developer documentation says update problems are probably related to permissions issues on the filesystem. Our own reading: the account PHP runs as is not allowed to create folders where the update is unpacking or installing.

What the error means

In the WordPress 6.7.1 source, the text Could not create directory. is returned in five places. In wp-admin/includes/class-wp-upgrader.php it is the string mkdir_failed, used when the destination folder of an update does not exist and WordPress fails to create it. In wp-admin/includes/file.php the same text is returned by the unzip code (_unzip_file_ziparchive and the PclZip fallback) when it cannot create a folder while unpacking a package, and by copy_dir and move_dir when they cannot create a folder in the destination. The update screen in updates.js shows the message after Update failed: or Installation failed:.

The unpacking happens in wp-content/upgrade, the working folder in unpack_package. WordPress then copies the files to wp-content/plugins, wp-content/themes or the core folders.

How WordPress writes depends on its filesystem method, chosen by get_filesystem_method. If the constant FS_METHOD is defined, that value is used. If it is not, WordPress creates a small test file in wp-content and compares the owner of that file with the owner of wp-admin/includes/file.php. If the two owners are the same it uses the direct method, which makes folders with PHP's own mkdir as the PHP user. If the owners differ, it falls back to FTP or SSH methods, which prompt for connection details. Two exceptions: plugin and theme updates can be allowed to use direct when the folder is writable even though the owners differ, and a filter named filesystem_method can change the result.

The developer documentation for wp-config.php says: "FS_METHOD forces the filesystem method. It should only be “direct”, “ssh2”, “ftpext”, or “ftpsockets”." It adds that direct "is chosen automatically when appropriate".

Likely causes

Cause What you see How to confirm
The wp-content tree is owned by one account but PHP runs as another, and FS_METHOD is forced to direct The error on every plugin or theme update FS_METHOD in wp-config.php is direct; owners differ between wp-content and the PHP account
wp-content/upgrade (or the plugin's own folder) was created by another user, for example during a manual copy as root Fails for one folder only; other folders work ls -ld shows a different owner on that folder
wp-content is not writable for PHP All updates and uploads fail Site Health lists the folder as Not writable

Prove the cause before changing anything

All of these steps only read.

1. Look at what WordPress itself reports. In the Site Health information screen, WordPress 6.7.1 has a section named Filesystem Permissions. It lists the main WordPress directory, the wp-content directory, the uploads, plugins and themes directories, each as Writable or Not writable.

2. Read the owner and mode of the folders involved. The path below is the one in the example.

ls -ld /var/www/example.com/htdocs/wp-content /var/www/example.com/htdocs/wp-content/upgrade /var/www/example.com/htdocs/wp-content/plugins /var/www/example.com/htdocs/wp-content/themes

Each line shows the mode, then the owner, then the group. A folder that does not exist is reported as such; WordPress makes upgrade itself when it can.

3. Read the owner of the file WordPress compares against.

ls -l /var/www/example.com/htdocs/wp-admin/includes/file.php

WordPress compares this owner with the owner of a test file that PHP has just created, which is owned by the account PHP runs as. A good result is the account PHP runs as (step 5). A bad result is a different owner, which is the case the filesystem method detection is built around.

4. See whether FS_METHOD is set.

grep -n "FS_METHOD" /var/www/example.com/htdocs/wp-config.php

No line means WordPress is choosing the method itself. A line with direct means it will always write as the PHP user.

5. Ask your host which account PHP runs as. That is the user that should own the folders in step 2 and, for the direct method, the file in step 3. The ls command, ls -l and ls -ld in steps 2 and 3, lists directory contents in a long format, or with -d lists directories themselves, not their contents, as the ls manual page describes. The grep -n in step 4 prefixes each output line with its line number, as the grep manual page describes.

Fix

WordPress's hardening guide sets out the scheme: "All files should be owned by your user account, and should be writable by you." It says wp-content is "intended to be writable by your user account and the web server process", and that theme files "can be writable only by your user account" if the built-in theme editor is not used. For plugin files it says all files should be writable only by your user account. On automatic updates it says: "all file operations are performed as the user that owns the files, not as the web server’s user." In the 6.7.1 source, direct is chosen when the owner of file.php is the owner of the test file PHP has just created, which is the account PHP runs as.

Where a whole tree is owned by another user, the hardening page's scheme above ("All files should be owned by your user account") is the target, and reaching it is a change for the host or administrator. Changing a whole tree cannot be undone to a mixed starting state, because the old owners are lost. The two cases below can be reversed exactly.

One folder owned by the wrong user

First save the current state: write down the owner, group and mode that ls -ld shows for wp-content/upgrade, and the time.

Risk: the next command changes the owner of one folder, and only that folder. If the account name is wrong, updates keep failing and the folder may no longer be readable by the user who deployed it. It needs administrator rights on the server.

Change the owner and group of the folder to the account PHP runs as. The chown manual page gives the form chown [OPTION]... [OWNER][:[GROUP]] FILE... and says it changes the owner and/or group of each file. In the command, exampleuser stands for that account.

chown exampleuser:exampleuser /var/www/example.com/htdocs/wp-content/upgrade

To undo it, set the folder back to the owner and group you wrote down. The update then fails again if that owner was the cause.

Risk: the undo command changes the owner of the same single folder again, and needs the same administrator rights. If the values typed are not the ones you wrote down, the folder keeps a wrong owner.

In the command, <owner>:<group> stands for the values you wrote down.

chown <owner>:<group> /var/www/example.com/htdocs/wp-content/upgrade

Then run step 2 again and check that the owner and group of upgrade match what you wrote down.

FS_METHOD forced to direct

The wp-config.php page says to use FS_METHOD only "if you are experiencing update problems" and: "If you change it and it doesn’t help, change it back/remove it." This second case applies only when someone added a direct line to try to fix update problems and it did not help. If step 4 showed a direct line and the owners of the files differ from the account PHP runs as, the ownership change above is the repair; without the line WordPress asks for FTP or SSH details instead.

First save the current state. Keep a copy of wp-config.php beside it. The cp manual page says cp copies a source to a destination and -p preserves mode, ownership and timestamps.

cp -p /var/www/example.com/htdocs/wp-config.php /var/www/example.com/htdocs/wp-config.php.2026-12-04

Risk: the copy holds the database login, so it must stay out of any web-readable place you share. The next edit removes a line from wp-config.php, the file that holds the database login. A typing error can take the whole site offline at once. With the line gone, WordPress chooses the method itself, and if the owners differ it asks for FTP or SSH details instead of writing directly.

Edit wp-config.php and remove the line that defines FS_METHOD.

To undo it, copy wp-config.php.2026-12-04 back over wp-config.php.

Risk: the undo command overwrites wp-config.php. It discards any other change made to the file since the copy and puts the FS_METHOD line back.

cp -p /var/www/example.com/htdocs/wp-config.php.2026-12-04 /var/www/example.com/htdocs/wp-config.php

Then run step 4 again and check that the FS_METHOD line is back.

Example (illustrative): on web01, www.example.com runs PHP as exampleuser. A plugin update fails with Update failed: Could not create directory. Step 2 shows wp-content/plugins owned by exampleuser but wp-content/upgrade owned by root, which a manual file copy created. The administrator writes down root:root and the mode, changes the owner of upgrade to exampleuser, and the update completes.

Confirm the fix

  1. Run the update again from the same screen and expect it to complete.
  2. Run step 2 again and check that the upgrade folder and the plugin folder show the account PHP runs as.
  3. Open Site Health and check that Filesystem Permissions lists wp-content as Writable.

What to watch afterwards

  • When files are copied onto the server as an administrator account, set the owner afterwards to the account PHP runs as.
  • The wp-config.php page says to use FS_METHOD only "if you are experiencing update problems", and "If you change it and it doesn’t help, change it back/remove it."
  • The developer documentation says one-click updates work on most servers, and "If you have any problems, it is probably related to permissions issues on the filesystem."

Risks and limits

  • These commands have not been run or lab-tested.
  • A recursive ownership change cannot be reversed to a mixed state; only a full file copy restores it.
  • How WordPress picks its method is described for the 6.7.1 source; other versions may differ.

Sources