Use the command line tool to scaffold a wordpress site on windows

Pre-requirements

Make sure you have apache and phpmyadmin installed. You can download and install xampp here, which will provide you with both and more.

https://www.apachefriends.org/download.html

You will also need an internet connection.

This is easier if you use Linux, but if you prefer using Windows here is a quick guide.

Get wp-cli.phar

Follow the online instructions to get wp-cli.phar:

http://wp-cli.org/

If that doesn’t help try these alternative install methods:

https://github.com/wp-cli/wp-cli/wiki/Alternative-Install-Methods

Add the wp-cli.phar file to your system. I have a bin folder on Windows that I add any .phar files to.

C:\bin\wp-cli.phar

To run the wp-cli.phar on windows you will need to use the following command:

php [filepath]\wp-cli.phar

With [filepath]\ being the path to the location of your wp-cli.phar file.

Eg:

php C:\bin\wp-cli.phar

Check that the wp-cli.phar is working:

Run

php C:\bin\wp-cli.phar –info

Add a database

Go to your phpmyadmin, and add a blank database for your new wordpress to use. Typically your phpmyadmin will be here: http://localhost/phpmyadmin.

Just click on the “Databases” tab and create a new database called wp-test.

Add the mysql.exe filepath to your environment variables so that the command line can run mysql. You also need to have the php.exe filepath in your evironment variables;

Eg I added the below to my PATH variable in my evironment variables:

mysql

C:\xampp\mysql\bin;

php

C:\xampp\php;

Remember to separate each file path with a semicolon ;.

Read this post if you need to learn how to add to your environment variables.

Change to your wordpress directory

Go to the directory you want to add wordpress to. This will need to be on a server like apache. If you have xampp installed add wordpress in the htdocs folder.

Eg

cd C:\xampp\htdocs\wordpress\

This can be in any directory you like, just create the directory you want to install in and make sure you are in that directory in your command line.

Download wordpress using the command line

Step 1. Now that you have wp-cli.phar working download wordpress.

Run

php C:\bin\wp-cli.phar core download

The bonus of this approach is if you have already downloaded wordpress it will be cached on your system and the system will use that cached copy to install. You do not need to download it every time.

Setup the wp-config.php

Step 2. Every wordpress installation needs a wp-config.php file. Run the below to create the file.

Run

php C:\bin\wp-cli.phar core config –dbname=[db name] –dbuser=[db user] –dbpass=[db pass]

Eg

php C:\bin\wp-cli.phar core config –dbname=wp-test –dbuser=root

I have left out the –dbpass as I don’t have a password. By default in phpmyadmin the user name will be root and the password blank.

Getting an error?

If you get this error, you need to check that you have the mysql.exe location in your environment variables.

Error:
‘mysql’ is not recognized as an internal or external command, operable program or batch file.

You need to open a new command line instance in order to use the environment variable. You won’t be able use the mysql path reference in the same command line window.

Set wordpress up

Step 3. This is where you add in your admin user details and database details.

Run

php C:\bin\wp-cli.phar core install –title=’Test’ –admin_user=[your user name] –admin_password=[your password] –admin_email=[your email]  –url=[your wordpress url]

Eg

php C:\bin\wp-cli.phar core install –title=’Test’ –admin_user=admin –admin_password=securepassword –[email protected]  –url=http://localhost/wordpress/

Done.

You now have the ability to get wordpress up and running through the command line.