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:
Text
cd /home/username/public_html
Download the newest WordPress core version once you are in the public_html directory:
Text
wp core download
Enter the wp-config create command to MySQL database credentials to WordPress:
Text
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:
Text
wp core install --url=yourdomain.com --title=Site_Title --admin_user=admin_username --admin_password=admin_password --admin_email=testing@email.com
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.
Text
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:
Text
wp post list
To delete a post use this command:
Text
wp post delete 1
To create a new post, use this command:
Text
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:
Text
wp post generate --count=5
To import all images from the images_for_site folder use this command:
Text
wp media import images-for-site/*