This is a slightly customised installation process for the way I prefer to build things in my home lab. I'm also using this as a chance to see how well the btrfs file system works with MariaDB.
Joomla Installation
Filesystem Preparation
This next step may be considered a little bit non-conventional by most people, but is still a common approach. I do not like running primary applications under /var as it can lead to issues with it filling and breaking things if it's a dedicated filesystem or even worse if it's part of the root filesystem. For this reason I make two changes:
- Apache: The Joomla virtual directory gets it's own filesystem so I can easily snapshot it - and btrfs is ideal for that.
- MariaDB: The joomladb directory gets it's own filesystem - but in hindsight I'm not sure this is the best approach.
The btrfs filesystem is a bit of a curious beast. I find it helps to think of it as a pools of disk space, which can be partitions or entire disks, and out of that you can create multiple directory trees, each with their own root if you want or they can be linked. Another of it's abilities is it lets us create a snapshot of a part of the disk in an instant, hold it for as long as it takes to do a backup while the application keeps writing to the original files and then when done delete the snapshot. It means we don't have to worry about files being changed while the backup is running. And unlike XFS which is another favourite, you can also shrink btrfs disks if you've got your initial sizing wrong.
This is all due to btrfs being a Copy-on-Write filesystem, the downside is on databases if you're making lots of writes to files then it can tie itself in knots as rather than changing files it's constantly copying the entire file to make the changes and then deleting the old which can quickly become a bottleneck, and I'm not using snapshots for the DB backup (at least not yet) so there's minimal gain.
We are going to need 3 subvolumes for this approach, plus a normal directory. Using Ubuntu conventions the root subvolumes will be prefixed with an @ symbol.
- @joomla-srv for the application
- @joomla-db for the database
- A www subvolume of @joomla-srv to hold the Apache2 virtual directory - this can then be the source for backup snapshots
- A backup subdirectory in @joomla-srv where we'll mount backup snapshots and dump the database to.
To prepare our btrfs subvolumes, mount the application disk. This all needs to be done as root.
cd /mnt
mkdir sdc
mount /dev/sdc1 sdc
cd sdc
btrfs subvol create @joomla-srv
btrfs subvol create @joomla-db
cd @joomla-srv
btrfs subvol create www
mkdir -p backup/db
cd ..
umount sdc
We can mount the Apache2 virtual directory now. My preferred method is to do this via /etc/fstab so then you prove that at the same time. Add the following to the end of the file:
# Joomla mounts
/dev/sdc1 /srv/joomla btrfs defaults,subvol=@joomla-srv 0 0
And then apply using mount -a and you should then be able to see a backup and www directory under /srv/joomla
Create the Joomla Database
Login to MariaDB and create the Joomla database and user, and grant the Joomla database user access to the tables. You need to be the root user on the host to log in to the database as root too. The database user can have any name, I've used joomlauser as an example and the DB can also be any name, again I've used joomladb just as an example
root#> mysql -u root -pEnter password:Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 45Server version: 10.3.37-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database joomladb;Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> create user joomlauser@localhost identified by '[**password**]';Query OK, 0 rows affected (0.002 sec)MariaDB [(none)]> grant all on joomladb.* to joomlauser@localhost with grant option;Query OK, 0 rows affected (0.001 sec)MariaDB [(none)]> flush privileges;Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> quit;Bye
The database should now exist in /var/lib/mysql/joomladb and should contain a single db.opt file at this point. Stop mariadb so we can do the filesystem switch. With MariaDB offline (this is really not a production-friendly approach, but it's safe) rename the database directory to something different, e.g. joomladb-orig, and then create a new joomla-db directory to be the mount point for our database filesystem. As a matter of habit I create a notmounted.txt file in mount points just to make it obvious if they go missing.
As before, edit the /etc/fstab to add the mount command by appending
/dev/sdc1 /var/lib/mysql/joomladb btrfs defaults,subvol=@joomla-db 0 0
And then apply using mount -a and then we need to copy the original content back and reset permissions.
cd /var/lib/mysql/joomladbcp -p ../joomladb-orig/* .cd ..chown mysql:mysql joomladbchmod 700 joomladb
You should now be able to restart MariaDB and it won't know or care what happened. It will get upset if you try to drop the database, but that's a drastic option to be taking. I'll also be having a rethink as I'm not 100% happy with this this right now.
Deploy Joomla
Note: The initial download was for Joomla 4.2.8 from https://downloads.joomla.org/ which was the latest version in Feb 2023.
The /srv/joomla/www directory should have been created earlier. Copy the installation zip file to it and unzip the entire file. For Ubuntu 20.04 LTS Install unzip via apt install unzip to do this.
Set www-data:www-data ownership for /srv/joomla/www and all it’s files and subdirectories. Also make sure that at least the group on /srv/joomla is www-data with r-x permissions so Apache can access the files.
Configure PHP.ini
The php.ini also needs to be adjusted. There can be several copies of php.ini, the active one in this installation should be in /etc/php/7.4/apache2/php.ini. Once Joomla is installed it will show the path to the active config file, it's also possible to check in separately with a little bit script once you have the Apache2 config prepared. Just for safety make a copy of the php.ini before you change anything.
memory_limit = 256Mupload_max_filesize
= 128Mpost_max_size =
128Mmax_execution_time
= 300output_buffering =
Offdate.timezone = UTC
Configure Apache2 Virtual Directory
We need to configure a site for Joomla using the configuration file /etc/apache2/sites-available/joomla.conf. This configuration creates a plain HTTP site which is fine for initial setup.
<VirtualHost *:80>
ServerAdmin
DocumentRoot /srv/joomla/www/
ServerName joomlacube-dev.example.com
ErrorLog ${APACHE_LOG_DIR}/joomlacube-error.log
CustomLog ${APACHE_LOG_DIR}/joomlacube-access.log combined
<Directory /srv/joomla/www/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Check the configuration with apachectl -t and then activate with a2ensite joomla.conf and disable the default site with a2dissite 000-default and restart Apache2.
Later on I'll install an internal TLS certificate and switch to HTTPS because we can (and it stops browsers whinging about security). For a publicly accessible site you'll definitely want to enable the use HTTPS as soon as the initial login screen is live. For the initial build and testing it can make troubleshooting easier if you don't have TLS adding to any issues.
You should now be able to get an initial Joomla site in your browser, and if you go to the administrator URL you'll be presented with the initial configuration page.
Bootnote (and spoiler alert)
While performance of MariaDB on Btrfs for a development Joomla was OK given there's very little write activity, this is not something I'd recommend for productive use. For subsequent installs I used XFS for the /var/lib/mysql filesystem and it really became apparent with a Nextcloud deployment (see Test Nextcloud 26 Server Build) that approach works so much better.
I also found trying to have separate filesystems (VM disks) for each DB under /var/lib/mysql isn't worth the bother either.