Tek Eye Logo

Tek Eye

Setup WordPress on CentOS 7 for a Website

This tutorial covers setting up WordPress on a CentOS 7 system. WordPress is a Content Management System (CMS) which is used to make it easy to publish and maintain a website. WordPress is the most popular of the CMSs and is used in 25% of the Worlds's websites and dominates the CMS market with over 50% market share.

WordPress Logo

The popularity of WordPress means that nearly all web hosting providers support it and provide easy install options. The control panel for the web hosting service normally has an option to install WordPress. If not a manual install is usually straightforward. A web hosting company will normally have online help to show how to setup wordpress on their hosting plans. For a self-managed dedicated server or Virtual Private Server (VPS) the setup requires several steps to be completed. In this article WordPress is setup on a CentOS 7 system using a VirtualBox virtual machine (VM) for testing purposes. A test set up replicating a live server allows changes to be tried out before deployment. Similar steps apply to the setup of WordPress on a live VPS or dedicated server.

CentOS Logo

WordPress Pre-Setup Requirements

Before installing WordPress on a CentOS 7 VM, VPS or dedicated server ensure that the CentOS system is ready. This requires that the CentOS system has a web server running, normally Apache, has PHP installed and working, and has a database server running, normally MySQL or MariaDB. This is called a LAMP stack with LAMP standing for Linux Apache MySQL PHP. Here CentOS is the GNU/Linux being used. See the following articles if you need to configure Apache, MySQL and PHP:

WordPress also requires the support of URL rewriting in the Apache .htaccess files. This ensures that the web address a visitor types into a browser gets correctly processed by WordPress. Recent versions of Apache turn off running rules in .htaccess files. See this article:

For a CentOS 7 VM, VPS or dedicated server it is assumed that command line (shell) access is available, usually via SSH. An example of using SSH to access a minimal CentOS 7 VM is covered in this article:

Prepare MySQL/MariaDB for WordPress

WordPress will require a database name, a user name for the database, and a secure password. Think about the values to use. For this article the values are:

  • Database name = wpdb
  • Wordpress database user name = wpdbadmin
  • Wordpress database password = wppw2015 (not very secure so choose your own longer password)

Login to the web serve and run the mysql utility, using the database root password:

# mysql -u root -p

Create the WordPress database:


Create the WordPress database user:

> CREATE USER wpdbadmin@localhost IDENTIFIED BY "wppw2015";

Give the WordPress user name access to the WordPress database then flush and exit the MySQL utility:

> GRANT ALL PRIVILEGES ON wpdb.* TO wpdbadmin@localhost;

Get the WordPress Files

Here the default Apache public web folder is used. If another directory has been configured for the web site use that directory. Change to the directory that will hold the web files:

# cd /var/www/html

Get the compressed WordPress files (if wget is not installed then get it with yum install wget):

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

Extract the WordPress files from the wordpress folder in the download:

# tar -xzvf latest.tar.gz --strip-components=1

Rename the configuration file from wp-config-sample.php to wp-config.php:

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

Edit the wp-config.php in vi or nano to set the correct database values:

# vi wp-config.php

(For vi use i to enter insert mode and escape to leave it. Use :wq to write the file and quit.) Or:

# nano wp-config.php

(Ctrl-O writes the file and Ctrl-X exits in nano.) Change the database entries for DB_NAME, DB_USER, DB_PASSWORD.

WordPress Database Settings in wp-config.php

Now point the browser at the WordPress install.php script in the wp-admin directory, e.g. example.com/wp-admin/install.php. In this tutorial accessing the script in the VM used the address localhost:8000/wp-admin/install.php in the browser. If a page is display with Error establishing a database connection then check the database settings in the wp-config.php file before seeking help on the WordPress installation support forum:

WordPress First Install Page

Complete the installation fields for the first administrator of the WordPress based website. Make a note of the details for safe keeping. Click the Install WordPress button and a Success page should display:

WordPress Successfully Installed

Press the Login button to be taken to the normal WordPress login address, e.g. example.com/wp-login.php or for the VM used here localhost:8000/wp-login.php:

WordPress Login Page

Once logged in to the WordPress dashboard website pages and posts can be created and the website managed.

WordPress Dashboard

To configure settings, plugins and allow media (images, videos and audio) to be uploaded to WordPress the ownership of the wp-content directory may need changing. Back in the /var/www/html directory use the chown command to change the ownership on the wp-content folder. Here it is assumed that the default Apache web server install is running under the apache owner and the apache group:

# chown -R apache:apache wp-content

If you need to check the Apache user:

# ps aux | grep apache

The user name is in the first column, then use groups:

# groups apache
apache : apache

Alternatively instead of changing the directory owner use weak permissions for testing purposes (not recommended for live servers):

# chmod 777 wp-content

Author:  Published:  Updated:  

markdown CMS Small Logo Icon ↓markdown↓ CMS is fast and simple. Build websites quickly and publish easily. For beginner to expert.

Articles on:

Android, HTML, ↓markdown↓ CMS, VPS, Computing, Computer History