Installing WordPress – Database creation and configuration

This article follows on from the last article I wrote and continues the theme of installing the wordpress software on your server. In the last article we dealt with downloading the software and installing it on the server – this article deals with wordpress database creation; setting up the database for wordpress and editing the configuration file so that WordPress can connect to the database.

WordPress Database Creation and Configuration

As with the last article I’m going to make some assumptions but they are not huge assumptions. Since it is a requirement of WordPress that you have an SQL database and currently wordpress only runs with MySQL or MariaDB (which is a fork of MySQL), I’ll assume that you have MySQL installed on your server environment (or development laptop if that is what you are using). I’ll also assume that you have the credentials of an account which has permission to create databases and users.

Later, I’m going to write an article on setting up a digital ocean server from scratch so if you need help with that, come back in a couple of weeks.

WordPress Database Creation

The first thing we need to do is log into the MySQL server and for that I tend to use the MySQL command line client. The command to log into the database using the command line client would be

In this case I am using a MySQL server which is running on the local machine and logging in as the root user. The -p option means I will be asked to supply the password as soon as I issue the command (hence the Enter Password prompt).

It’s possible, although unlikely, that you have a MySQL server running on another machine in which case you would supply the hostname after the -h parameter.

If the command is successful and you connect, you will be greeted with the MySQL login command prompt.

The first thing we are going to do is create a database for our WordPress install and then a user and password to allow WordPress to use the database. Before we do that however I would suggest a bit of house keeping.

I’ve found over the years when I’ve created blogs or other sites, that the easiest thing in the world is to just go through the commands and set everything up with the full intention of making a note somewhere of the usernames and passwords you have used, only to find that you forget to do it. It’s even easy to convince yourself that you don’t need to make a note because all the information will be copied into the configuration file for WordPress and you can always read them from there. Well that may well be true, but I would still take the time to work out beforehand what username, password and database name you are going to use and write them somewhere securely before you start. A system like Lastpass is brilliant for this and will solve a lot of problems in the future if you have recorded this information.

Also be aware that your install of mysql could have been enabled to require passwords with high security, in which case you may need to ensure you use punctuation characters in the password and / or capitals, or mixed case and numbers.

Anyway, back to the database. The following shows the commands I use to create the database and user required to access WordPress, along with the expected response from MySQL.

Obviously you would need to use the values for database (‘my-site’ in the example), username (‘mysite_user’ in the example) and password (‘my-secret-password’ in the example) which you have decided on.

As a check that the user and database connection works, it’s a good idea to disconnect from the database and try reconnecting with the new account.

WordPress Database Configuration

With the new database and user set up we are now in a position to use the database, username and password information to complete the configuration of the wordpress software we installed in the first part of this series. To do this we need to go to the wordpress directory which got created when we untarred the wordpress install archive, and add the parameters to the configuration file.

On my install I’ve created a directory for my new site at /usr/local/sites/my-site-name.co.uk so I cd to the wordpress directory within that directory

The configuration is held in a file called wp-config.php but that file isn’t supplied in the wordpress install. Instead there is a file called wp-config-sample.php which needs to be renamed and edited to make the install work.

In the last command above I’ve stared an editing command with the nano editor to change the parameters. I don’t particularly like nano, and personally I would use jed, but you can be pretty sure nano is installed on virtually every machine so it is safe to assume it is there.

Irrespective of the editor you use, the first section which needs to be altered is this one

It is fairly self explanatory which information goes into which php define, but once that is added there are a couple more entries which should be altered.

Further down the file is another entry which defines some random strings used for generating security hashes for form submission, site cookies etc and should be replaced with some unique values. You don’t need to think of these yourself however,  there is a generation service at https://api.wordpress.org/secret-key/1.1/salt/ which will generate a complete set of define statements ready to paste into the file in place of the existing default values.

The area of the file which needs to change is

Finally, if the site you are setting up is purely for development there is one other entry which should be changed which is

this should be set to true if the site is going to be used for development since it will allow useful warnings and debug messages to be displayed. Don’t set it to true for a production site however.

With those changes made the wp-config.php file can be saved and we are nearly ready to move to the next part of the install which is setting up a virtual web server configuration.

First however we should set the directory so it is readable by the web server software.

In the next part of this series I’ll cover setting up a virtual server configuration file for nginx and apache which are the two most popular web servers used on the Internet.

One Comment:

  1. Pingback:Installing wordpress - introduction and download — Develop with Wordpress

Leave a Reply