DEV Community

Cover image for Making a local MicroK8s environment available externally (Part 3 - NGINX and phpMyAdmin)
Peter Davis
Peter Davis

Posted on

Making a local MicroK8s environment available externally (Part 3 - NGINX and phpMyAdmin)

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Enable Firewall access

Now we've installed NGINX run the following

sudo ufw app list
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

This should return something like the following.

UFW Status

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.

Welcome to NGINX

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Within the editor find the line referencing the index files that are processed:

NGINX Index Before

And add

index.php
Enter fullscreen mode Exit fullscreen mode

to the list:

NGINX Index After

In the same config file find the reference to PHP scripts to FastCGI server:

NGINX PHP Before

And add the following.

location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        }
Enter fullscreen mode Exit fullscreen mode

NGINX PHP After

Exit out of nano CTRL+X, Y, ENTER, and the get NGINX to reload its config with the following command.

sudo systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

And then add the following line of code.

<?php phpinfo(); ?>
Enter fullscreen mode Exit fullscreen mode

NGINX Index PHP

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:

NGINX phpInfo

Install phpMyAdmin

We're almost there, just phpMyAdmin left to setup.

Run the following command.

sudo apt install phpmyadmin
Enter fullscreen mode Exit fullscreen mode

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.

phpMyAdmin Install 1

Next we'll be asked to configure phpMyAdmin:

phpMyAdmin Install 2

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
Enter fullscreen mode Exit fullscreen mode

Run the following.

UNINSTALL COMPONENT "file://component_validate_password";
Enter fullscreen mode Exit fullscreen mode

and exit out.

You can then run the following to remove and then re-install phpMyAdmin.

sudo apt remove phpmyadmin
sudo apt install phpmyadmin
Enter fullscreen mode Exit fullscreen mode

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";
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

After this we should be able to access phpMyAdmin by going to the following address http://pl-k8s-vm-1/phpmyadmin

phpMyAdmin Login

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.

phpMyAdmin Home

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

Buy Me A Coffee

Top comments (0)