Run WP CLI as the correct non-root user, even when logged in as root
Are you sick of running WP-CLI commands as root, having to constantly use the --allow-root
flag (then feeling somewhat uneasy about your server’s security)?
Find the exact path to where you installed wp-cli.phar
, usually somewhere in the /usr/local/ directory in Ubuntu – then use it in the following command (/usr/local/bin/wp
in my case):
alias wp='sudo -u `stat -c %U .` -s -- php /usr/local/bin/wp --path=`pwd` '
From now on, when you log in as root you’ll be running WP-CLI commands as the owner of the WordPress install, no need for the --allow-root
flag. It’s much safer too!
Set correct ownership for your WordPress directory
Replace /var/www/html/wordpress
with the absolute path to your WordPress install:
sudo chown -R www-data:www-data /var/www/html/wordpress
Set proper file permissions for your WordPress directory
Replace /var/www/html/wordpress
with the absolute path to your WordPress install:
sudo find /var/www/html/wordpress/ -type d -exec chmod 775 {} \;
sudo find /var/www/html/wordpress/ -type f -exec chmod 664 {} \;
Batch change file modified dates to bust/invalidate external caching
This affects all files in directories and subdirectories at your current location:
find . -type f -exec touch -d "60 seconds ago" {} \;
Reload systemd services (Ubuntu 18.04)
There a bunch of services potentially running on your rig. I use nginx and php7.4-fpm so my most used commands are:
sudo systemctl reload php7.4-fpm
sudo systemctl reload nginx
Depending on what you’ve built, you may have use for the following:
sudo systemctl reload apache
sudo systemctl reload mysql
sudo systemctl reload mariadb
Instead ofreload
, you can use restart
, stop
, start