Written by Varghese Emlin Charly
Contact :smiley:
- Slack: @vcharly
- Email: emlincharly@gmail.com
Table of Contents
- Prerequisites
- Summary
- Downloading and First-Time Startup of CentOS
- Setting up CentOS
- Installing Apache
- Installing the Database
- Installing PHP
- Adding a User to the Database
- Installing Wordpress
- Configuring Wordpress
- Installing Wordpress from Web GUI
- Troubleshooting
Prerequisites
- Have pfSense Running
- Have Ubuntu DNS Running
- Have Windows 10 Running
- Have ISP Gateway Running
Summary
The CentOS machine will be hosting a public e-commerce site created using Wordpress. When you are finished, the site will be accessible from the WAN network through the Windows 10 machine.
Downloading and First-Time Startup of CentOS
-
First, download the CentOS ISO. It can be found here
We are going to be using the CentOS Minimal ISO and install everything we need.
Once the ISO is done downloading, proceed to create a new virtual machine inside VMWare or Virtualbox using the downloaded ISO. Use the recommended settings for the allocated ram, storage, and cpu cores. And when asked for network adapter, allow CentOS to access the Host-Only, DMZ adapter. Adding the DMZ adapter allows the pfSense box to control the network traffic going in and out of the CentOS box.
Boot the CentOS vm to proceed with the installation
-
Once booted, choose the
Install CentOS 7
option.Now you will be greeted with a
Welcome to CentOS 7
screen.Choose your prefered language and proceed to the
Installation Summary
screen.Before the installation can begin, you must choose the installation destination. Click on
Installation Destination
and choose the virtual hard drive you created for the vm. This will ensure that the Operating system is installed to the correct location.Click
Done
andBegin Installation
. -
While CentOS installs, you must setup a
Root Password
and create aNew User
. Make sure you take a note of this information because you will be using this later to login.Once the install is done, you will be prompted to
Reboot
. -
The reboot process shouldn’t need any user input. But, once it has booted up, login with the new user you created while CentOS was installing.
If you successfully logged in, Congratulations! You have installed CentOS. If you couldn’t login, try login in with
localhost login: root
andPassword: (The root password you set)
. Once you login with root, BE SURE YOU CREATE A NEW USER. If that didn’t work, try reinstalling CentOS from the beginning.
Setting up CentOS
-
Execute
ip a
and take note of your network adapter. It should be something along the lines ofenp0s3
for Virtual Box vms andens33
for VMWare vms. -
Type
su root
to obtain root. Thesu
is sometimes referred to as the “superuser” or “switch user” command. Using this command is one of the easiest way to switch your current user to root. -
And then,
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
. (If you are using a VMWare vm, usevi /etc/sysconfig/network-scripts/ifcfg-ens33
) Vi is a text editor you can use in the terminal.To edit text in
vi
, you must clicki
to enter “insert mode” and once you are done editing, clickESC
to exit insert mode, now clickSHIFT
and:
at the same time and enterwq
.wq
means write to the file and quit the file. The same can be done by doingx
instead ofwq
. Refer to this website to learn more about vi.You need to change the configuration from
BOOTROTO=dhcp ONBOOT=no
to
BOOTROTO=static ONBOOT=yes
DCHP is a protocol that dynamically assigns IPs to machines. Changing
BOOTORO
to static makes sure that machine doesn’t try to acquire an IP address automatically. This is because we are going to manually give it an IP. This also means that if the IP configuration is not done correctly, you cannot connect with the other machines properly.Once that has been added, add these lines to the end of the configuration document
IPADDR=172.20.240.11 NETMASK=255.255.255.0 GATEWAY=172.20.240.254 DNS1=172.20.240.23 NM_CONTROLLED=no
IPADDR=172.20.240.11
will manually set the machine’s IP. This is possible because we disable DHCP and changed it to static earlier.DNS1=172.20.240.23
will make sure that DNS requests will be passed through the Ubuntu DNS. -
Now to ensure that CentOS has an IP address, execute these commands (Again, if you are VMWare, your adapter is most likely ens33 or something similar).
sudo ifdown enp0s3
(ifdown
takes down the network interface)sudo ifup enp0s3
(ifup
bring back up the network interface, while essentially doing a reboot)ip a
(Displays the network interfaces on the machines so you can make sure thatenp0s3
/ens33
shows up)
Let’s verify everything worked by doing
ping 8.8.8.8
andping wwww.google.com
and making sure both responds. The response should be in the form of a reply from the IP address of Google. At this point you can also try to ping the Gateway (172.20.240.254
) or any other machines that are on the same network (Ubuntu DNS).
Installing Apache
Install Apache using the following commands:
sudo yum update
(Updates yum and will ensure that the next lines will run smoothly.)-
sudo yum install httpd
(HTTPD is a daemon created by Apache and this command is installing Apache Server for the machine to host the Wordpress site later on.) Next,sudo iptables -F
needs to be run to flush the iptables. You can also runiptables -S
to make sure there are no rules currently on the table.Now, you can restart the service by running
sudo systemctl start httpd.service
We want Apache to start on boot, so we can run
sudo systemctl enable httpd.service
to enable that. (At this point you can visit172.20.240.11
from the Windows 10 machine to ensure everything is running properly. You should see the default page for Apache with lots of useful information about file locations and your Configuration Overview.
Installing the Database
Install the database using the following commands:
sudo yum install mariadb-server mariadb
(This installs the Maria Database, which is similar to MySQL.)sudo systemctl start mariadb
sudo systemctl status mariadb
(Will ensure that MariaDB is installed and started.)sudo mysql_secure_installation
(Is used to secure the database.)
Installing PHP
Install PHP using the following commands:
sudo yum install php php-mysql
sudo yum install nano
(Installs nano. Nano will be used to edit.php
files that will be later created. You can also use others like vim))sudo nano /var/www/html/info.php
(Will create and open a new.php
file in that directory. Make sure that yousudo
this command, if not, you may have difficulties when trying to save the file.) Add<?php phpinfo(); ?>
to the file. (This will be used to display general information about PHP later on. This can also be used as a check to make sure that PHP is installed correctly later.)sudo systemctl restart httpd.service
(Restarts the Apache service.) Runsudo systemctl status httpd.service
(Verifies that the service is back up and running.)- Now you can visit
172.20.240.11/info.php
from the Windows 10 machine and it will now display information about PHP that is created in step 3.Adding a User to the Database
Add a user to the database using the following commands:
-
mysql -u root –p
to login as rootAfter entering MYSQL, the terminal should look something like this:
mysql>
- Execute the following commands to add a user to the database:
CREATE DATABASE wordpress
Creates a database calledwordpress
CREATE USER web@localhost IDENTIFIED BY 'password';
Creates a user calledweb@localhost
that has a password ofpassword
(You can change the password to something you prefer).GRANT ALL PRIVILEGES ON wordpress.* TO web@localhost IDENTIFIED BY 'password';
Grants all privileges for the databasewordpress
to the userweb@localhost
with the passwordpassword
.(The*
means everything inside that database, just like/Desktop/*
means everything inside the Desktop folder.)FLUSH PRIVILEGES;
(Running this tells MySQL to reload the privileges granted to users)exit
Installing Wordpress
Install Wordpress using the following commands:
sudo yum install php-gd
(Installs PHP for the Wordpress website to communicate with the database) Usesudo service httpd restart
to restart the Apache service.cd ~
Will take you back to the home directory.sudo yum install wget
(Will installwget
, which is needed to retrieve the zip file needed to install Wordpress. Runningwget
on a URL will download the files that URL leads to.)wget http://wordpress.org/latest.tar.gz
(Downloads a zip file for Wordpress.)tar xzvf latest.tar.gz
(Unzips the file that was downloaded.)sudo rsync -avP ~/wordpress/ /var/www/html/
(Is used to move thewordpress
directory to its new home at/var/www/html/
.)mkdir /var/www/html/wp-content/uploads
(Creates a new directory.)sudo chown -R apache:apache /var/www/html/*
(Changes the owner for the directories.)
Configuring Wordpress
cd /var/www/html
(Moves the working directory to thehtml
directory.)cp wp-config-sample.php wp-config.php
(Copies the sample Wordpress config file and renames itwp-config.php
.)nano wp-config.php
Edit the file to accompany these new changes:define('DB_NAME', 'wordpress'); define('DB_USER', 'web') define('DB_PASSWORD', 'password');
(These credentials will be used by PHP to connect to the database called
wordpress
using the user “web
” and the password “password
” that we created earlier in MySQL.)- Visit
172.20.240.11
from the Windows 10 machine to ensure that the service is running properly.
Installing Wordpress from Web GUI
- Visit
http://172.20.240.11/wp-admin/install.php
from the Windows 10 machine. You should see a greeting from Wordpress and instructions to install Wordpress. - Follow the prompted instructions and proceed into setting. Use the following images to guide you through the process. (The images are provided by Wordpress)
Troubleshooting
If you have any issues installing Wordpress, please refer to Wordpress’s official documentation. The documentation for the installation process can be found here.