How to Install WordPress with LAMP on CentOS 7 server

2017-07-07 By Tarun 7433 Views linux centos cms_application wordpress
2 reviews

Introduction

WordPress is a widely-used CMS tool for blogging and building open-source websites that rely on PHP and MySQL programming languages. Its high-end flexibility has gained it worldwide recognition with more than 20,000 plugins actively running for developers and consumers. With such freedom in workability, it is one of the most preferable choices among users globally.

Being open-source, developers can set up WP on a number of OS systems. One of them is the famous Linux distribution OS comprising of a number of software known as CentOS. With the current version, which is CentOS 7, developers have been looking forward to using WordPress on their Linux distribution system as well. The procedure is, however, not as simple as for other common operating systems. So, this guide will help anyone in need of such a tutorial to get familiar with the technique.

Initial Requirements:

Prior to starting with the guide, there are certain requirements that are to be fulfilled.

Firstly, there is a need for installing CentOS 7 server that has a non-root user's configuration accompanied with sudo benefits. Furthermore, you would require a LAMP (Linux, MySQL, and PHP) stack on the CentOS 7 server. Install the stack on your server and move on to the next step to installing WordPress.

1) Setting Up Database for MySQL and WordPress

Your first step would be to set up the information for both databases. While MySQL already has an installed one by the name of MariaDB, WordPress will require a user and database so that it can work with the system.

For this, you will need to log into the administrative account of MySQL with the help of the command:

mysql -u root -p

You will then need to enter the password that you used for the administrator account while installing MySQL. After entering the password, you will have access to the MySQL command prompt. Now, our first step will be to create a database that WP is able to control. You can name it as per your freewill, but for this tutorial, we will call it WordPress.

CREATE DATABASE wordpress;

Your next step is to create a MySQL account that is going to be used with the WordPress database, exclusively. This is to have better access to the permissions and other security-based aspects. Let us call this account as wordpressuser that will be accessed through a password named, password. Make sure you use a secure name and password that are not easy to crack by other users.

CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';

By now, you are having a user account and database that are exclusively made for WordPress. But, as you can see that the user still does not have any access to the database, so we will have to join the two by providing access for the users to the database. This can be done using the below-mentioned command.

GRANT ALL PRIVILEGES ON WordPress.* TO wordpressuser@localhost IDENTIFIED BY 'password';

Once the user has acquired access to the database, you will have to flush the privileges in order for MySQL to know about the updates made by you.

FLUSH PRIVILEGES;

After executing these commands, you can exit the MySQL command prompt through the command:

exit

This should bring you back to the usual SSH command prompt.

2)Installing WordPress

Prior to downloading WordPress, there is a PHP module that you should install so that the whole process works flawlessly. Moreover, if you are not installing the particular PHP module, then you will have a problem resizing the images for thumbnail creation. This package can be accessed directly from the default repositories in CentOS using yum. Here is the command:

sudo yum install php-gd

After this, you will need to reboot the Apache server for it to accept the new module:

sudo service httpd restart

This brings us to the next step, which is downloading and installing WordPress. WordPress always offers the most recent update of their CMS tool through the link, so it reduces the effort to find the most stable version. This can be done by typing:

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

This downloads a compressed version of an archive file that comprises all the WP files required. You can extract these files to form the WP directory with this command:

tar xzvf latest.tar.gz

With this step, you have formed a new directory named, WordPress added to the home directory. Now, you can finish the setup by sending the unpacked files to the document root of Apache, where the visitors to your website will be served with these files. You can also relocate your WP files there using rsync, which will keep the default permissions of the files intact.

sudo rsync -avP ~/wordpress/ /var/www/html/

rysnc will let you copy all the content securely from the unpacked directory to the root directory /var/www/html/. But, there is still a need to generate a folder for WP so that it can store uploaded files. This can be done by using the command:

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

With this step done, you will now move on to assigning the permissions and ownership to the WP files. This is intended for increasing safety while still letting WordPress perform its functions without compromises. This is done using the command:

sudo chown -R apache:apache /var/www/html/*

After this change, your web server will have access to modify and create WP files and will also let you upload new content to the CentOS 7 server.

3) Configuring WP

While the configuration part for WP can be completed using the web UI at later stages, there is still some work to be done using the command prompt so that MySQL and WordPress are linked together. This can be done by firstly accessing the Apache's root directory where the WP files were installed:

cd /var/www/html

Many developers are familiar with the file, wp-config.php on which WordPress heavily relies. Here, you will need a sample config file that uses the preferred settings by default. You just have to copy this file to the default config file location in order for WP to recognize the file and use it:

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

Once, the configuration file has been added, it is time to use it through the text editor:

nano wp-config.php

Now, all you need to modify in this file are the parameters that comprise the information related to the database. For this, you will need to locate the section named, MySQL settings and modify the variables, DB_NAME, DB_USER and DB_PASSWORD so that WordPress can safely link and authorize to the created database.

Now, add in fields of the parameters with the database-related information that you generated. This should resemble the following commands:

// ** 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', 'wordpressuser');

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

These are the only values that you need to change, so save and close the file when you are finished.

4) Installing using the Web UI

After adding the files to their respective locations and configuring your software, you are now ready to install WordPress using the web UI. For this, all you need to do is go to your public IP address or the domain name of the server:

http://server_domain_name_or_IP

Select your preferred language for installation of WP and click continue. This will take you to a configuration page, where you will add your administrator account.

Fill in the fields for your site and admin account details that you would like to have. Once done, just click the install WordPress button present at the bottom of the page to move on to the next step. This will prompt WP to authorize your installation. It will then ask you to log in with the generated details. Press Login and then fill in the details of your admin account. This will take you to your WP Dashboard.

Finally, you have successfully installed WP with LAMP on your CentOS 7 server.

What do you think about this article?

Rate this article
LayerStack Promotion
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.