How to properly 'chown' & 'chmod' wordpress files to use with wp-cli?
My VPS set up is as follows --
- Debian 10
- Apache
- MariaDB
- PHP
- WP-CLI
- Wordpress
Wordpress File Ownership
I found a guide which says wordpress files should be owned by Apache's user (i.e. www-data).
(1) sudo chown -R www-data:www-data "my Document Root"
But I found the following paragraph in this wordpress official article.
Typically, all files should be owned by your user (ftp) account on your web server, and should be writable by that account. On shared hosts, files should never be owned by the webserver process itself (sometimes this is www, or apache, or nobody user).
It means I should chown as follow …
(2) sudo chown -R $USER:$USER "my Document Root"
Managing Wordpress from Dashboard and WP-CLI
If I use (1), Dashboard = OK, WP-CLI = NO (Can't mkdir)
If I use (2), WP-CLI=OK, Dashboard=NO (Asking for FTP credentials).
So, how should I set file ownership, 1 or 2 or something else?
Notes on WP-CLI
When I tried to run WP-CLI with sudo, WP-CLI prompt says to run with
sudo -u www-data -i -- wp wp-cli command
But I got This account is currently not available.
The working command is --
sudo -u www-data wp wp-cli command
I don't know their document need to be upgraded or am I missing something?
Wordpress File Permissions
According to the Wordpress Hardening Guide, I set --
cd "my Document Root"
sudo find . -type d -exec chmod 750 {} \;
sudo find . -type f -exec chmod 640 {} \;
sudo chmod 400 wp-config.php
But my website can't be accessed from browser, so I have to set --
cd "my Document Root"
sudo find . -type d -exec chmod 754 {} \;
sudo find . -type f -exec chmod 644 {} \;
sudo chmod 400 wp-config.php
I would like to know how to set wordpress files ownership & permissions properly.
1 Reply
Hey there -
I wanted to hop in here and offer our guide for changing file permissions with chmod, as it gives you the basics on how to do it. I think with our guide and the WordPress official doc that you linked, it'll help you get this to work.
Modify File Permissions with chmod
Here's our guide on chown:
The command to change ownership is as follows, and it is explained fully in the guide above:
chown user:group /path/to/file
I hope that helps!