This website uses cookies to ensure you get the best possible experience. See our Cookies Policy.

PMG Digital Made for Humans

How to Install WordPress from the Command Line

4 MINUTE READ | April 1, 2012

How to Install WordPress from the Command Line

Installing WordPress from the Command Line

I love working on the command line: editors, database clients, anything. If your know what you’re doing, it’s fast and efficient. One that happens quite frequently is installing WordPress completely from the command line – over SSH or just creating another install on my local machine.

This tutorial will show you how to do the same.

You’re dealing with a server or machine that has a HTTP server, PHP, and MySQL installed. This tutorial won’t cover server setup, just getting WordPress up and running from the command line.

The hardware & software I’m using to run the commands for this article: Mac Pro running OSX Lion, Nginx 1.0.13, PHP 5.3.10 (using PHP-FPM), and MySQL 5.5.20.

Assuming your MySQL server has been started, we need to connect with it via the mysql command line tool. Run this command, substituting <user> for your MySQL username and <password> for that user’s password.

$ mysql -u <user> -p <password>

This should drop you into the mysql shell and you’ll see a prompt like this: mysql> . First up, we need to create a database user for our new WordPress installation.

mysql> CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'apassword';

This should create the user wpuser with the password apassword. Now we need to create a database for our new WordPress install.

mysql> CREATE DATABASE wordpressdb;

And now we need to give our wpuser permissions to use and update the newly created wordpressdb.

mysql> GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wpuser'@'localhost';

There’s also a shortcut here. We can create the user and grant privileges in one statement.

mysql> GRANT ALL ON wordpressdb.* TO 'anotheruser'@'localhost' IDENTIFIED BY 'somepass';

With that out of the way, you can exit the mysql shell by typing exit and hitting enter. You should see “Bye” and then return to your normal prompt.

mysql> 

exit Bye

 $

Next up, we need to actually get WordPress. I like to set up my server directories like this:

virtualhost/

wp-config.php

htdocs/

WordPress goes here

logs/

access.log

error.log

So cd into the virtual host directory. Then use wget (or cURL) to fetch the latest stable WordPress tarball. Finally use the tar command to decompress it.

$ cd ~/Sites/wpalt

# bunch of stuff gets spit out here at wget connects and downloads

$ tar -xzf latest.tar.gz

$ ls

latest.tar.gz   wordpress

The last command, ls lists the files in the current directory. We decompressed latest.tar.gz into the wordpress directory.

Now let’s move wordpress to htdocs (or whatever you’d like your server root to be – public_html is common, so is just html. If the server root folder already exists, you can remove it with rm. Just be careful.

$ mv wordpress htdocs

$ ls

htdocs      latest.tar.gz

With all that fun stuff out of the way, we can create our wp-config.php file. First, let’s move the default wp-config-sample.php out of the server root folder (htdocs for my example) to the virtual host directory. WordPress will look for the file in both places and it’s better to keep that sensitive information off the document root.

$ mv htdocs/wp-config-sample.php wp-config.php

$ ls

htdocs      latest.tar.gz   wp-config.php

From here on out, it’s just the typical 5 minute install. I use vim to edit wp-config.php, but you can use whatever command line editor you like.

$ vim wp-config.php

… do stuff!

The only thing worth noting is an additional security concern: the WordPress table prefix. This, at the time of writing, is on line 62 of the default wp-config-sample.php. Change this to something that isn’t the default wp_.

Stay in touch

Bringing news to you

Subscribe to our newsletter

The above is incredibly useful if you need to get WordPress installed very quickly or if you only have SSH access to a server. It’s also useful if you need to spin up multiple WordPress installs on your local machine.


Posted by Christopher Davis

Related Content

thumbnail image

Get Informed

PMG Innovation Challenge Inspires New Alli Technology Solutions

4 MINUTES READ | November 2, 2021

Get Informed

Applying Function Options to Domain Entities in Go

11 MINUTES READ | October 21, 2019

thumbnail image

Get Informed

My Experience Teaching Through Jupyter Notebooks

4 MINUTES READ | September 21, 2019

Get Informed

Trading Symfony’s Form Component for Data Transfer Objects

8 MINUTES READ | September 3, 2019

Get Inspired

Working with an Automation Mindset

5 MINUTES READ | August 22, 2019

Get Informed

Parsing Redshift Logs to Understand Data Usage

7 MINUTES READ | May 6, 2019

Get Inspired

3 Tips for Showing Value in the Tech You Build

5 MINUTES READ | April 24, 2019

thumbnail image

Get Informed

Testing React

13 MINUTES READ | March 12, 2019

Get Inspired

Tips for Designing & Testing Software Without a UX Specialist

4 MINUTES READ | March 6, 2019

Get Informed

A Beginner’s Experience with Terraform

4 MINUTES READ | December 20, 2018

ALL POSTS