How to Install WordPress 4.7 with Apache on RHEL/CentOS 6/7 and Fedora?

Introduction To WordPress

WordPress, one of the most in use CMS (Content Management System) system for website creation. It was developed using MySQL and PHP. It was introduced in the year 2003 and now it’s getting popular day by day because of its plugins available in a mass quantity. With the evolution of web servers, Apache and NGINX WordPress is also flourishing.

So, here we are for How to Install WordPress 4.7 with Apache on RHEL/CentOS 6/7 and Fedora? and By the end of this article, we will get aware of setting up WordPress with Apache/MySQL/MariaDB/PHP

If, looking for setting up WordPress with Nginx Read Full Article Here

Scenario:

  1. My Server IP is 168.1.188
  2. Up and Running MySQL – Read How to SetUP MySQL Server 5.5
  3. Up and Running Apache – Read How to SetUp Apache Server
  4. Up and Running PHP – Read How to Setup Custom PHP or PHP 5.4

Note: If you are a SUDO user then prefix every command with sudo, like #sudo ifconfig

In short, ALL we need is an up and running LAMP environment. Read what LAMP environment is and how to set up LMAP environment?

Here is a quick SetUp for LAMP environment

Let’s start

Step 1: Install Required Packages

To set up WordPress we might require few packages so please install following packages according to your system configuration, requirement, and OS version.

For RHEL/CentOS 7:

# yum install httpd mariadb mariadb-server php php-common php-mysql php-gd php-xml php-mbstring php-mcrypt php-fpm

For RHEL/CentOS 6 & Fedora 15-20:

# yum install httpd mysql mysql-server php php-common php-mysql php-gd php-xml php-mbstring php-mcrypt

For Fedora 21 Or Above:

# dnf install httpd mariadb mariadb-server php php-common php-mysql php-gd php-xml php-mbstring php-mcrypt

After successful installation of MySQL/MariaDB please start your MySQL server and run the following command to get some vulnerabilities removed from your MySQL/MariaDB server.

For CentOs/RHEL 7 and Fedora 22 or Above:

# systemctl start mariadb.service
# mysql_secure_installation

For CentOs/RHEL 6 and Fedora 15 -21:

# service mysqld restart
# mysql_secure_installation

Note: If Stuck Somewhere Please Read Article – Read How to SetUP MySQL Server 5.5

Step 2: Get WordPress

After installing Apache and MySQL we need the WordPress lump on our server. To get this download done you have to be the root user.

# cd /var/www/html
# wget http://wordpress.org/latest.tar.gz

Step 3: Extracting WordPress Files

Now we will extract our WordPress files from this tarball and rename it ( If you want to ). Please run following command.

# tar -xvzf latest.tar.gz
# rm -rf latest.tar.gz
# mv wordpress wp_test
# chmod -R 775 wp_test
# chown -R apache:apache wp_test



Step 4: Creating MySQL User & Database

We need a database for up and running WordPress and a database user which will interact with the database for WordPress. Use the following series of command to login in database and  to create database and MySQL user

#mysql -u root -p
mysql>CREATE DATABASE wp_db;
Query OK, 1 row affected (0.00 sec)

Now, we will create a new user. You can replace the name of database and password, with your preferences.

mysql >CREATE USER 'wp_user'@'localhost' identified by "password";
Query OK, 0 rows affected (0.00 sec)

Note: If you already have a user and want to change password you may use the following command

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

As we have our user and database created now let’s grant all required  privileges and permissions

mysql>GRANT ALL PRIVILEGES ON wp_db.* TO 'wp_user'@'localhost';
Query OK, 0 rows affected (0.00 sec)

Now refresh MySQL with following command and exit

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

Note: Highlighted values will be used later so please use accordingly and do as per your need. Also, if there is any problem in setting up mysql server read: – How to SetUP MySQL Server 5.5

Step 5: Creating Apache VirtualHost for WordPress

Here Are Two Conditions: First one, if you have a domain name for your WordPress installation then follow Setting 2 virtual host and if you want to run WordPress installation on localhost or IP then follow Setting 1 for the virtual host.

Setting 1: If Setting WordPress on IP or LocalHost

# vim /etc/httpd/conf.d/vhost.conf

Copy paste these given lines of code  and change the highlighted values accordingly and as per your needs

NameVirtualHost *:80
<VirtualHost *:80>
ServerName 192.168.1.188 #Your Server IP
ServerAdmin [email protected]
DocumentRoot /var/www/html/
DirectoryIndex index.php index.htm index.html
ErrorLog /var/log/httpd/error_log
CustomLog /var/log/httpd/access_log combined
</VirtualHost>

<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
order allow,deny
allow from all
</Directory>

Now save the file using the command  #: wq!

Now Restart your Server for getting your changes in effect

For CentOs/RHEL 7 and Fedora 22 And Above:

# systemctl restart httpd.service

For CentOs/RHEL 6 and Fedora 15-21:

# service httpd restart

Setting 2: if want to install WordPress on a domain

# vim /etc/httpd/conf.d/vhost.conf

Copy paste these given lines of code  and change the highlighted values accordingly and as per your needs

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/wp_test
ServerName test.kapendra.com #Your Domain Name
ErrorLog /var/log/httpd/test.kapendra.com-error-log
CustomLog /var/log/httpd/test.kapendra.com-access-log common
</VirtualHost>

Now Restart your Server for getting your changes in effect

For CentOs/RHEL 7 and Fedora 22 And Above:

# systemctl restart httpd.service

For CentOs/RHEL 6 and Fedora 15-21:

# service httpd restart



Step 6: Setting up WordPress

This is the key part of getting WordPress installation done. Make sure to make a copy of the default configuration file then make any changes. This configuration file is present in WordPress directory

#cd /var/www/html/wp_test
#cp wp-config-sample.php wp-config.php

Then open the WordPress configuration file:

#vim wp-config.php

You will see content like this and make your changes to the following which I have highlighted.

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

Write and quit the file using :wq!

Step 7: Finishing WordPress Installation and Verification

Now, Open your browser and type any of the following address as per your setting you chose above. I have done my installation using IP address so I will use http://192.168.1.188/wp_test

http://test.kapendra.com

http://localhost/wp_test (If System Is LocalHost)

http://your-ip/wp_test (If WordPress running on IP)

If everything goes right then you will be prompted for this

Now fill all the detailed like Site Title, Admin User, Admin Password, and Enter Your E-Mail and then hit Install button.

And you will have a site running on WordPress you may login into WordPress dashboard using

http://test.kapendra.com/wp-login

http://localhost/wp_test/wp-login/  (If system is Local)

http://your-ip/wp_test/wp-login/  (id WordPress running on IP)

Watch Video:

Coming Soon…