June 28, 2010

WordPress 3.0 installation from a command line

Many of use have been in that slow situation where you must download the zip of WordPress, unzip it, and then FTP it to your web host. Today I bring gifts to those who have shell access, installation from the command line. I will give you all of the neat commands, and even a script to reduce the keyboard work.

Start by creating a database for WordPress to run on.

Log in via shell you your web hosting account and execute the following commands with your own parameters for database name, user name, and password:
mysql
create database db_name_of_choice
GRANT USAGE ON db_name_of_choice.* to db_user_of_choice@localhost IDENTIFIED BY 'db_passwd_of_choice';
GRANT ALL ON db_name_of_choice.* to db_user_of_choice@localhost;

Write a WordPress install file.

From the folder you would like to install WordPress into, execute the following command:
vi installWP.sh

Copy+Pasting with VIM can be accomplished using the following key commands:
Press "a" to allow for text entry in VIM.
Press CTRL+V to paste the following lines of code into VIM.

Now copy+paste the following commands in:
wget http://www.wordpress.org/latest.zip
unzip latest.zip
cd wordpress
mv * ../
cd ..
rm -R wordpress/
echo "### Removing latest.zip install files ###"
rm -R latest.zip
mv wp-config-sample.php wp-config.php
echo DONE!

Now save the file
ESC
Press SHIFT+":"
type: wq!
Press RETURN/ENTER

Run the install file.

Change the permissions on installWP.sh so it can run as a shell script.
chmod 755 installWP.sh

Now run installWP.sh
./installWP.sh

Setting the database settings in wp-config.php.

With WordPress now downloaded, and extracted from the zip file we need to configure our database name, user name, and password in the wp-config.php file.
vi wp-config.php

Find the following lines, and add your database settings from before:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'db_name_of_choice');
/** MySQL database username */
define('DB_USER', 'db_user');
/** MySQL database password */
define('DB_PASSWORD', 'db_passwd');

Key VI Commands
Press "a" to allow for text entry in VIM.
ESC to exit text entry.
Press SHIFT+":" to run save or exit commands
type: wq! to write the file, and quite.
Press RETURN/ENTER

Installation complete!

The WordPress application is now setup, and is ready for in-browser configuration. Browse to the location where you installed WordPress and you should see the following screen.

Wordpress 3 Install

Answer a few configuration questions and you will be up and running.

~Nathan Hein