Thursday, 20 February 2025
  1 Replies
  41 Visits
0
Votes
Undo
  Subscribe
If you want to test and update code, an easy method of creating a Joomla instance is needed. You can of course use a proper server (local or remote) and install Joomla in the regular way, but developing on a live server is generally not the best idea.

Also, if you are making lots of quick tests across many different installation environments, then using a fixed server instance makes it hard to switch between say different php versions.

Traditionally a service like WAMP, XAMP or MAMP provides a virtualised server that provides a local instance of a LAMP or LEMP stack. But this can have it's own challenges as generally changing between PHP versions involves the same process that you use on a regular server, as that's essentially what it is.

This is where using a containerised instance is the way to go. Containerisation is where the entire server instance is bundled within a singe file that can be easily deployed. Think of it more as a lightweight bundle rather than a virtual machine. This allows for easy deployment across different platforms as everything needed is contained within one easy to distribute file. It also means that it is fairly trivial to swap the image or change the configuration. This makes for very quick environment changes. Spinning up a server instance literally only takes a few seconds and allows you to create multiple test environments.

Docker is one such containerisation platform. Let's see how it works...

Using Docker to Create a Joomla test site.

If you are new to Docker, the first thing is to go and install it. Head over to Docker.com and grab a copy of Docker Desktop. There's versions for available for all platforms

Once installed, you will note that there are some tutorials available from within the Docker application. If you are brand new to Docker it's worth running through these to get to grips with how things work.

But if you want to jump straight in, lets take a look at how things work.

compose.yml


services:
joomla:
image: joomla:5.1.4-php8.3-apache
restart: always
ports:
- 51005:80
- 51006:443
environment:
JOOMLA_DB_HOST: db
JOOMLA_DB_USER: joomla
JOOMLA_DB_PASSWORD: db_password
JOOMLA_DB_NAME: joomla_db
JOOMLA_SITE_NAME: Joomla
JOOMLA_ADMIN_USER: DeeEmm
JOOMLA_ADMIN_USERNAME: DeeEmm
JOOMLA_ADMIN_PASSWORD: joomla_password
JOOMLA_ADMIN_EMAIL: deeemm@deeemm.com
volumes:
- ./www:/var/www/html
networks:
- joomla_network
db:
image: mysql:8.1
restart: always
environment:
MYSQL_DATABASE: joomla_db
MYSQL_USER: joomla
MYSQL_PASSWORD: db_password
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db_data:/var/lib/mysql
networks:
- joomla_network

phpmyadmin:
image: phpmyadmin:5.2.1
ports:
- 51011:80
depends_on:
- db
environment:
PMA_HOST: db
networks:
- joomla_network

volumes:
joomla_data:
db_data:

networks:
joomla_network:



The file above is a docker-compose file. It contains all of the information needed to create a server instance in a Docker container. If you are unfamiliar with the YAML language, you might not know that much like Python it uses syntactically significant newlines and indentation. So if you are used to languages like PHP or C++ you are probably used to seeing curly braces to encapsulate data. With YAML delineation is signified by indentation.

This means that the number if indents are critically important. Also equally important is the fact that it uses spaces and not tabs. So depending on how your text editor behaves, or how well that code you cut and pasted from the internet was formatted, it is advisable to convert all tabs to spaces.

Breaking the files Down you can see that there are distinct sections that relate to the different server aspects...


  • Joomla
  • DB
  • phpMyadmin
  • Volumes
  • Networks


Each section defines the settings needed to create the relevant aspect of the server instance.

image: joomla:5.1.4-php8.3-apache


The above line above refers to the container image. This is actually an official Joomla supported Docker image. There are many different versions available. So if you want to spin up a different flavour of PHP or maybe want to use a different style of server or different Joomla version, then you can simply call a different image. You can find all of the official Joomla Docker images listed in the Joomla-Docker Github Repository

Create a project folder

- Next create a folder on your local computer called 'test'. This will be where the files associated with this instance will live.
- Create a file in the folder named compose.yml
- Paste the code snippet above into it (make sure you convert tabs to spaces)
- Create a Folder within the 'test' folder called 'www'

it should look something like this...


Screenshot 2025-02-20 at 8.38.48 pm.png

Now open up a terminal session and navigate to the test folder. Then run the following command...

docker-compose up -d


This command calls the Docker CLI client to read and process the docker-compose.yml file. You will note that it then starts to download and process the data and reports the progress on the screen.

Once it has finished you will note that it will say something similar to the following...


[+] Running 5/5
✔ Network test_joomla_network Created 0.1s
✔ Volume "test_db_data" Created 0.0s
✔ Container test-db-1 Started 10.5s
✔ Container test-joomla-1 Started 10.5s
✔ Container test-phpmyadmin-1 Started


Next lets check Docker Desktop


Docker Desktop Container

You will see that there is now additional information under the Volumes, images and Containers tabs.

The container should be running and you should see a screen similar to the following.

Screenshot 2025-02-20 at 8.11.02 pm.png

If it doesn't load straight away you can click on the container to view the log. It may still be copying files into the www folder. This is where your Joomla files are located.

If you click on the port number for the Joomla instance - 51005:80 it will open your browser and display a brand new Joomla installation. You can log in using the credentials from the compose.yml file.

You can also click on the port number for the phpMyAdmin instance - 51011:80 and edit the database using phpMyAdmin.

If you want to create another instance, simply create another folder i.e. 'test2' and copy the compose.yml file and create a new www folder. and run the docker-compose command again.


File locations

The database itself along with its associated files are not exposed. These reside within the docker container created at build time. You can view and edit the files from the 'Volumes' tab. We mapped the /var/www folder to a local folder so that we can easily access and edit the Joomla files for testing purposes.


volumes:
- ./www:/var/www/html


Note the left side of the colon starts with ./ indicating a local file instance. Whereas the files used for the database use a named reference


volumes:
- db_data:/var/lib/mysql


You will see the db_data folder in the Volumes tab.


What next?

This is only a simple example of how to create a basic Joomla-Docker instance. Docker is powerful enough to do a lot more. You will note from the Docker Tutorials that you can easily save your own instances to the Docker Hub. In fact you will see plenty of different Joomla instances there.
3 weeks ago
·
#30
0
Votes
Undo
Adding a custom php.ini

If you want to edit your php.ini file settings, for example, to increase the upload_max_filesize you first need to create a PHP override file.

Add a file named custom_php.ini to your test folder.
Edit the file and add the following


memory_limit = 32M
upload_max_filesize = 32M


Next we need to map the file to the conf.d override folder by adding the following line to the volumes: section of the joomla: definition within the compose.yml file

- ./custom_php.ini:/usr/local/etc/php/conf.d/custom_php.ini


Like this...


volumes:
- ./www:/var/www/html
- ./custom_php.ini:/usr/local/etc/php/conf.d/custom_php.ini
networks:
- joomla_network


Then re-run the docker compose command

docker-compose up -d


If you check the value of upload_max_filesize in system information > php information tab, you will see that it has now updated to 32M.
  • Page :
  • 1
There are no replies made for this post yet.
Submit Your Response
Upload files or images for this discussion by clicking on the upload button below.
Supported: gif,jpg,png,jpeg,zip,rar,pdf
· Insert · Remove
  Upload Files (Maximum 2MB)