Joomla website with PostgreSQL
- Prepare your cloud
- Create a VM for Joomla
- Create a PostgreSQL database cluster
- Install Joomla and additional components
- Configure the Apache2 web server
- Configure Joomla
- Upload the website files
- Configure the DNS
- Check that the website is running
- How to delete the resources you created
- How to create an infrastructure using Terraform
This tutorial will teach you to deploy websites powered by Joomla CMS and using the PostgreSQL database management system in a Yandex Cloud infrastructure.
To set up a static website on Joomla:
- Create a VM for Joomla.
- Create a PostgreSQL database cluster.
- Install Joomla and additional components.
- Configure the Apache2 web server.
- Configure Joomla.
- Upload the website files.
- Configure the DNS.
- Check that the website is running.
If you no longer need the website, delete all its resources.
You can also deploy the infrastructure for hosting a website based on the Joomla CMS with a PostgreSQL DB via Terraform using a ready-made configuration file.
Prepare your cloud
Sign up for Yandex Cloud and create a billing account:
- Go to the management console
and log in to Yandex Cloud or create an account if you do not have one yet. - On the Billing
page, make sure you have a billing account linked and it has theACTIVE
orTRIAL_ACTIVE
status. If you do not have a billing account, create one.
If you have an active billing account, you can go to the cloud page
Learn more about clouds and folders.
Make sure that the selected folder contains a network with subnets in the ru-central1-a
, ru-central1-b
, and ru-central1-c
availability zones. To do this, select Virtual Private Cloud on the folder page. If the list contains a network, click on its name to see the list of subnets. If the subnets or network you need are not listed, create them.
Required paid resources
The cost of hosting a Joomla-powered website includes:
- Fee for a continuously running VM (see Yandex Compute Cloud pricing).
- Fee for using a dynamic or static public IP (see Yandex Virtual Private Cloud pricing).
- Fee for a PostgreSQL DB cluster (see pricing Yandex Managed Service for PostgreSQL).
- Cost of outgoing traffic from Yandex Cloud to the internet (see Yandex Compute Cloud pricing).
Create a VM for Joomla
-
On the folder page in the management console
, click Create resource and select Virtual machine. -
Use the Name field to enter a VM name, such as
joomla-pg-tutorial-web
. -
Select an availability zone to place the VM in.
-
Under Image/boot disk selection, go to the Cloud Marketplace tab and select CentOS Stream as your public image.
-
Under Computing resources:
- Choose a platform.
- Specify the required number of vCPUs and the amount of RAM.
The minimum configuration is enough for functional testing:
- Platform: Intel Ice Lake.
- Guaranteed vCPU share: 20%.
- vCPU: 2.
- RAM: 1 GB.
-
In Network settings, select the subnet to connect the VM to once it is created.
-
Enter the VM access information:
- Enter the username in the Login field.
- In the SSH key field, paste the contents of the public key file.
You will need to create a key pair for the SSH connection yourself. To create keys, use third-party tools, such asssh-keygen
(on Linux or macOS) or PuTTYgen (on Windows).
-
Click Create VM.
It may take a few minutes to create the VM.
Once created, the VM is assigned an IP address and a host name (FQDN). This data can be used for SSH access.
Create a PostgreSQL database cluster
- On the folder page, click Create resource and select PostgreSQL cluster.
- In the Name field, enter the cluster name:
joomla-pg-tutorial-db-cluster
. - Under Host class, select the appropriate host class.
- In the Storage size section, enter 10 GB.
- In the Database section, specify:
- DB name:
joomla-pg-tutorial-db
. - Username:
joomla
. - Password: The password you'll use to access the database.
- DB name:
- In the Network list, select the network your VM is connected to.
- In the Hosts section, add two more hosts in the other availability zones. When creating hosts, do not enable Public access to them.
- Click Create cluster.
Creating a DB cluster may take a few minutes.
Install Joomla and additional components
After the joomla-pg-tutorial-web
VM's status changes to RUNNING
:
-
Under Network on the VM page in the management console
find the VM's public IP address. -
Connect to the VM via SSH. You can use the
ssh
utility in Linux or macOS, or PuTTY in Windows.The recommended authentication method when connecting over SSH is using a key pair. Don't forget to configure using the generated key pair: the private key must match the public key sent to the VM.
-
Download and unpack the Joomla 3.8.7 archive:
CentOS Streamsudo mkdir -p /var/www/html/ curl https://github.com/joomla/joomla-cms/releases/download/3.8.7/Joomla_3.8.7-Stable-Full_Package.tar.gz?format=gz -o Joomla_3-8-7-Stable-Full_Package.tar.gz -L sudo mv Joomla_3-8-7-Stable-Full_Package.tar.gz /var/www/html/ (cd /var/www/html/ && sudo tar -zxvf Joomla_3-8-7-Stable-Full_Package.tar.gz) sudo rm /var/www/html/Joomla_3-8-7-Stable-Full_Package.tar.gz sudo mv /var/www/html/htaccess.txt /var/www/html/.htaccess
-
Install additional components:
CentOS Streamsudo dnf install epel-release sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm sudo yum -y install --enablerepo remi-modular httpd php php-pgsql php php-common php-mbstring php-zip php-xml nano wget php-json sudo dnf module enable postgresql:13 sudo dnf install postgresql-server
-
Get and configure the SSL certificate:
CentOS Streamsudo mkdir ~apache/.postgresql sudo wget "https://crls.yandex.net/allCLCAs.pem" -O ~apache/.postgresql/root.crt sudo chmod 0600 ~apache/.postgresql/root.crt sudo chown -R apache:apache ~apache/.postgresql
Configure the Apache2 web server
-
Perform the basic configuration of Apache2:
CentOS Streamsudo chown -R apache /var/www/html/
-
Specify the virtual host settings in the Apache2 configuration file. You can edit files in the
nano
editor:CentOS Streamsudo nano /etc/httpd/conf.d/joomla.conf
Make the file look like:
<VirtualHost *:80 [::]:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/ <Directory /var/www/html/> DirectoryIndex index.php index.html DirectorySlash off RewriteEngine on RewriteBase / AllowOverride all </Directory> </VirtualHost>
-
Restart the web server:
CentOS Streamsudo service httpd restart
-
Change the settings:
CentOS Streamsudo restorecon -R /var/www/html sudo setsebool -P httpd_can_network_connect 1
Configure Joomla
Configure Joomla following the instructions
-
Get the addresses of the DB cluster hosts in the management console:
- Open the folder where the DB cluster was created and select Managed Service for PostgreSQL.
- Select the cluster
joomla-pg-tutorial-db-cluster
. - Open the Hosts tab.
- Copy the host addresses from the Host name column.
-
At the Database step, fill in the following fields in the Joomla web installer:
-
Database type:
PostgreSQL
. -
DB server name:
<address of host 1>,<address of host 2>,<address of host 3> port=6432 sslmode=verify-full target_session_attrs=read-write
-
Username:
joomla
. -
Password: enter the DB user's password.
-
DB name:
joomla-pg-tutorial-db
.
-
-
For security reasons, Joomla may ask you to create or delete a special test file. On the VM, go to the
/var/www/html/installation
folder and create or delete the specified file there. -
Create an empty file
configuration.php
to safe configuration and configure write permissions for the folder:sudo touch /var/www/html/configuration.php sudo chmod 655 /var/www/html/configuration.php sudo chown -R apache:apache /var/www/html/ sudo restorecon -R /var/www/html
-
After the installation is completed, delete the
installation
directory. This is a Joomla security requirement:sudo rm -rf /var/www/html/installation
Upload the website files
-
Under Network on the VM page in the management console
find the VM's public IP address. -
Connect to the VM via SSH.
-
Grant your user write access to the directory
/var/www/html
:sudo chown -R "$USER":apache /var/www/html
-
Upload the website files to the VM via SCP
.Linux/macOSWindowsUse the
scp
command-line utility:scp -r <path to the file directory> <VM username>@<VM IP address>:/var/www/html
Use WinSCP
to copy the local file directory to/var/www/html
on the VM.
Configure the DNS
You need to bind the domain name you wish to use for your website to the created joomla-pg-tutorial-web
VM. You can use the Cloud DNS service to manage your domain.
The tutorial below describes configuring DNS for the example.com
domain name.
Add a zone
To add a public zone:
- Open the Cloud DNS section of the folder where you need to create a DNS zone.
- Click Create zone.
- Specify the zone settings:
- Zone name:
example-zone-1
. - Zone:
example.com
. Specify your registered domain. - Type: Public.
- Zone name:
- Click Create.
Add resource records
Create DNS records in the public zone:
- Under Network on the VM page in the management console
find the VM's public IP address. - Create an A record:
- Open the Cloud DNS section of the folder where the
example.com
zone is located. - Select
example.com
from the list. - Click Create record.
- Set the record parameters:
- Name: Leave empty.
- Record type: Keep
A
as the value. - TTL (record time to live): Leave the default.
- Value: Enter your VM's public address.
- Click Create.
- Open the Cloud DNS section of the folder where the
- Create a CNAME record:
- Select
example.com
from the list. - Click Create record.
- Set the record parameters:
- Name:
www
. - Record type: Select
CNAME
as the value. - TTL (record time to live): Leave the default.
- Value: Enter
example.com
.
- Name:
- Click Create.
- Select
Delegate the domain name
Delegation is the transfer of authority from the registrar's servers to yours. For a domain, NS resource records are created (ns1.yandexcloud.net
and ns2.yandexcloud.net
).
To delegate a domain, specify its DNS servers in the registrar's account.
Delegation does not take effect immediately. It normally takes internet service providers up to 24 hours (86400 seconds) to update records. This depends on the TTL value which determines how long domain records are cached.
You can verify domain delegation using the Whoisdig
utility:
dig +short NS example.com
Result:
ns2.yandexcloud.net.
ns1.yandexcloud.net.
Check that the website is running
To check that the site is up, enter its IP address or domain name in your browser:
http://<virtual machine public IP address>
.http://www.example.com
.
How to delete the resources you created
To stop paying for the resources you created:
- Delete the VM.
- Delete the static public IP if you reserved one.
- Delete the Managed Service for PostgreSQL cluster.
How to create an infrastructure using Terraform
With Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically determines which part of your configuration is already deployed and what should be added or removed.
To create infrastructure for your Joomla-based website with a PostgreSQL DB:
-
Install Terraform and specify the source for installing the Yandex Cloud provider (see Configure a provider, step 1).
-
Prepare a file with the infrastructure description:
Ready-made archiveCreating files manually- Create a directory for the file with the infrastructure description.
- Download the archive
(2 KB). - Unpack the archive to the directory. As a result, it should contain the
joomla-postgresql-terraform.tf
configuration file and thejoomla-postgresql-terraform.auto.tfvars
file with user data.
-
Create a directory for the file with the infrastructure description.
-
In the directory, create a configuration file named
joomla-postgresql-terraform.tf
:joomla-postgresql-terraform.tf# Declaring variables for custom parameters variable "folder_id" { type = string } variable "vm_user" { type = string } variable "ssh_key_path" { type = string } variable "db_user" { type = string } variable "db_password" { type = string sensitive = true } variable "dns_zone" { type = string } variable "dns_recordset_name" { type = string } # Adding other variables locals { network_name = "example-network" subnet_name1 = "subnet-1" subnet_name2 = "subnet-2" subnet_name3 = "subnet-3" sg_vm_name = "sg-vm" sg_pgsql_name = "sg-pgsql" vm_name = "joomla-pg-tutorial-web" cluster_name = "joomla-pg-tutorial-db-cluster" db_name = "joomla-pg-tutorial-db" dns_zone_name = "example-zone-1" } # Setting up the provider terraform { required_providers { yandex = { source = "yandex-cloud/yandex" version = ">= 0.47.0" } } } provider "yandex" { folder_id = var.folder_id } # Creating a cloud network resource "yandex_vpc_network" "joomla-pg-network" { name = local.network_name } # Creating a subnet in the ru-central1-a availability zone resource "yandex_vpc_subnet" "joomla-pg-network-subnet-a" { name = local.subnet_name1 zone = "ru-central1-a" v4_cidr_blocks = ["10.128.0.0/24"] network_id = yandex_vpc_network.joomla-pg-network.id } # Creating a subnet in the ru-central1-b availability zone resource "yandex_vpc_subnet" "joomla-pg-network-subnet-b" { name = local.subnet_name2 zone = "ru-central1-b" v4_cidr_blocks = ["10.129.0.0/24"] network_id = yandex_vpc_network.joomla-pg-network.id } # Creating a subnet in the ru-central1-d availability zone resource "yandex_vpc_subnet" "joomla-pg-network-subnet-d" { name = local.subnet_name3 zone = "ru-central1-d" v4_cidr_blocks = ["10.130.0.0/24"] network_id = yandex_vpc_network.joomla-pg-network.id } # Creating a security group for a PostgreSQL database cluster resource "yandex_vpc_security_group" "pgsql-sg" { name = local.sg_pgsql_name network_id = yandex_vpc_network.joomla-pg-network.id ingress { description = "PostgreSQL" port = 6432 protocol = "TCP" v4_cidr_blocks = ["0.0.0.0/0"] } } # Creating a security group for a VM resource "yandex_vpc_security_group" "vm-sg" { name = local.sg_vm_name network_id = yandex_vpc_network.joomla-pg-network.id egress { protocol = "ANY" description = "ANY" v4_cidr_blocks = ["0.0.0.0/0"] from_port = 0 to_port = 65535 } ingress { description = "HTTP" protocol = "TCP" v4_cidr_blocks = ["0.0.0.0/0"] port = 80 } ingress { description = "HTTPS" protocol = "TCP" v4_cidr_blocks = ["0.0.0.0/0"] port = 443 } ingress { description = "SSH" protocol = "ANY" v4_cidr_blocks = ["0.0.0.0/0"] port = 22 } } # Adding a pre-configured VM image resource "yandex_compute_image" "joomla-pg-vm-image" { source_family = "centos-stream-8" } resource "yandex_compute_disk" "boot-disk" { name = "bootvmdisk" type = "network-hdd" zone = "ru-central1-a" size = "10" image_id = yandex_compute_image.joomla-pg-vm-image.id } # Creating a VM resource "yandex_compute_instance" "joomla-pg-vm" { name = local.vm_name platform_id = "standard-v3" zone = "ru-central1-a" resources { cores = 2 memory = 1 core_fraction = 20 } boot_disk { disk_id = yandex_compute_disk.boot-disk.id } network_interface { subnet_id = yandex_vpc_subnet.joomla-pg-network-subnet-a.id nat = true security_group_ids = [ yandex_vpc_security_group.vm-sg.id ] } metadata = { user-data = "#cloud-config\nusers:\n - name: ${var.vm_user}\n groups: sudo\n shell: /bin/bash\n sudo: 'ALL=(ALL) NOPASSWD:ALL'\n ssh-authorized-keys:\n - ${file("${var.ssh_key_path}")}" } } # Creating a PostgreSQL database cluster resource "yandex_mdb_postgresql_cluster" "joomla-pg-cluster" { name = local.cluster_name environment = "PRODUCTION" network_id = yandex_vpc_network.joomla-pg-network.id security_group_ids = [ yandex_vpc_security_group.pgsql-sg.id ] config { version = "14" resources { resource_preset_id = "b2.medium" disk_type_id = "network-ssd" disk_size = 10 } } host { zone = "ru-central1-a" subnet_id = yandex_vpc_subnet.joomla-pg-network-subnet-a.id } host { zone = "ru-central1-b" subnet_id = yandex_vpc_subnet.joomla-pg-network-subnet-b.id } host { zone = "ru-central1-d" subnet_id = yandex_vpc_subnet.joomla-pg-network-subnet-d.id } } # Creating a database resource "yandex_mdb_postgresql_database" "joomla-pg-tutorial-db" { cluster_id = yandex_mdb_postgresql_cluster.joomla-pg-cluster.id name = local.db_name owner = var.db_user } # Creating a database user resource "yandex_mdb_postgresql_user" "joomla-user" { cluster_id = yandex_mdb_postgresql_cluster.joomla-pg-cluster.id name = var.db_user password = var.db_password } # Creating a DNS zone resource "yandex_dns_zone" "joomla-pg" { name = local.dns_zone_name zone = var.dns_zone public = true } # Creating a type A resource record resource "yandex_dns_recordset" "joomla-pg-a" { zone_id = yandex_dns_zone.joomla-pg.id name = var.dns_recordset_name type = "A" ttl = 600 data = [ yandex_compute_instance.joomla-pg-vm.network_interface.0.nat_ip_address ] } # Creating a CNAME resource record resource "yandex_dns_recordset" "joomla-pg-cname" { zone_id = yandex_dns_zone.joomla-pg.id name = "www" type = "CNAME" ttl = 600 data = [ var.dns_zone ] }
-
In the directory, create a
joomla-postgresql-terraform.auto.tfvars
file with user data:joomla-postgresql-terraform.auto.tfvarsfolder_id = "<folder ID>" vm_user = "<VM_username>" ssh_key_path = "<path_to_public_SSH_key>" db_user = "<database_username>" db_password = "<database_password>" dns_zone = "<DNS_zone>" dns_recordset_name = "<DNS_record_name>"
For more information about the resources you can create with Terraform, see the provider documentation
. -
In the
joomla-postgresql-terraform.auto.tfvars
file, set the user-defined parameters:folder_id
: ID of the folder.vm_user
: VM username.ssh_key_path
: Path to the file with a public SSH key to authenticate the user on the VM. For details, see Creating an SSH key pair.db_user
: Database username, e.g.,joomla
.db_password
: Password for the database. The password length must be between 8 and 128 characters.dns_zone
: DNS zone. Specify your registered domain, e.g.,example.com.
.dns_recordset_name
: Name of the record set, e.g.,example-recordset
.
-
Create resources:
-
In the terminal, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
in the terminal and press Enter.
-