Objectives
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
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.
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.
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.
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.
Save the file and exit from the editor.
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.
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.
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.
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.
We can see that the WordPress installation procedure has created the tables in this database.
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
- 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.
What might you use the effect in #1 for?
- 3.
Why did we use the download from the WordPress web site rather than the Fedora version of WordPress?