;

How to Install WordPress on CentOS 7

Try it in our public cloud & Get $5 Credit
CLAIM NOW

WordPress (WP) is one of the most popular content management system, powering an estimated 25% of the web. Part of this popularity stems from its ease of installation. If you’re looking to launch it on your CentOS 7 server, you’ve come to the right place.

Getting Started with WordPress

To complete this guide, you will need the following:
• 1 Node (Cloud Server or Dedicated Server) with CentOS 7 and a LAMP setup previously installed.

If you don't want to go through the whole installation of WordPress on your CentOS 7 server, you can always try our One-Click Apps and get a new WordPress in seconds.

Tutorial

Let’s get started. First we’ll create WordPress’ database. In these examples we’ll use “wordpress” as the database name, “wpuser” for the user and “wppassword” as the password. Please change the username and password to something unique and strong, otherwise anyone who reads this tutorial will know how to access your database. First, access MariaDB with your database root credentials:

mysql -u root -p

Next, let’s create the database where WP will store its content.

MariaDB > CREATE DATABASE wordpress;

We now need a user and password for the database. These credentials are for MariaDB only, and are not how you will access your site in later steps.

MariaDB > CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'wppassword';

The created credentials now need the privileges necessary to update the database. We’ll assign those here.
MariaDB > GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';

We’ve created the privileges, but they must now be confirmed and saved to the database in order to take effect.
FLUSH PRIVILEGES;

Great, you’ve successfully set up the database. Let’s exit and begin setting up WordPress’ PHP scripts.
MariaDB > exit

Start by retrieving the latest distribution. Fortunately, the latest download is stored at a permanent URL that is easy to retrieve.

cd /root
wget http://wordpress.org/latest.tar.gz

Now we’ll unzip the file. This will create a WordPress directory in which we’ll need to perform a few steps.

tar -zxvf latest.tar.gz

WordPress requires a few non-standard PHP modules that aren’t enabled by default in CentOS. Let’s install and activate them.

yum install php-gd php-mbstring

All necessary PHP modules are now available and active, but Apache needs to be restarted to take advantage of the new capabilities.

systemctl restart httpd.service

Great. We’re now ready to start setting up WordPress’ scripts to run under Apache. Let’s place them in Apache’s document root so it knows where to find them.

cd wordpress
cp * -R /var/www/html/

Next we need an uploads directory, where any content uploaded by users and administrators is stored.

mkdir /var/www/html/wp-content/uploads
chmod 775 /var/www/html/wp-content/uploads

Let’s now give Apache permission to read and write to its document root. This will enable plugin installation and upgrades.

chown -R apache. /var/www/html/*

The WP files are now in place, so next we’ll need to tell it how to connect to the database. We’ll do that by entering the root directory.

cd /var/www/html/

Take a backup of the default configuration in case you make any mistakes.

cp wp-config-sample.php wp-config.php

It’s now time to set the database credentials. Do so by editing the wp-config.php file, replacing “wpuser” and “wppassword” with the database user and password set up in previous steps.

nano wp-config.php
// ** 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', 'wpuser');
/** MySQL database password */
define('DB_PASSWORD', 'wppassword');

Save the file. You’ve just recorded database access credentials in a file that can be accessed over the web. To prevent that, let’s edit the .htaccess file to block this plus a few other common attacks.

cd /var/www/html/
nano .htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

We’re almost done. Save the file, and continue the installation by accessing WordPress’ web-based installer. Visit http://your_main_ip to start the process.

First, select your default language. Next, set a site title. Set an administrative username, a strong password and enter your email address. Don’t choose usernames like “admin,” “webmaster” or “root” that an attacker might guess. Also be sure to use a strong password.

You can now access your site with the username and password you just entered. Simply visit http://your_main_ip and start adding content!

Conclusion

Congratulations! You’ve gone from a pristine new server to a sophisticated website hosting platform in just a few minutes of work. Enjoy adding posts and pages to your brand new site. If this guide was helpful to you, kindly share it with others who may also be interested.