No module Published on Offcanvas position

Installing Joomla in Docker with SSL support

If you havn't noticed, this blog is run using Joomla. I always had it installed on a VM but because I needed more Joomla based websites I decided to look into installing Joomla as a Docker container.
Lesson learned, always plan ahead even when you are not sure if it will happen in the future. Saves you the hassle of migrating stuff...

During installing there are some differences compared to installing on a simple VM, so here's a guide.

I've always used Ubuntu but the guide should be adapatble to any Linux distro I guess.
There also way too many guides online in how to install Docker so I won't be convering that and I just assume you have a machine ready to go with Docker installed.

  1. Create a MySQL container where your joomla container can connect to
    docker run --name mysqldbname -d --restart unless-stopped -e MYSQL_ROOT_PASSWORD=rootpasswordhere mysql
    This will download the lastest MySQL version from the docker repository and set the container to restart on reboot
  2. Create the Joomla container
    docker run --name joomlaname --link mysqldbname:mysql -d --restart unless-stopped -p 8082:80 joomla
    This will download the latest Joomla version from the docker repository, set the container to restart on reboot and set the port to 8082 so it can be reached over that.
    However, if you need to run a older version of Joomla because plugins or templates you are running, you need to specify the specific version by doing this: joomla:<versionhere>
    You can find the versions on the Joomla docker page here.

    At this stage, you have a working Joomla docker container and you can access it by going to http://dockerip:portnumber
    If you just want to play around with Joomla and don't care for securing your site, then stop reading and go play.
    Otherwise read on!

  3. Install NGINX
    You need NGINX to correctly route requests to the correct container, also known as a reverse proxy.
    You can choose to install this as a container or on the server itself. I chose to install it on the server itself because in my use cass I don't see the point in puttting it in a container.
    To install NGINX: sudo apt install nginx
  4. Installing the certificate
    It's very possible to use Let's Encrypt for this, but I have my own so I'm using those. First get your certifcates in .crt and .key format, there are many ways to convert them from .pfx if you have it in that format.
    Then move both files to the /etc/ssl/private folder on your Linux machine.

  5. Configuring NGINX to route to your Joomla container
    On your Linux machine, navigate to /etc/nginx/sites-available and create a new file for your website, you can name this file anything you want really but wisest would be to name it after your website.
    Put the following inside the file:


    server {
    root /var/www/html;
    index index.php index.html index.htm;
    server_name my.website.com;

    location / {
    proxy_pass "http://localhost:8082;">http://localhost:8082;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    #try_files $uri $uri/ /index.php?$args;
    }

    location \.php# {
    fastcgi_param HTTPS on;
    }

    listen 443 ssl;
    ssl_certificate /etc/ssl/private/certificate.crt;
    ssl_certificate_key /etc/ssl/private/certificate.key;

    client_max_body_size 100M;
    autoindex off;
    }

    server {
    #if ($host = my.website.com) {
    # return 301 https://$host$request_uri;<br">https://$host$request_uri;<br< a=""> /> #}</br<>

    "https://$host$request_uri;<br">listen 80 ;
    listen [::]:80 ;
    server_name my.website.com;
    return 404;
    }

  6. Enable HTTPS in Joomla
    Login as an administator in your Joomla installation and go to System > Global Configuration > Server tab and set Force HTTPS to Entire Site

If everything went right, when you visit your site it should automatically redirect to HTTPS!
If you need to add more sites, repeat 5 and 6. If it's a new site but a different domain then repeat step 4 to 6 because there's a different certificate involved.
I haven't used Let's Encrypt yet, but I believe it automates much of the process in step 4 to 6, but yeah really usefull if you want free certificates not really much need to buy them nowadays.

Siang Lim