How to install WordPress with WP-CLI on easyname VPS

Lesedauer 3 Minuten

WP-CLI is the official command-line-interface (CLI) tool for WordPress, which allows you to perform many WordPress actions without using a browser.

Why without a browser?

There are use cases in which we do not have a browser available to install or interact with WordPress, for example with our new virtual servers (VPS):* It is up to you whether you install Plesk as a server administration tool. However, since Plesk needs a lot of resources, we prefer to use a server without it. Apart from that, we can implement various actions with WP-CLI, which are especially suitable for testing and development of WordPress websites, such as installing WordPress and updating cores, plug-ins and themes, creating 100 dummy posts with or without content, changing passwords, searching and replacing text strings or restoring thumbnails. The list of all WP-CLI commands can be found here.

In this blog post, we want to show you how to use WP-CLI to install WordPress very quickly without downloading it and clicking through the installation. As a small bonus, we will introduce you to other useful WP CLI Commands at the end.

First, log in to your VPS using the command line tool of your choice:

ssh [your user]@[IP address of your VPS] 

Enter the password when prompted.

WP-CLI installation

If you have not installed WP-CLI yet, follow these steps:

  1. Download the .phar file from WP-CLI using wget or curl: 
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

2. Make the .phar file executable and move it *.

chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info

3. shows you whether WP-CLI has been installed correctly.

WordPress Core installation with WP-CLI 

1. Navigate to the directory where you want to install WordPress. Now you can download WordPress Core:

wp core download 

2. Now you need to generate the wp-config.php file: 

wp config create --dbname=wordpress --dbuser=[your database user] --dbpass=[your database password] --dbhost=127.0.0.1--locale=de_DE 

 3. You can install WordPress:  

wp core install --prompt 

The –prompt flag means that the command line queries each data needed for WordPress installation one by one: URL, title, admin-user, admin-password, admin-email and asks whether to send an e-mail about the successful installation of WordPress. The installation can also be performed without this flag, then the command will look like this:

wp core install --url=[your URL] --title=[your title] --admin_user=[your admin user] --admin_password=[your admin-password] --admin_email=[your admin-email] 

When the message “Success: WordPress installed successfully!” is displayed, you can visit your new WordPress website in the terminal. Congratulations!

Bonus 

As mentioned at the beginning, there are also other commands that you can execute from the command line. Here is a small example:

Plug-ins and themes 

wp plugin install classic-editor --activate 

downloads and installs Classic Editor (sorry Gutenberg…) 

wp scaffold plugin my-plugin 

generates the basic structure of plug-in modules

wp scaffold child-theme sample-theme --parent_theme=twentytwenty 

Creates a Child Theme based on a Parent Theme (my favourite command) 

Posts and page

wp post generate --count=100 --post_type=post 

generates 100 posts

curl -N http://loripsum.net/api/5 | wp post generate --post_content --count=100 

generates 100 posts with the content of the specified URL

wp post delete $(wp post list --post_type='page' --format=ids) 

deletes all posts of the specified type

Media 

wp media image-size 

shows the current image sizes

wp media regenerate 

restores media files, e.g. after resizing images.

 
There are many other commands from areas such as user administration, media, databases, maintenance, terms and taxonomy, transients, widgets, sidebars …  Try them here: https://developer.wordpress.org/cli/commands/ 

Conclusion 

WordPress Command-Line Interface WP-CLI will fulfil almost all your wishes. Not only is it fun to test all the commands, but it has also proved very helpful in practice 🙂 

* It is also possible to use WP-CLI with one of our web hosting products by directly executing the .phar file. Here is what you do:

php wp-cli.phar --info

Theresa Schmidt ist Webentwicklerin in unserem Development Team und eine Expertin in allen Belangen rund um WordPress. Hier geht's zu ihrer persönlichen Website.