How to install WordPress on CentOS 7 server

If you have a CentOS 7 server, you can easily install WordPress from the command line without additional hosting control panels. This is the manual for setting up the CentOS 7 operating system so that WordPress can work on it. This is what is written here, and what you can do using this manual:

Step 1 – Install Apache Web Server on CentOS 7
Step 2 – Install MySQL on CentOS 7, create a database and user for WordPress
Step 3 – Install PHP on CentOS 7
Step 4 – Install PHP modules on CentOS 7
Step 5 – Test PHP with info.php file
Step 6 – Install WordPress on CentOS 7 server
Step 7 – Set WordPress on CentOS 7 server

Note: This guide is for beginners and just answers the question How to install WordPress on CentOS 7 server. The guide does not contain steps to improve security on the CentOS 7 server.

Step 1 – Install Apache Web Server on CentOS 7

Apache Web Server is currently the most popular web server in the world. This makes it an excellent solution because of the community it gathers and the support that comes in this way. In order for your WordPress to work, you need to install this package as well. Connect to the server using the console and SSH connection first (here’s the instruction).

Type the following to install the web server:

yum install httpd

Start a web server with:

systemctl start httpd.service

Make sure that you are running a web server by typing the server’s IP address into your Internet browser. If you see the page from the image below, it means it works:

Set the web server to run together with the server. Type in the console next:

systemctl enable httpd.service

 

Step 2 – Install MySQL on CentOS 7, create a database and user for WordPress

In order to manage MySQL, we need to install the mysql-server package. This is possible on the CentOS 6 operating system, but not on CentOS 7. If you type a command to install the mysql-server package, you will receive the following:

[root@server ~]# yum install mysql-server
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 156 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 145 kB 00:00:00
(3/4): updates/7/x86_64/primary_db | 5.2 MB 00:00:01
(4/4): base/7/x86_64/primary_db | 5.7 MB 00:00:01
No package mysql-server available.
Error: Nothing to do
[root@server ~]#

Therefore, instead of the mysql-server package, we will install the mariadb-server package using the yum package installer:

yum install mariadb-server mariadb

It looks like this in the console:

If you, among these lines, notice the following:

Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.

you do not have to take steps to install the package that is listed here. It’s a package that’s useful if you have a slow internet connection. The deltarpm package works by comparing existing packages in the system and taking only the difference needed for updating – to save time on slow connections on computers.

After installation of the package, it is necessary to run MariaDB with the help of the following command:

systemctl start mariadb

Now that MySQL works, we can achieve a little bit better than the default. Type in the following:

mysql_secure_installation

When you enter the specified command in the console, you will be prompted for an existing MySQL password, since it’s just installed, you do not have a password, so it’s enough to press Enter on the keyboard. You will get a few more y/n questions, so you will not make a mistake if you press Enter for each question (selects the default setting).

It looks like this in console:

Set it now to start the MariaDB with the system:

systemctl enable mariadb.service

Log in to MySQL with the root privileges:

mysql -u root -p

Enter the password that you defined earlier (MySQL password) and create a new database by typing the following:

CREATE DATABASE wordpressdb1;

wordpressdb1 is the name of the new database that will be created.

Note: All MySQL commands should end with ; so keep this in mind if something does not work properly when trying to create a new database or user.

Now we need to create a new user for the database and define the password through which this user will access the database:

CREATE USER wpkorisnik@localhost IDENTIFIED BY 'LoZiNkA';

The wpkorisnik is the name of the new user, while LoZiNkA is the new password that the user will use.

In order for the new user to access the new database, they should now be connected by adding privileges:

GRANT ALL PRIVILEGES ON wordpressdb1.* TO wpkorisnik@localhost IDENTIFIED BY 'LoZiNkA';

Now it is necessary to update the privileges so that the new user can access and use the database:

FLUSH PRIVILEGES;

Finally, exit MySQL by typing the following:

exit

 

Step 3 – Install PHP on CentOS 7

To install PHP on CentOS 7, type the following:

yum install php php-mysql

Restart Apache Web Server:

systemctl restart httpd.service

 

Step 4 – Install the PHP modules on CentOS 7

Install the PHP modules:

yum install php-gd php-pdo php-pear php-pecl php-xml php-gd php-zlib

In the command line above, you can see examples of modules, it’s best to explore what you need for your WordPress site and install the necessary modules. To view all available PHP modules and libraries, type:

yum search php-

To get more information about a particular module, type the following (replace the package_name with the name of the package, for example php-pdo):

yum info package_name

 

Step 5 – Test PHP with the info.php file

Now we will test the server and check if PHP is properly set up. We will make an ordinary PHP file with a basic script that will call a particular page. We will place this file in the “web root” that is for CentOS 7 at the following location: /var/www/html/ so we are going to create the necessary test file:

vi /var/www/html/info.php

An empty file will open. Insert the following PHP code into this file:

<?php phpinfo(); ?>

Note: To save changes in Vi text editor, press the Esc key, then :  then that q

Visit the following address to see that the file that you set up calls the correct page (the page will print all PHP settings):

http://ip-of-your-server/info.php

If you see a page that begins as in the picture below, then everything is fine:

When you review and explore everything, you can delete this file by typing the following:

rm /var/www/html/info.php

 

Step 6 – Install WordPress on the CentOS 7 server

We will download the WordPress installation package from the official repository and unpack it. First, log in to the server via the console and SSH connection, then go into the working directory:

cd ~

Download WordPress using wget:

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

Unzip (untar) the downloaded archive:

tar xzvf latest.tar.gz

Here’s what it looks like in the console:

If you look at what is in your working directory, you will see that you now have one tar.gz archive and a folder called wordpress:

[root@server ~]# ll
total 8608
-rw-r--r-- 1 root   root  8807744 Jan 16 23:39 latest.tar.gz
drwxr-xr-x 5 nobody 65534    4096 Jan 16 23:39 wordpress

Now move all the WordPress files to the location from where the web server (Apache) will be able to serve them correctly. You can do the moving using rsync so that the permissions on the files are saved:

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

Add a directory where WordPress will store all the uploaded files:

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

Now set the correct permissions on the folders so that the web server can access, store and upload files correctly:

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

This completes the installation but does not set up the WordPress on the CentOS 7 server.

Step 7 – Setup WordPress on CentOS 7 Server

Switch to the directory where the WordPress installation is located:

cd /var/www/html

The default settings for WordPress are in the wp-config.php file, but this file still does not exist. We will make it from the file that already exists as an example and is called wp-config-sample.php:

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

Open this new file in the Nano text editor (if this text editor is not present, install it with yum install nano):

nano wp-config.php

We need to change only three rows, the database name, user for the base, and the password for the user:

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

Navigate through the Nano with the arrows on the keyboard. Enter the data and save it with the combination of the Ctrl + O key and then exit with the Ctrl + X key combination. From our example with database and user data we previously created, it looks like this:

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

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

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

To test whether everything is correct, just visit your server’s IP address. If you see this page, you did everything well:

Each next step is the classic installation of WordPress where you enter administrator data (username, password, email address):

Finally, the WordPress site will work on your IP address or on the domain that has an IP address for your server for an A record.

Other ways to install WordPress on the server

If this seems too complicated for you, a faster and much simpler solution is to use WHM/cPanel on your server. With the help of WHM/cPanel, you can easily create a database and users, add PHP modules, and make a file upload easy. You can also install WordPress in one click.

With each hosting company, you can easily rent a cPanel license with the server. If you lease a cPanel with us, you also get a free cPanel setup. If you have any additional questions or if you encounter difficulties with your server, feel free to contact us on the Adriahost contact page.

Tags: , , , , , ,

No comments yet.

Submit Comment