Server Setup 6: WordPress Pre-requisites

If this is your first time looking at a post from this series, have a look at this summary: Server Setup 0: Contents

WordPress is a very flexible platform, but there are a few key pieces that are essential for it to run:

  • A websever
    • We installed Apache in an earlier post so that’s covered, though we will need some extra modules.
  • PHP
    • This is the programming language WordPress is built in and runs on, so our server needs to have it installed.
  • A Database
    • We’ll install MariaDB, which is powerful & popular solution.

The full details are on the WordPress website, and we’ll refer back to this for the specifics in a bit: https://make.wordpress.org/hosting/handbook/handbook/server-environment/

First, lets install PHP

sudo apt install php

It’s worth paying some attention to what apt is actually doing at his point:

sandy@waldorf:/var/www/test$ sudo apt install php
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libapache2-mod-php7.3 libsodium23 php-common php7.3 php7.3-cli php7.3-common php7.3-json
  php7.3-opcache php7.3-readline psmisc
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libapache2-mod-php7.3 libsodium23 php php-common php7.3 php7.3-cli php7.3-common php7.3-json
  php7.3-opcache php7.3-readline psmisc
0 upgraded, 11 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,377 kB of archives.
After this operation, 17.7 MB of additional disk space will be used.
Do you want to continue? [Y/n]

In the list of packages that will be installed, php7.3 has been selected. This is the current stable version of PHP, and is the default in Debian 10. Also, libapache2-mod-php7.3 will be installed – this is the Apache module that lets it run php code when to create the web pages you see.

We can test this with the phpinfo(); function, which does a similar thing to the http://test.example.org/server-info page we created in the previous post.

Create a file called phpinfo.php in the folder for the test website:

sudoedit /var/www/test/phpinfo.php

Type in this line:

<?php phpinfo(); ?>

Now visit http://test.example.org/phpinfo.php. You should get a long page full of information that looks like this:

All of the headings on this page after HTTP Headers Information and before Additional Modules are the modules that PHP has loaded and can be used by php webpages on your server.

If we compare that list of modules, to the list of extensions required by WordPress, we might find some gaps. This is the list from my server:

Required by WordPress Installed on myserver
calendar
Core
ctype
curl
date
dom
exif exif
fileinfo fileinfo
filter
ftp
gettext
hash hash
iconv
imagick
json json
libxml
mbstring
mysqli
openssl openssl
pcntl
pcre pcre
PDO
Phar
posix
readline
Reflection
session
shmop
sockets
libsodium* (the documentation is slightly out of date, sodium replaces libsodium) sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
Zend OPcache
zip
zlib

So the missing ones are:

  • curl
  • dom
  • imagick
  • mbstring
  • mysqli
  • xml
  • zip

So we’ll install them. The package names take the form of php- or php7.3- and then the module name. The dom module is provided within the php-xml package. mysqli is in php-mysql.

sudo apt install php-curl php-imagick php7.3-mbstring php-mysql php-xml php-zip

For some reason, some of these need to be enabled manually, the others just work.

sudo phpenmod -s apache2 curl mbstring mysqli

Restart the webserver:

sudo systemctl restart apache2

Database

The Database holds all of the live content in your wordpress blog, like the posts and comments. It also has all of the user information.

We’ll install mariadb

sudo apt install mariadb-server

Now we’ll use a ready-made script to set basic security options. You’ll need to create a strong password for root user for the database server (not the same as the root user of the system).

sudo mysql_secure_installation

Say yes to all of the options, entering the database server root password when prompted.

Now create the actual worpress database in the database server. Start by logging into the database with the mysql command line client, and enter the password when prompted.

sudo mysql -u root -p
sandy@waldorf:/etc/php/7.3/apache2$ sudo mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 57
Server version: 10.3.22-MariaDB-0+deb10u1 Debian 10

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)]>

You’re now logged into a special command line that’s just for working on the database server. This command creates the database – the name could be anything – just remember it for later. I’ve called mine wp_db.

CREATE DATABASE wp_db;

Then next command creates the user that WordPress will use to access this database. It also sets their password and gives them access to the database. Fill in your own values for wp_db, wp_usr and password.

GRANT ALL PRIVILEGES ON wp_db.* TO "wp_usr"@"localhost" IDENTIFIED BY "password";

Now force the database to reload that user information and exit:

FLUSH PRIVILEGES;
EXIT

This is what the whole interraction looks like on my system:

sandy@waldorf:/etc/php/7.3/apache2$ sudo mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 57
Server version: 10.3.22-MariaDB-0+deb10u1 Debian 10

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)]> CREATE DATABASE wp_db;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON wp_db.* TO "wp_usr"@"localhost" IDENTIFIED BY "password";
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> EXIT
Bye

Leave a Reply

Your email address will not be published. Required fields are marked *