How to Install WordPress with WP-CLI

WP-CLI is the command line tool for managing your WordPress sites. Using this tools, we can perform several operations without even log in to the dashboard. We all know about installing and setup WordPress manually. But, using WP-CLI we can do all WordPress setup from one place only without navigating anywhere.

Having said that, let us study how to install WordPress with WP-CLI.

WP-CLI Installation

To get started, you should first install WP-CLI on your system. There are several ways to install WP-CLI. For this tutorial we follow installation using Composer.

We are installing WP-CLI globally on a system. So, this would be a one time process. You don’t need to install it again on your system.

Open the terminal in your root directory(htdocs or www) whichever you are using for your projects and run the command below.

composer global require wp-cli/wp-cli

After the above command, you need to set ~/.composer/vendor/bin(for Linux) in your PATH. If you are running the command on local Windows operating system then set the C:\Users\YOUR_COMPUTER_NAME\AppData\Roaming\Composer\vendor\bin in the environment variables path.

Once you installed the library and set the PATH, we can check if WP-CLI installed correctly by the command:

wp --info

You should see output something like below.

WP-CLI Info

Install WordPress with WP-CLI

We have set up a WP-CLI on our system. Now lets install and setup WordPress with WP-CLI. We will create a WordPress project ‘wpcli’. At first, we need to download the latest WordPress files and folders in our ‘wpcli’ directory.

Below command will create a directory ‘wpcli’ and download the latest WordPress in it.

wp core download --path=wpcli

Navigate to ‘wpcli’ directory through cd wpcli. We need to create a wp-config.php file. So we shoot the command:

wp config create --dbname=wpcli --dbuser=DB_USERNAME --dbpass=DB_PASSWORD

In this command, we passed DB name as ‘wpcli’. Of course, we have not created database yet. WP-CLI will handle it in later commands. In our case, our database username is ‘root’ and password is empty. So our command would become:

wp config create --dbname=wpcli --dbuser=root --dbpass=

You can notice wp-config.php file created in your project root directory. Next thing is creating a database with the credentials passed in the config file.

wp db create

If you go to your phpMyAdmin then you will see the new database ‘wpcli’ get created. At this point, this is an empty database. We don’t have any tables yet.

We all set to install and setup WordPress now. In the below command we will pass our basic details like project URL, project title, admin username, admin password and admin email.

wp core install --url=http://localhost/wpcli --title="WordPress" --admin_user=admin --admin_password=admin?123 --admin_email=wp@test.com

Above command will create all core tables in WordPress database and finish your WordPress installation. Open the browser and run the URL http://localhost/wpcli you should see your WordPress website’s homepage.

We hope you understand how to install WordPress with WP-CLI. You may also like to see our article How To Manage WordPress Website Using WP-CLI. Please share you thoughts in the comment section below.

If you liked this article, then please subscribe to our YouTube Channel for video tutorials.

Leave a Reply

Your email address will not be published. Required fields are marked *