If you're following along with the steps to get our MicroK8s environment up and running this part isn't strictly necessary, but getting phpMyAdmin up and running can make the administration of our MySQL installation easier.
As part of this, we'll also look at installing the NGINX webserver and enable this through the built in firewall in Ubuntu.
If you haven't already SSH
into our VM using windows terminal, in my case using the following command.
ssh pete@pl-k8s-vm-1
Install NGINX
To act as our webserver for hosting phpMyAdmin we're going to install NGINX.
This should be pretty quick and easy, simply run the following,
sudo apt update
sudo apt install nginx
Enable Firewall access
Now we've installed NGINX run the following
sudo ufw app list
This will provide us with a list of applications registered with the firewall that we can allow access to. In this instance we'll just enable Nginx HTTP
as we don't require https
access at this point.
...oh, and while we're here we'll also allow OpenSSH access as well.
Run the following commands.
sudo ufw allow 'Nginx HTTP'
sudo ufw allow OpenSSH
Once this is done we can check the status to make sure we're allowed access through the firewall with the following command.
sudo ufw status
This should return something like the following.
Once this is done we can check that the webserver is up and running by launching a web browser on our host machine and simply inputting our VMs hostname, in my case http://pl-k8s-vm-1
, and hopefully you should see the welcome to nginx page.
Installing PHP
Before we can install phpMyAdmin
we need to go ahead and install PHP
and then setup our NGINX
webserver to serve php pages.
Run the following command to install PHP.
sudo apt install php-fpm php-mysql
After this we need to tell NGINX
to process our php pages so run the following to edit the config.
sudo nano /etc/nginx/sites-enabled/default
Within the editor find the line referencing the index files that are processed:
And add
index.php
to the list:
In the same config file find the reference to PHP scripts to FastCGI server
:
And add the following.
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
Exit out of nano CTRL+X, Y, ENTER
, and the get NGINX
to reload its config with the following command.
sudo systemctl reload nginx
Once this is done lets quickly test if PHP
is being correctly processed by NGINX
.
Run the following command to create a demo php file in the route of the webserver.
sudo nano /var/www/html/index.php
And then add the following line of code.
<?php phpinfo(); ?>
Exit out of nano CTRL+X, Y, ENTER
, reload the url we originally used to test our NGINX
install, in my case http://pl-k8s-vm-1/
, and hopefully you should see the PHP Info page:
Install phpMyAdmin
We're almost there, just phpMyAdmin
left to setup.
Run the following command.
sudo apt install phpmyadmin
The installation will run and you'll be presented by a wizard with options to choose from. The first one will ask you to select which webserver to use, now NGINX
won't be in the list, but we won't let that stop us, choose apache2
instead by pressing SPACE
, TAB
then ENTER
.
Next we'll be asked to configure phpMyAdmin:
press ENTER
on YES
and in the next screen set a password of your choice for phpMyAdmin to use to connect to the database server.
Password validation
If during the MySQL
installation you choose to enable a 'Validate Password plugin' you may receive password does not satisfy the current policy requirement
errors when trying to create the phpmyadmin user. If this is the case the easiest way I found to fix it was to choose the option to ignore the error then log into MySQL
with the following command.
mysql -u root -p
Run the following.
UNINSTALL COMPONENT "file://component_validate_password";
and exit out.
You can then run the following to remove and then re-install phpMyAdmin
.
sudo apt remove phpmyadmin
sudo apt install phpmyadmin
This time your password should be accepted. If you then want to re-enable the password validation you can log back into MySQL
and run the following.
INSTALL COMPONENT "file://component_validate_password";
Continuing the phpMyAdmin install
Once the install has completed we want to create a link from the phpmyadmin share to the root of our NGINX
webserver by running the following command.
sudo ln -s /usr/share/phpmyadmin /var/www/html
After this we should be able to access phpMyAdmin
by going to the following address http://pl-k8s-vm-1/phpmyadmin
We can then use the account we setup in Step 2, mine was pluser
with a password of 5ecurePassw0rd!
, to access our MySQL
installation with phpMyAdmin
.
Next Steps
I think we've got everything in place now so it's about time we got something up and running in our new Kubernetes environment. Lets head over to Part 4 to get our docker containers up and running.
Pete
Top comments (0)