WordPress On Raspberry Pi – Part 4 – phpMyAdmin Setup

phpMyAdmin Logo

This will be the last post in this series. However I’m not done with WordPress. Hence, expect corollary articles in the near future.

In previous posts I covered:

In this tutorial, I’ll address phpMyAdmin configuration.

You may wonder: “Why discuss phpMyAdmin in a series about WordPress”?

Because it can come in handy ! And because, at some point, chances are you’ll want to have a peek under the hood. When the time comes you’ll be equipped.

1. Apache Configuration

In the first post of this series, I proposed to install the apache2-doc package. If indeed you did install it, you can access Apache’s documentation locally on your raspberry pi.

Try adding /manual to the raspberry pi IP address in your browser URL bar to see it with your own eyes:

Apache2 Documentation Locally On A Raspberry Pi
Apache2 Documentation Locally On A Raspberry Pi

Oddly, there is no such a thing as a manual directory in /var/www/html. Furthermore, there is no corresponding site enabled either in /etc/apache2/sites-enabled. How come ?

But off course, this actually relies on another Apache’s trick !

We saw how to enable sites and modules (for instance the rewrite module for Wordress permalinks in part 3), but we’ve not fiddled with configurations just yet.

$ cd /etc/apache2
$ ls -lA

As you can see, besides the directories for sites and modules, we find: conf-available and conf-enabled.

As usual, in order for Apache to load a configuration on startup, a link must exist in conf-enabled to a configuration in conf-available. Apache provides 2 commands to that end: a2enconf and a2disconf. Their usage should be familiar to you by now.

Let’s have a look:

$ cd conf-available/
$ ls -lA
$ cat apache2-doc.conf
$ ls -lA ../conf-enabled/

We are going to use the very same mechanism to enable phpMyAdmin, without the need to declare a new virtual host:

$ sudo vi phpmyadmin.conf

Add the following line to the file and save:

Alias /phpMyAdmin /var/www/html/phpMyAdmin/

Then enable the configuration and let Apache reload all its configuration files:

$ sudo a2enconf phpmyadmin.conf
$ ls -lA ../conf-enabled/
$ apache2ctl -t
$ sudo systemctl reload apache2

Finally, point your browser to your raspberry pi IP address adding /phpMyAdmin at the end of the URL:

phpMyAdmin Login Page
phpMyAdmin Login Page

2. phpMyAdmin Configuration

Now that everything’s in place it’s mostly a matter of setting up phpMyAdmin. Start your browser and open the following URL:

{your raspberry pi IP address}/phpMyAdmin/setup

You should see something like the screenshot below:

phpMyAdmin Setup Overview
phpMyAdmin Setup Overview

Click on the New server button to create a new server configuration and allow phpMyAdmin to connect to the MariaDB database:

phpMyAdmin Add A New Server
phpMyAdmin Add A New Server

Next, enter the missing information. The values visible in the screenshot above should be just fine.

  • The Verbose name of this server is just a display name.
  • The Server hostname should have been set to localhost already by default.
  • The Server socket is more interesting: it defines how to establish a two-way connection channel to exchange data with the database. Here we go for a socket rather than using a network connection.

In order to find the socket path, input the following commands and look for the UNIX socket line:

$ mysql -u wordpress -p
> status
> quit

Also, in the Authentication tab check that the Authentication type is set to cookie.

Finally, press the green Apply button at the bottom of the configuration section, to save the configuration and return to phpMyAdmin main setup screen.

phpMyAdmin Setup With A Server Config
phpMyAdmin Setup With A Server Config

The Servers section should show the server configuration we just created. Click on the Display button in the Configuration file section to see what this all ends up to.

phpMyAdmin Configuration File
phpMyAdmin Configuration File

As a last step, all there is to do is copy the configuration from the text area, paste and save it to the proper configuration file:

$ cd /var/www/html/phpMyAdmin
$ sudo vi config.inc.php

And voilà, you should be able to log in to MariaDB through phpMyAdmin. Use the wordpress password you’ve created in the part 2 of this series.

phpMyAdmin Home Page As An Authenticated User
phpMyAdmin Home Page As An Authenticated User

3. Additional Considerations

phpMyAdmin is definitely handy, but you don’t necessarily need it. A graphical user interface (GUI) seems easier, but those used to SQL commands may stick to them.

For instance, I mainly used to use phpMyAdmin to backup my WordPress databases. However it’s very easy to do on the command line as well:

$ cd # with no argument change directory to /home/pi
$ mysqldump -u wordpress -p wordpress > wordpress.sql # backup to file
$ mysql -u wordpress -p < wordpress.sql # import

For more detailed information see: How To Import and Export Databases in MySQL or MariaDB.

Furthermore, for security reasons, I would only enable phpMyAdmin access when necessary. Indeed, you don’t want to leave an open door to your database exposed to brute force attack.

$ cd /etc/apache2/conf-enabled/
$ ls -lA
$ sudo a2disconf apache2-doc.conf
$ sudo a2disconf phpmyadmin.conf
$ ls -lA
$ apache2ctl -t
$ sudo systemctl reload apache2

Be aware though that you can improve phpMyAdmin security by enabling 2 factor authentication.

Another valid approach could be to restrict access only through localhost and not from the network.

4. Final Words

I hope you’ve found this last post interesting, even though phpMyAdmin isn’t absolutely necessary it’s still a good exercise to deploy it.

Don’t hesitate to give your feedback. Also please let me know if you find any typo or error, so I can update the post. Thank you !

Leave a comment