CentrioHost Blog

Stories and News from IT Industry, Reviews & Tips | Technology Blog


HOW TO SET UP A WORDPRESS DEV ENVIRONMENT IN YOUR CENTOS 7 SERVER

WordPress

WordPress is the most popular CMS – Content Management System available. It is user-friendly and provides a vast array of free themes and plugins that essentially allow you to run any type of website you want. It is open source, and its technical core consists of PHP and MySql.

Today we will show you how to set up a fully-fledged WordPress dev environment using your cheap CentOS 7 server.

Prerequisites:
  • CentOS 7 server installed and configured with non-root user and with sudo privileges.
  • LAMP – (Linux, Apache, MySql and PHP) installed on CentOS 7 server

We will now walk you through the prerequisites.

Configuring a non-root user having sudo privileges in CentOS 7 server:
  • Log into the server as root user. Upon log in you will be prompted for the root password as shown below-
  • Use adduser command to add new user. Provide a new user name-
    adduser <username>
  • Provide new user’s password-
    passwd <username>
  • Confirm the password in the prompt as shown below. ReType the password.
  • Use usermod command to add the new user to wheel group. In CentOS, by default, members of wheel group have sudo privileges-
    usermod  -aG wheel <username>
  • You can test sudo access to the user by using-
    su  – <username>
    This way you can check for sudo access. In case sudo access is not working, then you will see an error message in the console.
Installing Apache:

Apache is one of the most popular web servers and it is a great choice for hosting a website. To install Apache, we need to use the following command:

sudo yum install httpd

Once Apache is downloaded and installed, you can start Apache using:

sudo systemctl start httpd.service

To check the installation has been done properly, you can check by typing the server’s public IP address in the browser as – http://<server_IP_address>
You can find your server IP address by using hostname -i

You will be able to see a page as shown below-

Once Apache is installed properly, you can change Apache to start at boot by using the following command-
sudo systemctl enable httpd.service

 

Installation of MySQL (MariaDB):
  • To install the database use yum command as shown below-
    sudo yum install mariadb-server mariadb
  • Once the installation is complete, we can start database by using the following command-
    sudo systemctl start mariadb
  • To remove some of the dangerous defaults and enhance security features use:
    sudo mysql_secure_installation
  • This will prompt an interactive command prompt. Press ENTER and proceed with each prompt. This will enable default values and remove certain users, databases, as well as disable remote root logins
  • To enable the database to start up at boot:
    sudo systemctl enable mariadb.service
Installation of PHP:
  • To install PHP along with php-mysql package use-
    sudo yum install php php-mysql
  • Once PHP is installed, we need to restart Apache webserver in order for it to work with PHP. Apache web server can be restarted as shown below-
    sudo systemctl restart httpd.service
  • You can install additional modules of PHP. To see the list of modules and libraries available type-
    yum search php-
  • To get description about each module you can use this command-
    yum info <package name>
  • An example of this is shown here:
    yum info php-soap
  • In case you wish to install this package then you can use-
    sudo yum install php-soap
 
Testing PHP and Apache Web server:

To test PHP, you will have to write a basic PHP script – test.php. In Apache, this should be placed in “web root”. For CentOS 7, this will be placed at location /var/www/html/.

You will create the file as-
sudo vi /var/www/html/test.php

Open the file, add a simple but valid PHP script, and save the file–
<?php phpinfo(); ?>

In case you have a firewall running, then use the following commands to allow http and https traffic-
sudo firewall-cmd –permanent –zone=public –add-service=http
sudo firewall-cmd –permanent –zone=public –add-service=https
sudo firewall-cmd –reload

Finally, to test that PHP is working, we can open the browser and type-
http://<your_server_IP>/test.php

In case this works as expected, then you will be able to see a web page displaying PHP information.Once these prerequisites are done and configured, as a next step we will proceed to install and configure WordPress.

CREATE MYSQL DATABASE AND USER FOR WORDPRESS:

We have already installed MariaDB. Login using root account-
mysql -u root -p

You will be prompted for a password. Create a Database as-
CREATE DATABASE testwordpress;

Once the database is created, create a new test user-
CREATE USER testwordpressuser@localhost IDENTIFIED BY ‘password’;

Grant all privileges to the user and flush privileges –
GRANT ALL PRIVILEGES ON testwordpress.* TO testwordpressuser@localhost IDENTIFIED BY ‘password’;
FLUSH PRIVILEGES;

 

WORDPRESS INSTALLATION:

Before installing WordPress, we require one PHP module which is needed for resizing images in WordPress. This module needs to be installed. This can be installed as shown below-
sudo yum install php-gd

Restart Apache so that Apache can recognize this module-
sudo service httpd restart

Now we can download WordPress by using-
cd~
wget http://wordpress.org/latest.tar.gz

Extract the archive using-
tar xzvf latest.tar.gz

Once extracted you will have a wordpress directory in your home directory. To finish the installation, transfer these files to Apache document root as shown below-
sudo rsync -avP ~/wordpress/ /var/www/html/

rsync will safely copy all the contents. Once this is done, we need one folder for WordPress to store uploaded files. You can use mkdir-
mkdir /var/www/html/wp-content/uploads

Once the folder is created, we need to provide correct ownership and permissions. To grant ownership to Apache’s user and group use the following-
sudo chown -R apache:apache /var/www/html/*

With the above changes, the Apache web server can now create/modify WordPress files and also allow you to upload content to the server.

 

CONFIGURE WORDPRESS MANUALLY AND USING WEB INTERFACE:

The key configuration file for WordPress is wp-config.php. A sample file exists during installation. Copy this file-
cd /var/www/html
cp wp-config-sample.php wp-config.php

Open this file in text editor-
nano wp-config.php

You need to modify changes for the database settings in the section- MySQL settings. Replace DB_NAME, DB_USER, and DB_PASSWORD

The modified file should have the created Database credentials-
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘testwordpress’);
/** MySQL database username */
define(‘DB_USER’, ‘testwordpressuser’);
/** MySQL database password */
define(‘DB_PASSWORD’, ‘password’);

These are only fields which needs to be edited. You can now save your changes.

Now to complete the installation, we will make use of the web interface. In the browser, use the IP address or Domain name as shown-
http://<server_domain_name_or_server_IP>

First, select a language for installation. After clicking on continue, you can see a configuration page as shown below-

After filling all the information and clicking on install WordPress button, you will be able to see the following message-

Log in and you will be able to see the WordPress dashboard-

CONCLUSIONThis finishes the setup of WordPress dev environment on your CentOS 7 server. From here on you can start using your VPS for WordPress development purposes.

Subscribe Now

10,000 successful online businessmen like to have our content directly delivered to their inbox. Subscribe to our newsletter!

Archive Calendar

SatSunMonTueWedThuFri
 1
2345678
9101112131415
16171819202122
23242526272829
30 

Over 20000 Satisfied Customers!

  • web hosting reviewer
    Valerie Quinn
    CTO, Acteon Group

    Centriohost staff were fantastic, I had a concern with a domain and they got back to me very quickly and they helped me to resolve the issue! ~ . . . Read more

  • Joomla hosting reviewer
    Collin Bryan
    Photographer, Allister Freeman

    I'm using centrio for my portfolio since 2006. The transition was seamless, the support was immediate, and everything works perfectly. ~ . . . Read more

  • dedicated server reviewer
    Harry Collett
    Actor, A&J Artists

    Very easy to understand & use even though I am not very technologically minded. No complications whatsoever & I wouldn't hesitate to recommend it to all. ~ . . . Read more

  • vps web hosting reviewer
    Porfirio Santos
    Technician, Diageo PLC

    Centrio support team have been amazingly responsive and helpful to any of my queries, thank you so much to the Centriohost have been amazingly responsive and helpful to any of my queries 👍👍👍 ~ . . . Read more

  • wordpress hosting plans reviewer
    Catherine Auer
    Doctor, SmartClinics

    Anytime I've had a problem I can't solve, I've found Centriohost to be diligent and persistent. They simply won't let an issue go until the client is happy. ~ . . . Read more

  • reseller hosting reviewer
    Effectivo Social
    Freelancer, Fiverr

    Recommend their shared hosting for all my SME web design clients. Their cloud or VME offerings are too great to deal with. Pricing is perfect and suitable for all users (͠≖ ͜ʖ͠≖) 👌 ~ . . . Read more

Top