Select Page

This is a guide to preparing CentOS 6 Linux on the server so that WordPress can work on it. WordPress on CentOS can work without cPanel, PHPMyAdmin, everything is done from the console, and you will eventually need an Internet browser to install WordPress and check if it works.

We will see how to install Apache, MySQL, PHP, PHP extensions, how to run httpd and mysqld together with the server, how to modify the root password for MySQL, how to create the database and user from the console …

This instruction has educational purpose and is useful for those who want to deal with Linux administration. The guide does not contain steps to enhance security on the server environment or additional settings for better operation of the environment.

It assumes that you have already installed CentOS 6 operating system on your server. If you already use a server with the cPanel/WHM control panel, you do not need to do this in this way. If all of this is complicated for you, buy a cPanel/WHM license.

Step 1: Install and run Apache web server

To install Apache open the console, connect to the server using ssh connection and type the following command:

yum install httpd

After installation, be sure to run Apache by typing the following:

service httpd start

Here’s how it looks on the console:
apache

You can now check whether Apache works. Type the Internet address of your server in the Internet browser: http://12.34.56.789 You should get this page, if everything is fine:

apache test wordpress on centos

What is Apache?

Apache is currently the most used web server software. It’s open source software and it’s free. It was named after the original natives of America, the Apache tribe. Read more on Wikipedia.

What is a web server?

When someone in the Internet browser typed an address to a page, the web server comes in to first check the request, and then serve that page. Depending on the site, the web server can also invite other modules while generating a page that will serve to the visitor. At the same time, the web server also cares if these modules are ready-available before calling them.

Step 2: Install and run MySQL

Install MySQL now, open the console and type the following:

yum install mysql-server

Now run mysqld:

service mysqld start

It looks like this in the console:
mysql сервер инсталација

What is MySQL?

It is a management system for working with a database. It serves for better organization and use of data on the server.

What is mysqld?

mysqld is a MySQL server demon that runs in the background of the operating system. Calling this demon is actually starting a mysql server. Deactivating this demon, it also means shutdown of mysql server.

Step 3: Set the root password for MySQL

After installing MySQL, you need to set the root password for MySQL. Open the console that is connected to the server via SSH and type:

/usr/bin/mysql_secure_installation

An old password will be requested here:

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Since you just installed MySQL and do not have a password, just press Enter on the keyboard. You will also be prompted to enter a new password and set it (and remember or type it somewhere).

Before all is done you will have several more yes/no questions. If you are unsure and do not want to read, you will not make a mistake if you leave the default answers and press Enter every time.

Step 4: Install PHP

To install PHP on the server, open the console and type the following:

yum install php php-mysql

Here’s how it looks like in the console:

Step 5: Install PHP extensions

Depending on what you need to do on your WordPress, explore which PHP extensions-modules you need and install them.

Here’s an example of installing some modules:

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

Here’s how it looks like in the console:

Step 6: Let httpd and mysqld run together with the system

If you happen to restart the server, httpd and mysqld demons will not run on their own. You need to run them manually after each restart or enable it to run automatically after each server restart.

Open the console and type the following commands:

chkconfig httpd on
chkconfig mysqld on

chkconfign wordpress on centos

What does a chkconfig command do?

chkconfig updates and searches for “runlevel” information about system services. It can also be used to activate-deactivate the process. The on, off, or reset options change the settings associated with starting the system.

Step 7: Make sure PHP is working

You can now check whether PHP is running. Open the console and type the following to create a file that you later call through the Internet browser and see the PHP information:

nano /var/www/html/info.php

In the empty file that you opened for creation, insert the following:

<?php
phpinfo();
?>

Press Ctrl+O to save the entry and Ctrl+X to exit the text editor. Restart httpd:

service httpd restart

Here’s how it looks like in the console:

phpinfo centos 6

Finally, type in the Internet browser your server’s IP address and try to view the file you just created: http://12.34.56.789/info.php

If you receive this page, everything is fine and in this way you can read about the PHP settings that you have on your server:

Step 8: Download the latest version of WordPress

Connect to server using SSH connection. Then type the following command to download the latest version of WordPress:

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

If you have not used wget before, here’s how it looks in the console:

While you are still there, type in the following to unpack the archive you downloaded:

tar -xzvf latest.tar.gz

Step 9: Create a database and users

In order for WordPress to work, it is now necessary to create both a database and a user. Type the following to enter the MySQL shell:

mysql -u root -p

The password you set in step 3 will also be requested, then enter it.

Create a new database with the name as you wish. I put wordpress as an example:

CREATE DATABASE wordpress;

Make a user with a name as desired. In the example below, it is korisnik. Enter new user name before @localhost; :

CREATE USER korisnik@localhost;

Give the password for the new user. Instead of here-go-pass, type the password as you wish:

SET PASSWORD FOR korisnik@localhost= PASSWORD("here-go-pass");

Give all the privileges to the user:

GRANT ALL PRIVILEGES ON wordpress.* TO korisnik@localhost IDENTIFIED BY 'here-go-pass';

Refresh MySQL:

FLUSH PRIVILEGES;

Here’s how it looks in the console:

mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE USER user@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> SET PASSWORD FOR user@localhost= PASSWORD("password");
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON wordpress.* TO user@localhost IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit

We have finished work in this part. Let’s go back to WordPress with the files we downloaded and unpacked.

Step 10: Set WordPress

You must first create a new Configuration File for WordPress. This is done by copying the content of the wp-config-sample.php file to a file under another name wp-config.php:

cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php

After that, open this new file in the Vi text editor:

vi ~/wordpress/wp-config.php

Enter all the information here: database name, database user name and password for the database:

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

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

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

After you make changes, save them and close Vi. 🙂

To close Vi press Esc then : then w then q and press Enter.

Remember that WordPress files are not yet in the directory from where they can display the site publicly. Let’s do it.

Step 11: Transfer Wordpres files to /var/www/html

The following command will do it for you, more precisely, transfer everything from ~/wordpress to /var/www/html directory:

cp -r ~/wordpress/* /var/www/html

Let’s restart the web server before the last step:

service httpd restart

Step 12: Install WordPress on CentOS server

Now that we’ve done everything properly, visit your server’s IP address. Type it in the Internet browser and enter basic information:

Once you enter basic information such as title, user name, password, email, you can begin to set up WordPress.

Conclusion – CentOS 6 and Wordpres

This is not the end here. Such an environment needs to be upgraded, secured and maintained. For this, it takes time and knowledge. If you are planning to make this site public on a domain (usually it is), you can direct the domain through the A record to the server’s IP address.

This setting is used when you do not want to use cPanel or you do not need it. If you are planning to practice only, wipe it all start over again from the beginning.