Instaling WordPress From the Command Line – Just for Fun

Today I decided to do a fun exercise. Lets install wordpress entirely from the command line. We will download wordpress, unzip it, and create the database and user, all from the command line.

Downloading and Setting Up wordpress

To download wordpress we are going to use wget.
wget is a non-interactive network downloader. It is a pretty neat tool. If you have never used it, I recommend you read the man page for it, and to give it a try.

In order to download wordpress we need to run the following command:

wget http://wordpress.org/latest.zip

Be sure to be on the directory in which you want wordpress to be downloaded. In my case I’m using my in-house server, so I have access to all of it. I download everything to the Downloads directory.

Once wget is finished downloading wordpress you should have a new zip file named latest.zip. We need to unzip this file:

unzip latest.zip

This will extract the zipped files. You should end up with a newly created wordpress directory. Remember that at this point I am still on the Downloads directory, so I need to move the wordpress directory to public_html, which is the directory that apache uses as root. I will also change the name of the newly created wordpress directory to something more meaningful. Since I will be using this installation to develop a theme, I will just name it as the theme:

mv wordpress/ ../public_html/cafe

We are done with this step. Now we need to create the database and mysql user for this installation of wordpress.

Creating MySQL Database and User

We need to start mysql cli in order to create the database and user:

mysql -u user_name -p

user_name is the user name that you use to connect to your MySQL server. You will be required to enter your password. Once you do, you will be logged into the MySQL server and you will be able to run commands.

Creating the Database

Creating the database is simple:
CREATE DATABASE databasename;
You will need to change database for the name you want to give to your database.

Creating the User

Creating the user is also very simple:
CREATE USER 'user'@'localhost' IDENTIFIED BY 'passwd';
You need to change user for the user name you want to use. If you will be accessing the database from a different server, then change localhost for the host name that from which you will be accessing the database.

Now we need to grant the newly created user enough privileges to manage the database:

GRANT ALL PRIVILEGES ON databasename.* TO 'user'@'localhost';

Since this is just an exercise, we are granting all privileges. On a production site, you may want to not do this, and just grant enough privileges to the user so it can function properly.

Lastly, edit the wp-config.php file, and add the database and user information.

We are done. All that is left to do is run the wordpress installation program. Just use your browser to navigate to your wordpress installation, and install wordpress as you usually do.

Some reads you may be interested on:

http://dev.mysql.com/doc/refman/5.1/en/adding-users.html
http://dev.mysql.com/doc/refman/5.5/en/creating-database.html

3 thoughts on “Instaling WordPress From the Command Line – Just for Fun

  1. After looking at a handful of the blog posts on your website, I truly like your technique of
    blogging. I book-marked it to my bookmark
    website list and will be checking back in the near
    future. Take a look at my website as well and tell me what you think.

Comments are closed.