How do I ‘containerize’ something, part 2: Installing WordPress

As a reminder, I am starting with a basic WordPress installation running directly on my laptop. We will be wrapping things up into one or more containers in the following posts. This post specifically is simply for me to refresh my memory on how to get WordPress running!

Installing WordPress on a system actually starts with the database. As I am going back to basics, and just doing this all on my laptop, I am using Homebrew for my package manager – all the packages are available!

Installing MySQL

Let’s start with MySql – open a terminal, and after you have updated your Homebrew installation, use the following:

brew install mysql

After a successful installation, you should see the following:

We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
mysql -u root

To start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/mysql/bin/mysqld_safe --datadir\=/opt/homebrew/var/mysql
==> Summary
🍺 /opt/homebrew/Cellar/mysql/8.3.0_1: 323 files, 312.8MB
==> Running `brew cleanup mysql`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> mysql
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
mysql -u root

To start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/mysql/bin/mysqld_safe --datadir\=/opt/homebrew/var/mysql

Then it’s just a matter of starting and securing the MySQL installation:

brew services start mysql
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)

Running the secure installation script will walk you through the most common configuration tasks to ensure you are not deploying a completely unsecured database system. You can see a good sysnopsis of what happens below:

mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
… Failed! Error: Your password does not satisfy the current policy requirements

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

Dropping test database…
Success.

Removing privileges on test database…
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

Finally, all you need to do is create the user and the database to be used by WordPress – there are excellent instructions on the WordPress site, which I followed easily here:

Installing Apache and PHP

Honestly, there are so many good tutiorials out there, I am not going to recreate them here. I used the instuctions in this most excellent overview – https://dani.gg/en/apache-with-php-wordpress-and-phpmyadmin-on-macos/ – and it worked like a champ.

This essentially entails installing Apache and PHP through Hombrew…

brew install httpd
brew install php
brew install phpmyadmin

… and then following the instructions in the aforementioned blog to perform the necessary configurations for Apache and PHP.

Finally, you just need to download and unzip the WordPress installation into the root folder for your desired site – https://wordpress.org/download/.

Follow the instructions in the WordPress installation guide to get everything up and running:

The end result is a local, running installation of WordPress! I have taken the liberty of also importing some of the posts and media from my actual production blog, though I am using a different theme to make it really easy to differentiate between the two. You can see a screenshot of the local instance running on my laptop below:

There! I now have an installation of MySQLK, Apache, PHP, PHPMyAdmin and WordPress running locally on my laptop!

In the next post, we will begin the process of shoving all this into one or more containers!

Happy computing!