© David Both 2020
D. BothUsing and Administering Linux: Volume 3https://doi.org/10.1007/978-1-4842-5485-1_11

11. WordPress

David Both1 
(1)
Raleigh, NC, USA
 

Objectives

In this chapter, you will learn
  • To install PHP and MariaDB – requirements for WordPress

  • To create a MariaDB database for WordPress to use for a web site

  • To do the WordPress 5-minute installation

  • To use the WordPress Dashboard to make administrative changes and to add new posts and pages to the site

  • To change the WordPress theme for the web site to alter its look and feel

Introduction

In the previous chapter, we installed the Apache HTTPD web server and configured it to serve two web sites – one static and one dynamic. Dynamic web sites are important for businesses and other organizations that have a need to constantly change the information on their web sites.

The manual methods we used in Chapter 10 are slow. They force the user to be knowledgeable about the tools used to create and manage web pages in a way that detracts from fully engaging with the content. There is a better way. WordPress is one of a number of higher-level tools that allow users to create web pages and news feed posts using a GUI interface that works much like a word processor.

WordPress is a powerful, highly extensible combination of web publishing, blogging, and Content Management Software (CMS). It takes only a few minutes to install and can get a good-looking, complex web site up and running very quickly.

There are many other open source options available for building a web site. I use WordPress in this chapter because it is one of the easier to install and configure and it is very popular. It is also the one I use to build and manage all of my own web sites.

In this chapter, we will convert one of the virtual hosts to WordPress and create a minimal web site. This is not a chapter about using WordPress, so it only goes as far as getting a basic site up and running and then adding a blog post or two.

Install PHP and MariaDB

WordPress is written in PHP1, an open source hypertext preprocessing language specifically designed for use in web applications. PHP stands for yet another recursive algorithmic name, “PHP: Hypertext Preprocessor.” PHP is a server-side language in which PHP code is embedded in HTML web pages. The PHP code is executed on the server and the resultant HTML is sent to the client along with the surrounding HTML.

MariaDB is a fork of the MySQL project which was subsumed by Oracle. It is an open source SQL database used by WordPress to store all of the data for a web site. We also need to install the php-mysqlnd extension module.

These tools are not installed by default, so we need to install them.

Experiment 11-1

Perform this experiment as the root user on StudentVM2. Install the required PHP and MariaDB tools.
[root@studentvm2 ~]# dnf -y install php php-mysqlnd mariadb mariadb-server mariadb-server-utils

Restart the HTTPD service to enable Apache to integrate with PHP and to enable the MySQL (MariaDB) plug-in.

Install WordPress

WordPress is available from the Fedora repository, but in the past, it has been multiple releases behind that on the WordPress web site. So, for this experiment, you will download and install WordPress from the WordPress web site. This is also a good introduction to installing software that won’t have a nicely prepackaged version for Fedora – or whatever other distribution you might be using.

The code for WordPress is located at www.wordpress.org. Documentation for installation is located at codex.​wordpress.​org/​Installing_​WordPress. You should view the WordPress installation documentation while doing this experiment, but everything you need need is here in this experiment.

Experiment 11-2

Perform this experiment as root on StudentVM2.

Verify that the index.html file in the /var/www1/html directory has been deleted or at least renamed. It would be OK to delete it because it will not be needed again.

Download the latest tarball from the WordPress site into the /tmp directory.
[root@studentvm2 ~]# cd /tmp ; wget http://wordpress.org/latest.tar.gz
Extract the content of the tarball. The files are extracted to the ./wordpress directory which is created during the process.
[root@studentvm2 tmp]# tar -xzvf latest.tar.gz
Make /tmp/wordpress the PWD. Copy the files from the wordpress directory to the /var/www1/html directory. The -R option copies the files recursively so that all files in all subdirectories are copied.
[root@studentvm2 wordpress]# cp -R * /var/www1/html/
Make /var/www1/ the PWD and change the ownership of the files to apache.apache. Verify that the files are in the correct location and have the new ownership.
[root@studentvm2 wordpress]# cd /var/www1 ; chown -R apache.apache *
Enable MariaDB so it will start on boot, and then start it now. You also need to restart Apache to enable the MySQL plug-in.
[root@studentvm2 ~]# systemctl start mariadb ; systemctl enable mariadb ; systemctl restart httpd.service
Verify that MariaDB is up and running.
[root@studentvm2 ~]# systemctl status mariadb
[root@studentvm2 ~]# systemctl status mariadb
• mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-07-27 13:24:57 EDT; 1h 19min ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 27183 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 4696)
   Memory: 73.2M
   CGroup: /system.slice/mariadb.service
           └─27183 /usr/libexec/mysqld --basedir=/usr
Jul 27 13:24:56 studentvm2.example.com mysql-prepare-db-dir[27082]: Please report any problems at http://maria>
Jul 27 13:24:56 studentvm2.example.com mysql-prepare-db-dir[27082]: The latest information about MariaDB is av>
Jul 27 13:24:56 studentvm2.example.com mysql-prepare-db-dir[27082]: You can find additional information about >
Jul 27 13:24:56 studentvm2.example.com mysql-prepare-db-dir[27082]: http://dev.mysql.com
Jul 27 13:24:56 studentvm2.example.com mysql-prepare-db-dir[27082]: Consider joining MariaDB's strong and vibr>
Jul 27 13:24:56 studentvm2.example.com mysql-prepare-db-dir[27082]: https://mariadb.org/get-involved/
Jul 27 13:24:57 studentvm2.example.com mysqld[27183]: 2019-07-27 13:24:57 0 [Note] /usr/libexec/mysqld (mysqld>
Jul 27 13:24:57 studentvm2.example.com mysqld[27183]: 2019-07-27 13:24:57 0 [Warning] Could not increase numbe>
Jul 27 13:24:57 studentvm2.example.com mysqld[27183]: 2019-07-27 13:24:57 0 [Warning] Changed limits: max_open>
Jul 27 13:24:57 studentvm2.example.com systemd[1]: Started MariaDB 10.3 database server.
No password is required by default, so we will set a root password using the mysqladmin utility.
[root@studentvm2 ~]# mysqladmin -u root password <Your Password>
Now login to the MariaDB CLI to test the new password. Your results should look like those below.
[root@studentvm2 ~]# mysql -u root -p
Enter password: <Enter your password>
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 10
Server version: 10.3.12-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]>

This last line is the MariaDB command prompt.

HTTPD configuration

Due to the fact that Apache has not been configured for the index file used by WordPress, index.php, we need to add that to the VirtualHost stanza for the primary web site. This ensures that Apache uses the correct index file for the WordPress web site.

Experiment 11-3

Perform this experiment as root on StudentVM2.

Edit the httpd.conf file. In the VirtualHost stanza for the www1 web site, change the DirectoryIndex line from:
DirectoryIndex index.html index.txt /cgi-bin/index.cgi
to
DirectoryIndex index.php index.html index.txt /cgi-bin/index.cgi

Restart or reload Apache to activate the changes.

Creating the WordPress Database

At this stage, some basic databases required by MariaDB have been created, but we have created none for the WordPress web site. In this experiment, we will look at the existing databases and create the ones required for WordPress.

Experiment 11-4

Perform this experiment as root on StudentVM2.

Use the following command to view the basic databases required by MariaDB. Be sure to add the semicolon (;) to the end of each command.
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.001 sec)
MariaDB [(none)]>
Now we can create the database for the web site we want to build and grant privileges to the root user (the MariaDB root user, not the Linux root user) to all tables in the new database.
MariaDB [(none)]> create database www1;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> grant all privileges on www1.* to "root"@"studentvm1" identified by "<type the password here>";
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)
Now check the new database. The MariaDB user interface has some command-line editing capabilities, so you can just use the up-arrow key to scroll back to the show databases command.
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| www1               |
+--------------------+
4 rows in set (0.000 sec)

This completes all of the MariaDB configuration that is required to create a WordPress web site.

These are all of the SQL commands that you will ever need to know when creating a MariaDB database for WordPress. However, I have taken some time to learn a bit more for myself, and we will do a little more a bit later in this chapter. So do not log out of MariaDB. We will explore it a little further later in this lab project.

Configuring WordPress

We are now ready to configure WordPress itself. We will set up a configuration file and then run an administrative program from the web browser to complete the web site setup.

Experiment 11-5

Perform this experiment as root on StudentVM2.

Change the PWD to /var/www1/html/. Copy the file wp-config-sample.php to wp-config.php. Copying the file leaves the original in case the copied file gets badly hosed. Change the ownership of wp-config.php to apache.apache.

Open wp-config.php in vi for editing. Change some of the lines in the file so that they look like those in the portions of the file shown below. The specific lines to be changed are in bold.
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'www1');
/** MySQL database username */
define('DB_USER', 'root');
/** MySQL database password */
define('DB_PASSWORD', '<Your password goes here>');
. . .
/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = 'www1_';
. . .
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
        define('ABSPATH', dirname(__FILE__) . '/var/www1/html/');

Save the file and exit from the editor.

Open a browser or a new tab in an existing browser instance on StudentVM2 and enter the following line in the URL field.
http://www1.example.com/wp-admin/install.php

This opens the initial WordPress web site language configuration page. The default is usually correct for your location, but ensure that you select the correct locale. English (United States) was correct for me. Press the Continue button.

Fill in or choose the entries as shown in Figure 11-1.Student
../images/473483_1_En_11_Chapter/473483_1_En_11_Fig1_HTML.png
Figure 11-1

WordPress configuration settings

Then click the Install WordPress button to complete the setup. This may take a few minutes depending upon the specs of your VM. There is no progress indicator so be patient.

At the end of the process, you will be presented with a login page. Let’s take a look at the web site before we change anything. In a new tab of your browser, type in the web site URL, www1.example.com and press Enter.

You will see the WordPress web site home page with the default theme. The default theme changes each year so your web site may look different from this one. It is a good thing that themes are easy to change because the default ones are pretty bland. This one seems to suck more than most – at least to me. We will change the theme as part of this chapter.
../images/473483_1_En_11_Chapter/473483_1_En_11_Fig2_HTML.jpg
Figure 11-2

The default WordPress home page. It may look different for you because the default theme changes each year

Administering WordPress

WordPress is easy to administer, both in terms of creation and maintenance of content, the management of the look and feel of the site, and the ability to obtain traffic metrics. In Experiment 11-6, we take a very brief look at administering WordPress.

Experiment 11-6

Perform this experiment as the student user on StudentVM1.

We are doing this from StudentVM1 to illustrate that administration of a WordPress web site can be performed from any host that has network or Internet access to the web site. This is one good reason to use strong passwords and to not use the default Admin account.

Open a browser on StudentVM1 if one is not already open and go to URL, http://www1.example.com. Scroll down to the Meta section of the page and click Log in. Type in the username of student, enter the password, and click the Log In button. The WordPress Dashboard, from which all administrative activities can be performed, is shown in Figure 11-2.
../images/473483_1_En_11_Chapter/473483_1_En_11_Fig3_HTML.jpg
Figure 11-3

The Welcome page of the WordPress Dashboard

The WordPress Dashboard provides you with lists of things to do to get started customizing your web site, and the next steps that will enable you to add pages and posts to the site. Skip all that, click Dismiss (upper right of the welcome screen), and look at the dashboard itself on the left side of the screen.

Hover over Users, and then click All Users. Here you can manage users including adding and deleting them. Users can have roles. Since you are the admin you might not want anyone else to have that role so you would give them lesser roles.

Now hover over Appearance and click Customize. Here we can do things like change the theme which is what provides your web site with its personality. Click Themes, select one of the other themes, and click the Live Preview button to see what that theme would look like. I chose the 2017 theme, but it might not be available when you do this experiment. Just pick one and see how it changes the look and feel of your web site.

Once you have chosen one of the available themes, click the Activate and Publish button. Open another tab on your browser and go to the web site to see how it looks.

If none of the themes listed meet your needs, it is easy to download more from a very large selection of free ones. In the Previewing themes menu item, click Change, and then click WordPress.org themes. This opens up a list of many themes that are available for download. Scan through them and pick one or two that interest you and then click the Install & Preview button. This will install the theme and preview it so that you can decide whether you want to publish it. Experiment with themes for a few minutes just to get a feel for what can be done.

If you have an interest in learning more about WordPress, there is some good online help available at https://wordpress.org/support/category/basic-usage/. Because our objective here is to install it and get it running, we have mostly fulfilled our need as SysAdmins.

Updating WordPress

The last thing we need to know about WordPress is how to update it. This is easy and mostly takes care of itself.

When you log in to the dashboard, it will inform you when there are updates available. You can go to the updates page, click the available updates, and install them. It usually takes only a few minutes to do the updates. WordPress will go into maintenance mode during a portion of updates for WordPress itself, the active theme, and any active plug-ins.

If you create an account at WordPress.​org, you can choose for updates to be installed automatically.

Exploring MariaDB

The WordPress configuration procedure created the tables for the database and there is now some content. So take a few minutes to explore the MySQL database.

Experiment 11-7

Perform this experiment as root on StudentVM2.

It is only possible to work with a given database when it is the “current” one, somewhat like the present working directory. This is called “connecting” with the database. Connect to the www1 database with the command use www1; and MariaDB will display a message that says, “Database changed.”
MariaDB [(none)]> use www1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [www1]>
Now list the tables in the database. The results should look like these.
MariaDB [www1]> show tables;
+-------------------------+
| Tables_in_www1          |
+-------------------------+
| www1_commentmeta        |
| www1_comments           |
| www1_links              |
| www1_options            |
| www1_postmeta           |
| www1_posts              |
| www1_term_relationships |
| www1_term_taxonomy      |
| www1_termmeta           |
| www1_terms              |
| www1_usermeta           |
| www1_users              |
+-------------------------+
12 rows in set (0.001 sec)
MariaDB [www1]>

We can see that the WordPress installation procedure has created the tables in this database.

To explore the individual tables, you can use the describe command. This example shows the fields in the www1_posts table, along with their attributes.
MariaDB [www1]> describe www1_posts;
+-----------------------+---------------------+------+-----+---------------------+----------------+
| Field                 | Type                | Null | Key | Default             | Extra          |
+-----------------------+---------------------+------+-----+---------------------+----------------+
| ID                    | bigint(20) unsigned | NO   | PRI | NULL                | auto_increment |
| post_author           | bigint(20) unsigned | NO   | MUL | 0                   |                |
| post_date             | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_date_gmt         | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_content          | longtext            | NO   |     | NULL                |                |
| post_title            | text                | NO   |     | NULL                |                |
| post_excerpt          | text                | NO   |     | NULL                |                |
| post_status           | varchar(20)         | NO   |     | publish             |                |
| comment_status        | varchar(20)         | NO   |     | open                |                |
| ping_status           | varchar(20)         | NO   |     | open                |                |
| post_password         | varchar(255)        | NO   |     |                     |                |
| post_name             | varchar(200)        | NO   | MUL |                     |                |
| to_ping               | text                | NO   |     | NULL                |                |
| pinged                | text                | NO   |     | NULL                |                |
| post_modified         | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_modified_gmt     | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_content_filtered | longtext            | NO   |     | NULL                |                |
| post_parent           | bigint(20) unsigned | NO   | MUL | 0                   |                |
| guid                  | varchar(255)        | NO   |     |                     |                |
| menu_order            | int(11)             | NO   |     | 0                   |                |
| post_type             | varchar(20)         | NO   | MUL | post                |                |
| post_mime_type        | varchar(100)        | NO   |     |                     |                |
| comment_count         | bigint(20)          | NO   |     | 0                   |                |
+-----------------------+---------------------+------+-----+---------------------+----------------+
23 rows in set (0.001 sec)
MariaDB [www1]>
Use the following command to display the post_title rows of the database.
MariaDB [www1]> select post_title from www1_posts;
+----------------+
| post_title     |
+----------------+
| Hello world!   |
| Sample Page    |
| Privacy Policy |
| Auto Draft     |
+----------------+
4 rows in set (0.000 sec)
MariaDB [www1]>

Use the exit command to exit the MariaDB user interface.

This chapter is neither a course on web page design and creation nor one on MariaDB, so that is as far as we will go here. However, you now have at least a small bit of knowledge about using MariaDB and enough to get you started with WordPress.

Chapter summary

WordPress is a powerful and reliable tool for creating content-based web sites. It is one of the easiest ways to create and maintain a web site I have ever used. Despite that, the WordPress 5-minute installation is not really just 5 minutes – at least not for me. I do it seldom and so need to look up the steps each time. Reading the directions every time I do the installation takes some time, and I always take more than five minutes – but not much more.

If you plan to work on web sites using WordPress, spend some time learning to use it and to add posts and pages. My personal web sites www.both.org and www.linux-databook.info/ both use WordPress. I have also used it for some of my customers.

Exercises

Perform the following exercises to complete this chapter.
  1. 1.

    What happens if a new index.html file with a bit of plain ASCII text or HTML content is placed in the /var/www1/html directory?

     
  2. 2.

    What might you use the effect in #1 for?

     
  3. 3.

    Why did we use the download from the WordPress web site rather than the Fedora version of WordPress?

     
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.249.194