Tags Archives: wp-cli

How To Reset WordPress Permalinks Using WP-CLI

When transferring a WordPress website from one location or domain to another, or changing from https: to http: your permalinks will probably stop working.


The standard solution for this from WordPress.org is to resave your permalinks as type: plain in the WordPress Admin Dashboard.


However, if you are transferring or replicating your website and databases non-manually, ie automatically using a shell script, then you may want to perform this action using the WP-CLI or WordPress WP Command Line Interface tool.



Here are the instructions for changing your permalinks using WP.


You need to install WP-CLI on your WordPress server first in order to use this method.



if your permalinks are set to plain, then you get this output:



root@asus:~# wp option get permalink_structure –path=/var/www/wordpress –allow-root


if they are set to postname, then you get this output:


root@asus:~# wp option get permalink_structure –path=/var/www/wordpress –allow-root



so, you need to set the structure to nothing:



root@asus:~# wp option get permalink_structure –path=/var/www/wordpress –allow-root
root@asus:~# wp option update permalink_structure ” ” –path=/var/www/wordpress –allow-root
Success: Updated ‘permalink_structure’ option.
root@asus:~# wp option get permalink_structure –path=/var/www/wordpress –allow-root



Note the result of 


wp option get permalink_structure


is now a blank line. This means that the permalinks have now been set to ” ” ie plain format.


So you need to add ” ” as the argument for the value in order to set the permalinks to plain.


I checked in wp dashboard – settings – permalinks


– and this is correct.

Continue Reading

How To Install WordPress WP-CLI (command line interface)

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6342k 100 6342k 0 0 2773k 0 0:00:02 0:00:02 –:–:– 2773k


root@asus:~# php wp-cli.phar –info
OS: Linux 5.8.0-63-generic #71-Ubuntu SMP Tue Jul 13 15:59:12 UTC 2021 x86_64
Shell: /bin/bash
PHP binary: /usr/bin/php7.4
PHP version: 7.4.9
php.ini used: /etc/php/7.4/cli/php.ini
MySQL binary: /usr/bin/mysql
MySQL version: mysql Ver 15.1 Distrib 10.3.29-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /root
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.6.0


root@asus:~# chmod +x wp-cli.phar
root@asus:~# sudo mv wp-cli.phar /usr/local/bin/wp


wp cli version


root@asus:~# wp cli version
Error: YIKES! It looks like you’re running this as root. You probably meant to run this as the user that your WordPress installation exists under.


If you REALLY mean to run this as root, we won’t stop you, but just bear in mind that any code on this site will then have full control of your server, making it quite DANGEROUS.


If you’d like to continue as root, please run this again, adding this flag: –allow-root


If you’d like to run it as the user that this site is under, you can run the following to become the respective user:


sudo -u USER -i — wp <command>





usage examples:

root@asus:~# wp plugin list –path=/var/www/wordpress –allow-root
| name | status | update | version |

… plug list follows….



root@asus:/usr/local/bin# wp core version –path=/var/www/wordpress –allow-root


wp cache flush –path=/var/www/wordpress –allow-root



root@asus:~# wp cache flush –path=/var/www/wordpress –allow-root
Success: The cache was flushed.



Continue Reading