Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared Managed Cloud India
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Best lists Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Troubleshooting · Troubleshooting

How to Fix "Unable to Write to wp-config.php" in WordPress

Short answer

WordPress shows this error when the web server cannot write to wp-config.php or to the folder that holds it. Make the file writable by the account that runs WordPress, usually by setting it to 644 for a short time, then save your change. Set it back to a stricter value such as 640, 440, or 400 after the write works.

Key takeaways

  • The error means WordPress or a plugin tried to save wp-config.php and the server refused the write.
  • A read-only file, wrong owner, full disk, or locked folder can each cause the same message.
  • WordPress.org says wp-config.php starts at 644, while its suexec scheme uses 440 or 400 for that file.
  • Never leave the file at 777, and never set a whole folder to 777 to work around the error.
  • Back up wp-config.php before you edit it, because one bad line can stop the site from loading.

What does “Unable to Write to wp-config.php” mean?

The message means WordPress tried to save a change to wp-config.php and the server refused the write.

The file holds base settings such as database connection details, so WordPress must be able to read it on every page load. The Editing wp-config.php page from WordPress Developer Resources says the file sits in the root of the WordPress file directory.

You may see the message during install, when a plugin tries to add a line, or when you save a setting that writes to the file. The cause is a file rule, not a broken WordPress install in most cases.

What causes WordPress to fail writing wp-config.php?

The most likely cause is a read-only file.

WordPress.org's Changing File Permissions page says wp-config.php is first created with 644 permissions. A value of 440 or 400 gives read access only, so any later write will fail until you loosen it for a short time.

Other causes follow a clear order:

  • Wrong owner: the file belongs to a different account than the one PHP runs as.
  • Locked folder: the root folder will not let PHP create or replace the file.
  • Full disk or quota: the server has no space left to save the new version.
  • Security rule: a host rule, firewall, or file lock blocks writes to that file.
  • Wrong database details: the installer cannot finish, so it never reaches the write step.

If the site also shows a database error, check the database details first. Our guide to fixing the database connection error covers the five values to check in wp-config.php.

How do you back up before you change permissions?

Back up the file before you touch it.

Download a copy of wp-config.php to your own computer, and keep a full site backup as well. The Editing wp-config.php page from WordPress Developer Resources warns you to practise regular backups and know how to restore them before you change settings.

Do not leave a copy named wp-config.php.bak in the web folder. A copy with a plain text ending can be read in a browser, while the real file is run as PHP.

Store the backup outside the web folder or on your own computer. See our guide on how to back up WordPress if you do not have a recent backup yet.

How do you check the current permissions and ownership?

Check the file first, then the folder that holds it.

Open your hosting file manager or FTP client and find wp-config.php in the site root, next to wp-admin and wp-content. Note the number shown for it, plus the owner and group if your tool shows them.

WordPress.org's Changing File Permissions page says files should typically be owned by your user account and writable by that account. It also says files should never be owned by the web server process itself on shared hosts.

Check the root folder too. If the folder is read-only for the PHP account, WordPress cannot create the file during install, even when the file itself looks fine.

ItemCommon valueWhat it allows
Folders755Owner can write; group and others can read and open
Ordinary files644Owner can read and write; group and others can read
wp-config.php, suexec hosts440 or 400Read only, so other users on the server cannot read it
wp-config.php, short fix644Owner can read and write while you save a change
Never use777Everyone can read, write, and run the file

The table above follows the WordPress.org permission scheme. The Changing File Permissions page from WordPress.org gives 755 or 750 for folders, 644 or 640 for files, and 440 or 400 for wp-config.php on suexec hosts.

How do you fix the file with cPanel File Manager?

Use File Manager when you do not have FTP or SSH access.

  1. Open cPanel, then open File Manager and go to the site root, usually public_html.
  2. Select wp-config.php, then click Permissions in the toolbar.
  3. Set the value to 644, then click Change Permissions to save it.
  4. Retry the action that failed, such as the install step or the plugin save.
  5. Set the file back to 640, 440, or 400 once the write works.

The cPanel File Manager docs say you select the file, click Permissions, use the checkboxes or text boxes, and click Change Permissions. The same docs say the setting defaults to 0644.

If 644 does not work, the owner may be wrong. Ask your host which account PHP runs as before you try a looser value.

How do you fix the file with FTP or SSH?

Use FTP when File Manager is not available, and SSH when you are used to the command line.

In FileZilla, right-click wp-config.php, choose File Permissions, type 644, and click OK. Retry the failed action, then set the file back to 640, 440, or 400.

With SSH, run chmod 644 wp-config.php from the site root. The PHP chmod manual says the mode has three parts for owner, group, and others, where 4 means read, 2 means write, and 1 means execute.

If the owner is wrong, chmod alone will not help. The PHP chmod manual also says the mode can be changed only by the user who owns the file on most systems.

Ask your host to fix ownership if you see a permission denied error after chmod. A related install error is covered in our guide to fixing the could not create directory error.

How do you create wp-config.php by hand when the installer cannot write it?

Create the file by hand when the installer still cannot write it.

  1. Copy wp-config-sample.php to a new file named wp-config.php in the site root.
  2. Open the new file in a plain text editor, not a word processor.
  3. Fill in DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST from your hosting account.
  4. Add fresh salts from the WordPress.org secret-key service.
  5. Save the file, upload it if you edited it on your computer, then run the installer again.

WordPress Developer Resources says wp-config.php is not in the first download. The Editing wp-config.php page says the setup process creates the file from the details you give during install.

Put new settings above the line that says “That's all, stop editing!” The WordPress.org Debugging in WordPress page says debug code must go before that line.

How do you confirm the fix worked?

Repeat the action that failed, then check the site loads.

If the installer failed, run it again and look for the next step instead of the same write error. If a plugin failed, save its setting again and check that the line now appears in wp-config.php.

Open Tools, then Site Health, then the Info tab to review the site setup. The WordPress.org Site Health page says the page sits under Tools then Site Health, and that Site Health was added in WordPress 5.2.

Check the front of the site and wp-admin in a fresh browser tab. If either shows a blank page or a database error, restore your backup copy and check the last line you changed.

When should you call your host?

Call your host when the file, folder, and owner all look right but writes still fail.

Ask the host to check disk space, disk quota, file locks, and the PHP user for your site. Those four items sit outside the WordPress dashboard, so only the host can check them with certainty.

Also call the host if a permission change takes the site offline. WordPress.org's Changing File Permissions page warns that setting incorrect permissions can take your site offline.

Check the PHP version while you wait. WordPress.org's Requirements page recommends PHP 8.3 or greater, plus MariaDB 10.11 or greater or MySQL 8.4 or greater, with HTTPS support. Our guide on how to update PHP in WordPress explains the safe order for that change.

What mistakes should you avoid?

Avoid the quick fixes that leave the site open.

Never set wp-config.php or any folder to 777. WordPress.org's Changing File Permissions page says no folder should ever be given 777, even upload folders.

Do not leave the file at 644 after a fix if your host supports a stricter value. The WordPress hardening guide says to lock down file permissions as much as possible and loosen them only when you need to allow write access, in the Hardening WordPress page.

Do not edit the file in a word processor. Word processors can change quote marks and add hidden marks that break PHP.

Do not turn on debug display on a live site to chase this error. The WordPress.org Debugging in WordPress page says WP_DEBUG is false by default, and that debug tools are meant for local testing and staging installs, not live sites.

If the error came with a login loop or a 403 page, the cause may sit elsewhere. See our guide to fixing the 403 forbidden error before you change more file rules.

Frequently asked questions

Is it safe to set wp-config.php to 644?

Yes, for a short time while you save a change. WordPress.org says the file starts at 644, and 644 lets the owner read and write while others can only read. Set it back to 640, 440, or 400 after the write works, if your host supports that value.

Why does the installer say it cannot write wp-config.php?

The installer needs write access to the site root folder or to the file itself. A read-only file, wrong owner, full disk, or host file lock can each block it. Check the file value first, then the folder value, then ask your host about disk space and ownership.

Can I just create wp-config.php myself?

Yes. Copy wp-config-sample.php to wp-config.php, fill in the database name, user, password, and host from your hosting account, and add fresh salts. Save the file in the site root, then run the installer again. Keep a backup copy on your own computer first.

What should wp-config.php permissions be after the fix?

Use the strictest value that still lets the site load. WordPress.org gives 440 or 400 for wp-config.php on suexec hosts, and 640 or 644 in other setups. If the site stops loading after a stricter value, go back to the last working value and ask your host.

Does this error mean my database details are wrong?

Not always. Wrong database details can stop the installer before it writes the file, so the two problems can look alike. Check the write error first by fixing permissions, then check the database name, user, password, and host if the installer still cannot connect.

Sources

  1. Editing wp-config.php WordPress Developer Resources
  2. Changing File Permissions WordPress.org
  3. Hardening WordPress WordPress Developer Resources
  4. Requirements WordPress.org
  5. Debugging in WordPress WordPress.org
  6. File Manager cPanel Documentation

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

WPLegible editors

Researched from the primary sources listed above and checked against our editorial rules. About the site · How we test