Translate

Sunday, May 11, 2025

Install Joomla on Docker - APKH

I used Joomla for many websites, this is a procedure to install Joomla on a Docker container rather than the traditional set up on a server.

The advantage is the capability to install different versions of Joomla for tests/development or data retrieval from older backups.

Goals

This exercise has some goals :
  • be able to install a Joomla website on a machine.
    It can be a server or a local machine for tests
  • set up a Joomla website procedure

Install Docker

It is implicit to have installed on the machine (local or server) Docker and Docker Composer.
Many articles are available for instructions.
This article assumes to use Linux or MacOs.

Docker settings

First is necessary to set up the basics for the service.
Joomla need a database to work and the DB itself need to be run in a docker container, thus is necessary to have an "external" volume in order to save the DB itself and not lose it if the DB container is shut down.

The Joomla data and DB will be stored where other Docker services have the volume.
Note ! Instead to create a volume with docker, the idea is to manually set up an area somewhere and then "attach" that area as volume.
In this way is possible to better organize the area for backup or third part access.

Let create a directory somewhere called dockerPS that will contains all Joomla based sites.
On a server will be from the root, on a local machine will be under the user.
Since the idea is to be able to have more than one Joomla website, consider to use path to differentiate them,

For example :
  • /dockerPS/joomla/site1/mysql   --> database for Joomla site1
  • /dockerPS/joomla/site1/site    --> where the site1 will reside
The docker compose yml file will be something like :

version: '3.1'

services:
  joomla:
    image: joomla
    restart: always
    links:
      - joomladb:mysql
    ports:
      - 8005:80
    volumes:
      - ~/dockerPS/joomla/site1/site:/var/www/html
    environment:
      JOOMLA_DB_HOST: joomladb
      JOOMLA_DB_PASSWORD: <password_for_db>

  joomladb:
    image: mysql:5.7
    ports:
      - 3306:3306
    restart: always
    volumes:
      - ~/dockerPS/joomla/site1/mysql:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: <password_for_db>

Notes

  • image : it defines what version of Joomla is used. As in the example will be the latest stable
  • ports: every Joomla website should use a different port
  • volumes: set up the path for the dockerPS - for local installations, use ~/dockerPS, for server installations use /dockerPS
  • JOOMLA_DB_PASSWORD: it defines the password to be used in the DB, it must match te MYSQL_ROOT_PASSWORD in the joomladb section
    The same password will be asked in the Joomla installation process

The yml file will be saved somewhere, in the example the yml file will be called joomla-site1-docker-compose.yml.
First create a dockerPS directory, for this example let assume to install Joomla on a local machine for tests, not on a server, thus lets create a directory dockerPS :  mkdir -p  ~/dockerPS/joomla

To install/run it, go where the yml file is, then execute :

docker-compose -f joomla-site1-docker-compose.yml up -d

If everything works, Joomla code will be present in the ~/dockerPS/joomla/site1 directory (or /dockerPS/joomla/site1).
The database will be present in the ~/dockerPS/joomla/site1/mysql directory

Note : the password used in the yml file is : test

Installing Joomla


After the Docker-compose finish its job, will be possible to access to the site for the installation (the first time).

Open a browser and access the url : localhost:8005
It should appear the initial setting page for Joomla. At the time of this example Joomla installed was the version 

Connection to the DB from outside


Since the port 3306 is exposed, it is possible to connect to the DB from outside the server.
To do so use any MySQL client, in my case I did use DBeaver  and created a connection for MySql.


Use the local IP of the server, the user root and the password defined in the dockerfile.
Since the port is not enabled on the router, only local computers will be able to connect with the DB.
Leaving empty the Database field will show all the database present in the server.
I left all the rest of the fields as defaults.

Setting up the site

At this point is possible to start to configure Joomla itself for the specific site.
To do so is enough to go on a browser and point to the server IP on the port specified, in our case 8015.

DB settings

The only things to know at this stage are :
  • Host name :  joomladb
  • Username  : root
  • Password   : <password_for_db>   (the one defined in the yml file) 
  • Database Name : joomladb

Other settings


The other settings are intuitive.

Resources


tf:~$ docker run -d --name joomladb  -v mysql-data:/var/lib/mysql --network joomla-network -e "MYSQL_ROOT_PASSWORD=bauBAUmici0mici0" -e MYSQL_USER=joomla -e "MYSQL_PASSWORD=bauBAUmici0mici0" -e "MYSQL_DATABASE=joomla" mysql:5.7

aff17ec30c27252a6fbf9a349717b207d5b254e19d74a69eceb6b845a41cfe97

tf:~$ docker volume create joomla-data


joomla-data

tf:~$ docker run -d --name joomla -p 8005:80 -v joomla-data:/var/www/html --network joomla-network -e JOOMLA_DB_HOST=joomladb -e JOOMLA_DB_USER=joomla -e JOOMLA_DB_PASSWORD=bauBAUmici0mici0 joomla

85a3043b9088dada55ca12ee3bf191db54c53238aa2f19b9f4392f5158796d02

tf:~$ 

No comments:

Post a Comment