Install Joomla 5 and NGinx on Ubuntu
published on
This tutorial replaces Install Joomla 4 with PHP 8.1 on NGinx and Install Joomla 4 with PHP 8.1 on Apache as we will be installing Joomla V5.
Initial setup
Run sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common language-pack-en-base unzip
to install a few packages which will be needed throughout this guide.
Install NGinx
We will be installing the latest mainline version of NGinx here rather than relying on whatever the latest version happens to be in the Ubuntu repositories.
Run sudo add-apt-repository ppa:ondrej/nginx-mainline
to add the repository and then make sure to uncomment the second line in the /etc/apt/sources.list.d/ondrej-ubuntu-nginx-mainline-*.list
file.
Once you have done this you can run the following commands to install NGinx, make sure it is started and make sure it starts whenever the server reboots:
sudo apt-get update
sudo apt-get install nginx-core nginx-common nginx nginx-full libgeoip-dev libpcre3-dev
sudo systemctl enable nginx
sudo systemctl start nginx
Install PHP 8.2
Install PHP 8.2 and some of the extra modules, along with some other useful software by running the following commands:
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.2-{common,cli,bz2,zip,curl,intl,mysql,snmp,memcached,imagick,gd,imap,ldap,soap,tidy,xml,gmp,pspell,mbstring,opcache,fpm,ssh2,imap,redis,apcu,mcrypt}
sudo apt install ghostscript imagemagick
Configure PHP 8.2
Joomla requires, or recommends, certain configuration settings in PHP. To enable these first make sure the following three lines are uncommented in /etc/php/8.2/fpm/pool.d/www.conf
:
listen = /run/php/php8.2-fpm.sock
listen.owner = www-data
listen.mode = 0660
Now move on to editing /etc/php/8.2/fpm/php.ini
and altering, adding or uncommenting the following lines to look like the ones below:
output_buffering = Off
zlib.output_compression On
zlib.output_compression_level 5
disable_functions = show_source, system, shell_exec, passthru, exec, phpinfo, popen, proc_open
expose_php = off
max_execution_time = 30
max_input_time = 60
max_input_vars = 1000
memory_limit = 512M
post_max_size = 32M
upload_max_filesize = 32M
allow_url_fopen = On
allow_url_include = Off
opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=200
opcache.save_comments=1
opcache.jit_buffer_size=100M
opcache.jit=1255
Finally, restart PHP by running sudo systemctl restart php8.2-fpm
.
Install MariaDB
Run the following commands to install MariaDB and secure it. Make sure to create a root password and answer Y
or Yes
to the other questions:
sudo apt-get install mariadb-server
sudo mysql_secure_installation
Now edit the /etc/mysql/mariadb.conf.d/50-server.cnf
file and add, uncomment or add the following lines:
bind-address = 127.0.0.1
local-infile = 0
Finally, restart MariaDB by running sudo systemctl restart mariadb
.
Create the MariaDB database
Now that you have finished installing MariaDB we need to create the database for your Joomla installation. Run sudo mysql -u root -p
then, at the MYSQL command prompt, enter the following commands:
CREATE DATABASE joomladb;
CREATE USER 'joomladbuser'@'localhost' IDENTIFIED BY 'newpasswordhere';
GRANT ALL ON joomladb.* TO 'joomladbuser'@'localhost' WITH GRANT OPTION;
exit
Change the database name, user and password as required. Make sure to note them down though as you will need them later.
Install Redis
We will be using Redis to act as a cache for Joomla in order to help speed up access to the database. Install it by running the following commands:
sudo apt-get install redis-server php-redis
sudo systemctl enable redis-server.service
Now edit the /etc/redis/redis.conf
and add, uncomment or update the following lines to read like the ones below:
supervised systemd
maxmemory 256mb
maxmemory-policy allkeys-lru
bind 127.0.0.1 ::1
Finally, restart Redis with sudo systemctl restart redis.service
.
Download Joomla
Now that we have finished doing a lot of the preparation we can download Joomla. To do this run the following set of commands. Make sure to change [domain] to the domain name of your Joomla site.
sudo mkdir /var/www/[domain]
cd ~
wget https://downloads.joomla.org/cms/joomla5/5-0-2/Joomla_5-0-2-Stable-Full_Package.zip?format=zip -OJoomla_5-0-2-Stable-Full_Package.zip
unzip Joomla_5-0-2-Stable-Full_Package.zip
rm Joomla_5-0-2-Stable-Full_Package.zip
sudo mv * /var/www/[domain]
sudo chown -R www-data:www-data /var/www/[domain]
sudo find /var/www/[domain] -type d -exec chmod 755 {} \;
sudo find /var/www/[domain] -type f -exec chmod 644 {} \;
Create the Joomla server block
We now have NGinx installed and Joomla downloaded. However, NGinx hasn't been configured to let us access Joomla over the internet yet.
We will set this up by creating a new file with sudo nano /etc/nginx/sites-available/[domain].conf
and adding the following lines:
server {
listen 80;
listen [::]:80;
root /var/www/[domain];
index index.php;
server_name [domain] www.[domain];
autoindex off;
access_log /var/log/openresty/[domain]_access.log combined;
error_log /var/log/openresty/[domain]_error.log warn;
charset utf-8;
source_charset utf-8;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Make sure to replace [domain]
with the domain name of your Joomla site.
Now enable your new site configuration by running:
sudo ln -s /etc/nginx/sites-available/[domain].conf /etc/nginx/sites-enabled/
sudo systemctl restart nginx
Set up a TLS certificate
We now want to make sure that everyone accesses the site over HTTPS so we are going to run the following set of commands to install certbot, create a certificate and configure NGinx with it:
sudo apt-get install snapd
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot -d [domain] -d www.[domain] --nginx
Finishing off the installation
We are now nearly at the end of the guide. The penultimate thing to do now is to visit [domain]
in your browser and follow the instructions in order to setup your new Joomla installation.
Once Joomla has been installed login to the backend (the admin panel), navigate to System then Global Configuration then System (in the centre of the screen) and finally change Cache to Conservative caching
.
This now gives you some other options which should be edited as below:
Cache-Handler: Redis
Platform Specific Caching: No
Cache Time: 30
Persistent Redis: Yes
Redis Server Host: localhost
Redis Server Port: 6379
Redis Server Authentication: [leave as is]
Redis Database: 0
Finally, click on Save & Close
and enjoy your new site.