How do I install WordPress from the CLI?

Last updated: March 28, 2011

Installing wordpress from a command line interface is done in four easy parts. We will walk you through each and explain what we do and why for each step.

1) Get the files onto your server.
2) Set up the database.
3) Modify the config file.
4) Run the installer from a browser.

1) Get the files onto your server.

cd to the directory you wish to install. For our example we will use the default apache document root.

# cd /var/www/html

Get the archive from the wordpress server.

# wget http://wordpress.org/latest.tar.gz

Unpack the archive.

# tar xvfz latest.tar.gz

You will now have all the wordpress files in a directory called wordpress in your web root.

Optional: If you wish to run wordpress from a subdirectory you can leave it as is or rename the wordpress directory to something you wish such as blog.

# mv wordpress blog

If you want to run wordpress from your web root you will need to move the files in wordpress up to the html directory.

If you already have files of the same name in your web root they may be overwritten.

# mv /var/www/html/wordpress/* /var/www/html/wordpress/.??* /var/www/html/

Then delete the empty wordpress directory

# rmdir /var/www/html/wordpress

2) Set up the database.

Enter MySQL

# mysql

Create the database.

mysql> CREATE DATABASE databasename;

Create MySQL user for this database.

First enter the mysql database:

mysql> use mysql;

Then add the new user:

mysql> CREATE USER 'newusername'@'localhost' IDENTIFIED BY 'uniquepassword';

Now grant privileges to that user for the new database:

mysql> GRANT ALL PRIVILEGES ON databasename.* TO 'newusername'@'localhost' WITH GRANT OPTION;

Now use the flush command to reload the privileges for your new user:

mysql> FLUSH PRIVILEGES;

3) Modify the config file.

Edit the wordpress config file with the database, database user and the database user's password information you just created.

# vi /location/of/your/wordpress/install/wp-config.php

Change these lines:

define('DB_NAME', 'databasename'); // The name of the database
define('DB_USER', 'newusername'); // Your MySQL username
define('DB_PASSWORD', 'uniquepassword'); // ...and password

Save the file.

4) Run the installer from a browser.

Now point a browser to the domain and to the install.php location:

example.com/wp-admin/install.php

If you installed in a folder with a name like blog then the install page will be here:

example.com/blog/wp-admin/install.php

Go to that page in a browser.

You should see the WordPress installation configuration page.

Enter your Site's title.

Enter your Username. This will be a unique name and will be the initial admin for the site. (Does not need to be the same as any other username you used to get this far)

Enter a password twice. Make it a good one as people will likely get in if you use a simple one.

Enter your email address.

Click the Install Wordpress button.

If all went well and you did everything correctly you will presented with a Success! page and a login button.

Now comes the part we can't help you with and that's filling your site with great content!

Tags: cli, cms, install