How to Install WordPress using a Managed Database on CentOS 7

WordPress is a simple content management system based on PHP and MySQL. It is estimated that about one-third of the sites on the internet run on WordPress. WordPress has many features which simplify the setup and customization of a website or blog, which is part of what makes it so popular. In addition to it’s ease of use, there are many plugins that can add additional features. This guide will walk you through a quick and easy install of WordPress, but in this case we’ll be using a SpinUp Database separate from our web server, to allow us to scale easily in the future.

• A Cloud Server Running CentOS 7
• SSH Access as root or equally privileged user


Create the SpinUp Database

1) When logged into the SpinUp control panel, select ‘DATABASES’ from the left hand panel and click ‘Create’ on the next page.

2) You should now see a page with many fields and options for creating the database. For the configuration of WordPress, we recommend using MySQL 5.7, but all other options are subject to your needs. The more traffic your site will receive, the larger your database may need to be. Finish filling out the require information and press ‘SPINUP SINGLE INSTANCE’ at the bottom of the page.

3) Your database should now build and enter an ‘Active’ status when it has finished. Take note of the IP address provided, this is the IP address that we’ll direct the web server to to connect to the database.

4) At the bottom of the page you have the tab ‘Databases’. Under this tab we’ll need to create the individual databases that our WordPress site will connect to. For this article, we’ll create a database called ‘wordpress’. 

5) Next to ‘Databases’ there should be an option for ‘Users’. Select this and create a user for your database. This is the user wordpress will use to log into the database. For this guide, I’m using the username ‘wpadmin’.

Configure Web Server

This article assumes that while you have SSH access as root to your CentOS 7 VM, you’ve not made any other changes. So we’ll be going through the process of creating a sudo user, setting up LAMP, installing and configuring WordPress, and adjusting our firewall rules.

Creating the sudo user

Sudo users are beneficial because they would allow normal users to operate within the server as if they were a root user. This section of the guide will take you through setting up a sudo user.

1) Log into your server as the root user over SSH and run the following command to create a new user. Replace ‘spinupbob’ with the username you want created.

# adduser spinupbob

2) Next, run the following command to set the password for our newly created user:

# passwd spinupbob

You’ll be prompted twice for the password, and like when you log into SSH, you’ll see no feedback for characters entered as the password.

3) Once you are returned to the command line, it’s time to add our new user to the group which has sudo privileges. In CentOS there is always a ‘wheel’ group that provides sudo privileges to any users within it.

# usermod -aG wheel spinupbob

4) Now, you can use the su command to switch to our new user so that we can test their sudo access:

# su - spinupbob

You can try running a command now, but when using a sudo user, you will have to prepend all your commands with ‘sudo’. Example:

# sudo ls -lah

If this is the first time you’ve used sudo in a session, you’ll be required to enter your password for the account you’re sudo’ing as. Once you’ve entered the password the command should proceed and provide the output.

Setting up the LAMP stack

LAMP is an acronym for Linux, Apache, MySQL, PHP. These are all requirements for a WordPress server, and this part of the guide will go through installing and making the necessary configurations.

1) First, we will need to enable the Remi repository. The Remi Repo is a repository maintained by Remi Collet, and is used to provide a variety of up-to-date packages. Run the following command to install and enable the repository within our server.

# sudo yum -y install

2) WordPress recommends that we use PHP version 7.3 or above, so we will adjust our remi-repo to exclude the older php version(s). The easiest way to do this is to utilize the yum-utils package, which allows easy changes to our repos. Run the following commands to install yum-utils, and then disable php54 in favor of php73:

# sudo yum install yum-utils
# sudo yum-config-manager --disable remi-php54
# sudo yum-config-manager --enable remi-php73

3) Now that we’ve adjusted our repository, we can download all the software required for LAMP and php features that WordPress will require. The following command strings together a list of packages we’ll install.

# sudo yum install httpd mariadb mariadb-server php php-common php-mysql php-gd php-xml php-mbstring php-mcrypt

You’ll be prompted a few times to enter Yes(y) or No(n) as the packages are installed. Press Y to install them.

4) Now that the installations have finished, we’ll start up and secure our MySQL installation. Use the following commands to start and then begin the securing:

# sudo systemctl start mariadb
# sudo mysql_secure_installation

After running mysql_Secure_installation, you’ll be prompted with instructions for configuring your MySQL install. It will first ask for a root password, and since this is our first time running MySQL we won’t have one, so you can press ENTER and it will prompt you for whether you’d like to add a password for the root user, which is recommended. Continue following along with the instructions in the prompts until you’re returned to the normal server command prompt and then run this command to ensure that MySQL starts automatically on boot up:

# sudo systemctl enable mariadb

5) Open the MySQL port in your firewall so that we can establish a connection with your Cloud Database later:

# sudo firewall-cmd --add-service=mysql --permanent

6) We’ll also need apache, our web service, running in order to display our WordPress site and accept our connection. Use the following commands to start apache and set it to start on boot:

# sudo systemctl start httpd
# sudo systemctl enable httpd

Now our LAMP stack is all setup and ready to serve WordPress once we install it.

Installing and Configuring WordPress

1) To install WordPress, we first need to download the package that contains all the necessary files. It’s recommended that we move to our temporary directory to download the tar file. We’ll then use the wget command to download the package from the URL provided by WordPress:

# sudo cd /tmp
# sudo wget

2) Now that we’ve downloaded the package, we will want to extract it and place it in our apache web directory:

# sudo tar -xvzf latest.tar.gz -C /var/www/html

3) Now that we’ve created a wordpress folder at /var/www/html/wordpress, we will want to allow apache ownership of that folder. We’ll use this command to make that change:

# chown -R apache /var/www/html/wordpress

4) While configuring a vhost to serve WordPress is not required, it will it easier to add more sites in the future if necessary. To setup our vhost, we’ll have to open the /etc/httpd/conf/httpd.conf file with a text editor. Once the file is opened, add the following code to the end of your file, but be sure to change the fields to match your own site’s hostname and name log files. In our case, we’ll be using as the example.

  DocumentRoot /var/www/html/wordpress
  ErrorLog /var/log/httpd/wordpressspinup-error-log
  CustomLog /var/log/httpd/wordpressspinup-acces-log common

Be sure to save the file upon exit.

5) Now open port 80 for apache so that it can listen for requests over the web:

# sudo firewall-cmd --add-service=http --permanent

Configuring the WordPress Install

Our final task is to configure our WordPress install to use our SpinUp Database. The following steps will quickly guide you through this.

1) Navigate to the wordpress directory:

# sudo cd /var/www/html/wordpress

2) Within this directory, WordPress provides a sample config file, but the easiest thing to do is just to rename it and then edit it to be a working config file. The following command will rename the config file:

# sudo mv wp-config-sample.php wp-config.php

3) Now we need to open the wp-config.php file with our text editor of choice. Once the file is opened you’ll see a following block of code:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );

/** MySQL database username */
define( 'DB_USER', 'username_here' );

/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

We’re interested in changed the ‘database_name_here’, ‘username_here’, ‘password_here’, and ‘localhost’ of this block of code. ‘database_name_here’, ‘username_here’, and ‘password_here’ need to be replaced with the matching values that you used when creating your SpinUp database. The ‘localhost’ will need to be replaced with the IP or hostname of your database. 

Once these changes are made, it should resemble something like this:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** MySQL database username */
define( 'DB_USER', 'wpadmin' );

/** MySQL database password */
define( 'DB_PASSWORD', 'Password!' );

/** MySQL hostname */
define( 'DB_HOST', '' );

Also, add the following lines to the the file as well, and replace with your site’s URL. This will prevent you receiving 404 not found and WordPress trying to redirect you to using your server’s IP address.

define('WP_SITEURL', '');
define('WP_HOME', '');

Save the file upon exit. 

The final thing we’ll do is restart apache, and reload our firewall rules:

# sudo systemctl restart httpd
# sudo firewall-cmd --reload

Now, when you navigate to you should be greeted with with a WordPress Login page. Enter the username of the user you created on your server, and their password. You should now be passed into the WordPress Dashboard where you can begin configuring and customizing your WordPress site.

Leave a Reply

Your email address will not be published. Required fields are marked *