How to Install WordPress via WP-CLI

Installing WordPress with WP-CLI takes just a few commands. You need to follow the steps below to install WordPress via the WP-CLI interface.

Using the WordPress command-line interface Navigate to the public_html folder to access and manage your website:

cd /home/username/public_html

Download the newest WordPress core version once you are in the public_html directory:

wp core download

Enter the wp-config create command to MySQL database credentials to WordPress:

wp config create --dbname=wordpress --dbuser=user --dbpass=password --dbhost=localhost --dbprefix=wp_

NOTE: Replace the default values with your database details.

To complete the WordPress installation use the wp core install command:

wp core install --url=yourdomain.com --title=Site_Title --admin_user=admin_username --admin_password=admin_password [email protected]

NOTE: Replace the default values with your credentials.

After the installation is complete, you should see a successful message.

How to Reinstall WordPress Core via WP-CLI

Using the same WordPress installation command to reinstall the core software, use the skip-content option to download WordPress without the default themes and plugins and the force option to overwrite the existing files.

wp core download --skip-content --force

Manage Content via WP-CLI
This method can be useful for tasks such as creating bulk posts that can’t be done on WordPress admin panel

To see the list of all posts, use this command:

wp post list

To delete a post use this command:

wp post delete 1

To create a new post, use this command:

wp post create --post_status=publish --post_title="This Post Was Created With WP-CLI" --edit

This command will open the Vim text editor. Input the text editor's content, exit Vim by typing:wq then press Enter.

To generate 5 posts, enter this command:

wp post generate --count=5

To import all images from the images_for_site folder use this command:

wp media import images-for-site/*