You upload WordPress, open the site, fill in the database name, user and password, click Submit, and instead of the “Run the installation” screen you get this:
Unable to write to wp-config.php file. You can create the wp-config.php file manually and paste the following text into it.
Below it is a box full of PHP. It happens mostly on fresh VPS installs (Ubuntu or Debian with Apache or nginx) where the files were uploaded as root or as your SSH user, and PHP runs as a different user like www-data. It showed up again in a WordPress.org support thread this week, on Ubuntu 24.04 with MariaDB.
There are two ways out. You can do what the message says and create the file yourself, which takes a minute. Or you can fix the permissions so the installer can write it, which you will need later anyway for updates and uploads.
Why the installer can’t write the file
As of 2026-11-23, wp-admin/setup-config.php does one check before it writes anything: is_writable( ABSPATH ). ABSPATH is your WordPress root folder, the one that holds wp-admin, wp-includes and wp-config-sample.php.
So the question is not whether wp-config.php is writable (it doesn’t exist yet). The question is whether the user PHP runs as can create a new file in that folder. If the folder belongs to root with 755, it can’t, and WordPress falls back to showing you the generated config in a text box.
That is also why setting a single file to 777 often changes nothing. The folder is what matters, and the owner matters more than the mode.
Quick fix: create wp-config.php yourself
This is the fastest route and it is fully supported. The official install guide lists renaming wp-config-sample.php to wp-config.php and editing it as an optional install step.
Step 1. Copy the text from the installer box
Leave the browser tab open and select everything in the text box. That text already has your database details and a fresh set of salts, so it is the best thing to paste.
Step 2. Create the file in the WordPress root
Over SSH, in the folder that holds wp-config-sample.php:
cd /var/www/html
nano wp-config.php
Paste, save, and exit. If you use SFTP or a file manager instead, create a plain text file named exactly wp-config.php in the same folder. Watch out for editors that save it as wp-config.php.txt.
If you would rather type it from scratch, the part that matters is the database block. Everything else can come from wp-config-sample.php:
define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wp_user' );
define( 'DB_PASSWORD', 'your-password-here' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8mb4' );
define( 'DB_COLLATE', '' );
$table_prefix = 'wp_';

💡 If you build the file from the sample, replace the “put your unique phrase here” lines with real keys from https://api.wordpress.org/secret-key/1.1/salt/ so you don’t go live with placeholder salts.
Step 3. Run the installation
Click “Run the installation” on the installer page, or open /wp-admin/install.php directly. You should get the site title and admin user form.
If you reload the setup page instead, WordPress stops with “The file wp-config.php already exists”. That is fine. It means the file is in the right place, and the “installing now” link in that message takes you to the same form.
If install.php shows “Error establishing a database connection”, the file is being read but the credentials or host are wrong. I covered that one in Error Establishing a Database Connection in WordPress.
If you have WP-CLI on the server, you can skip the browser and the paste completely. Run it as the user that should own the files:
wp config create --dbname=wordpress --dbuser=wp_user --prompt=dbpass
wp core install --url=https://example.com --title="My Site" --admin_user=admin [email protected] --prompt=admin_password
wp config create should report that it generated wp-config.php. If it says it can’t connect to the database, check the credentials before going further.
Proper fix: let PHP write to the WordPress folder
Creating the file by hand gets you through the install, but the same permission problem will come back. Plugin updates fail, media uploads fail, and WordPress starts asking for FTP details. I would fix it now while the site is empty.
Step 1. Find the user PHP runs as
ps -eo user,comm | grep -E 'php-fpm|apache2|httpd' | sort -u
With Apache and mod_php on Debian or Ubuntu you will usually see www-data. With PHP-FPM, ignore the root line (that is the master process) and look at the pool workers. A custom pool may run as your own user, and then the files should simply belong to that user.
Step 2. Check who owns the WordPress folder
ls -ld /var/www/html
ls -l /var/www/html | head
If the owner is root, or a user that is neither the PHP user nor in its group, that is your cause.
Step 3. Fix ownership and modes
Back up first if anything is already on the site. Then, for a VPS where PHP runs as www-data and you deploy as deploy (replace both with your users):
sudo chown -R deploy:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod 775 {} \;
sudo find /var/www/html -type f -exec chmod 664 {} \;
Your user owns the files, and the web server can write through the group. The WordPress file permissions guide describes this group-writable setup (775 for folders, 664 for files) and says files should never be owned by the web server process itself.
The person in the support thread fixed it with chown www-data:www-data plus 755 and 644. That works too, but it lets any PHP code on the site rewrite every file, so I prefer the group approach above.
Now go back to /wp-admin/setup-config.php. It should create the file on its own and show the “Run the installation” button.
Step 4. Lock wp-config.php down after the install
The same guide says wp-config.php is created with 644 and that it is a hazard to leave it like that. Once the site is installed, make it readable only by you and the PHP group:
sudo chmod 640 /var/www/html/wp-config.php
Never leave a folder at 777 to “make it work”. If you changed something to 777 while testing, set it back now.
If WordPress still asks for FTP credentials after this, the ownership is still off. See WordPress Asks for FTP Credentials? Fix File Ownership First and WordPress FS_METHOD explained.
💡 On OpenPanel you don’t need SSH for this. The Fix Permissions tool sets you as owner of everything in /var/www/html/, sets files to 664 and folders to 775, and is meant for the “CMS cannot write to certain folders” case. In cPanel you usually change modes item by item in File Manager, and ownership changes need the host, since they require root.
Other messages from the same installer step
A few related errors come from the same file, and the fix is close:
- “You need to make the file wp-config.php writable before you can save your changes.” The folder is writable, but an existing read-only
wp-config.phpis in the way. Fix its owner, or remove the empty file and let the installer create it. - “Sorry, I need a wp-config-sample.php file to work from.” The upload was incomplete. Upload
wp-config-sample.phpfrom a fresh WordPress download. - “The file wp-config.php already exists.” Not an error. Go to
/wp-admin/install.php, or delete the file if you really want to start over.
If plugin installs later fail with “Could not create directory”, it is the same ownership problem on wp-content. I covered it in Installation failed: Could not create directory.
TL;DR: “Unable to write to wp-config.php file” means PHP can’t create files in the WordPress root folder. Copy the text from the installer into a new wp-config.php (or use wp config create) to finish the install now. Then give the folder the right owner and group so updates and uploads work, and set wp-config.php to 640 when you are done.

