4 MINUTE READ | April 1, 2012
How to Install 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.
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.
Next up, we need to actually get WordPress. I like to set up my server directories like this:
WordPress goes here
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
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
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
htdocs latest.tar.gz wp-config.php
$ 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
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.
AlliPMG CultureCampaigns & Client WorkCompany NewsDigital MarketingData & Technology
4 MINUTES READ | November 2, 2021
2 MINUTES READ | February 4, 2020