Joomla-based website with PostgreSQL
In these instructions, you'll learn how to deploy a website in Joomla CMS on a database running PostgreSQL in the Yandex.Cloud infrastructure.
To set up a static website on Joomla:
- Create a VM for Joomla.
- Create a PostgreSQL DB cluster.
- Install Joomla and additional components.
- Configure the Apache2 web server.
- Configure Joomla.
- Upload the website files.
- Configure DNS.
- Check that the website is running.
If you no longer need the website, delete all its resources.
Before you start
Before deploying the server, you need to sign up for Yandex.Cloud and create a billing account:
- Go to the management console. Then log in to Yandex.Cloud or sign up if don't already have an account.
- On the billing page, make sure you linked a billing account, and it has the
ACTIVE
orTRIAL_ACTIVE
status. If you don't have a billing account, create one.
If you have an active billing account, you can create or select a folder to run your VM in from the Yandex.Cloud page.
Learn more about clouds and folders.
Make sure the selected folder has a network with subnets in the availability zones ru-cental1-a
, ru-central1-b
, and ru-central1-c
. To do this, select Yandex 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 website in Joomla includes:
- A fee for a continuously running VM (see Yandex Compute Cloud pricing).
- A fee for using a dynamic or static external IP address (see Yandex Virtual Private Cloud pricing).
- A fee for the PostgreSQL database cluster (see pricing for Yandex Managed Service for PostgreSQL).
- The cost of outgoing traffic from Yandex.Cloud to the internet (see Yandex Compute Cloud pricing).
Create a VM for Joomla
To create a VM:
-
On the folder page in the management console, click Create resource and select Virtual machine.
-
In the Name field, enter the VM name:
joomla-pg-tutorial-web
. -
Select the availability zone to host the VM in.
-
Select the Ubuntu or CentOS public image.
-
Under Computing resources:
- Choose a platform.
- Specify the necessary number of vCPUs and amount of RAM.
The minimum configuration is enough for functional testing:
- Platform: Intel Cascade Lake.
- Guaranteed vCPU share: 5%.
- vCPU: 2.
- RAM: 1 GB.
-
In the Network settings section, select the subnet to connect the VM to when creating it.
-
Specify data required for accessing the VM:
- Enter the username in the Login field.
- In the SSH key field, paste the contents of the public key file.
You need to create a key pair for an SSH connection yourself. To generate keys, use third-party tools, such asssh-keygen
utilities on Linux and macOS or PuTTygen on Windows.
-
Click Create VM.
Creating the VM may take several minutes.
When a VM is created, it is assigned an IP address and hostname (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
. - In the DB class section, select b2.medium.
- In the Storage size section, enter 10 GB.
- In the Database section:
- In the DB name field, enter
joomla-pg-tutorial-db
. - In the Username field, enter
joomla
. - In the Password field, enter the password you will use to access the DB.
- In the DB name field, enter
- 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 the DB cluster may take several minutes.
Install Joomla and additional components
After the joomla-pg-tutorial-web
VM's status changes to RUNNING
, do the following:
-
You can learn the IP address of the VM under Network on the VM page in the management console.
-
Connect to the VM over SSH. You can use the
ssh
tool in Linux and macOS or PuTTY for Windows.The recommended authentication method when connecting over SSH is using a key pair. Don't forget to set up the created key pair: the private key must match the public key sent to the VM.
-
Download and unpack the Joomla archive:
$ sudo mkdir -p /var/www/html/ $ curl https://downloads.joomla.org/cms/joomla3/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:
Ubuntu 14Ubuntu 16Ubuntu 18CentOS 6CentOS 7$ echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list $ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - $ sudo apt-get update $ sudo apt-get -q -y install php5-pgsql php5-curl php5-json php5-cgi php5 libapache2-mod-php5 php5-mcrypt apache2 php5-common cron debconf-utils sendmail unzip iptables postgresql-client-10 $ sudo mkdir ~www-data/.postgresql $ sudo wget "https://crls.yandex.net/allCLCAs.pem" -O ~www-data/.postgresql/root.crt $ sudo chmod 0600 ~www-data/.postgresql/root.crt $ sudo chown -R www-data:www-data ~www-data/.postgresql
$ echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list $ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - $ sudo apt-get update $ sudo apt-get -q -y install php7.0-pgsql php7.0-curl php7.0-json php7.0-cgi php7.0 libapache2-mod-php7.0 php7.0-mcrypt apache2 php-mail php7.0-common cron debconf-utils sendmail unzip iptables composer postgresql-client-10 $ sudo mkdir ~www-data/.postgresql $ sudo wget "https://crls.yandex.net/allCLCAs.pem" -O ~www-data/.postgresql/root.crt $ sudo chmod 0600 ~www-data/.postgresql/root.crt $ sudo chown -R www-data:www-data ~www-data/.postgresql
$ echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list $ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - $ sudo apt-get update $ sudo apt-get -q -y install php7.2-pgsql php7.2-curl php7.2-json php7.2-cgi php7.2 libapache2-mod-php7.2 apache2 php-mail php7.2-common cron debconf-utils sendmail unzip iptables composer postgresql-client-10 $ sudo mkdir ~www-data/.postgresql $ sudo wget "https://crls.yandex.net/allCLCAs.pem" -O ~www-data/.postgresql/root.crt $ sudo chmod 0600 ~www-data/.postgresql/root.crt $ sudo chown -R www-data:www-data ~www-data/.postgresql
$ sudo yum -y install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-centos10-10-2.noarch.rpm $ sudo yum -y install http://rpms.famillecollet.com/enterprise/remi-release-6.rpm $ sudo yum check-update $ sudo yum -y install --enablerepo remi-php72 httpd php php-pgsql php php-common php-mbstring php-zip php-xml nano wget postgresql10 $ sudo 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
$ sudo yum -y install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm $ sudo yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm $ sudo yum check-update $ sudo yum -y install --enablerepo remi-php72 httpd php php-pgsql php php-common php-mbstring php-zip php-xml nano wget postgresql10 $ sudo 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:
Ubuntu 14Ubuntu 16Ubuntu 18CentOS$ sudo a2enmod php5 $ sudo a2dismod mpm_event $ sudo a2enmod mpm_prefork $ sudo a2enmod rewrite $ sudo chown -R www-data /var/www/html/
$ sudo a2enmod php7.0 $ sudo a2dismod mpm_event $ sudo a2enmod mpm_prefork $ sudo a2enmod rewrite $ sudo chown -R www-data /var/www/html/
$ sudo a2enmod php7.2 $ sudo a2dismod mpm_event $ sudo a2enmod mpm_prefork $ sudo a2enmod rewrite $ sudo chown -R www-data /var/www/html/
$ sudo chown -R apache /var/www/html/
-
Specify the virtual host settings in the Apache2 configuration file. You can edit the file in the
nano
editor:UbuntuCentOS$ sudo nano /etc/apache2/sites-enabled/000-default.conf
$ sudo 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:
UbuntuCentOS$ sudo service apache2 restart
$ sudo service httpd restart
-
This step should only be performed on a VM running CentOS.
Change the SELinux settings:
$ sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/html(/.*)?" $ sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html(/.*)?" $ sudo restorecon -R /var/www/html $ setsebool -P httpd_can_network_connect 1
-
This step should only be performed on a VM running CentOS 6.
Open network ports 80 and 443 using the
iptables
utility:$ sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT $ sudo iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT $ sudo iptables-save | sudo tee /etc/sysconfig/iptables
Configure Joomla
Configure Joomla following the instructions on the project website.
During the configuration process, you'll need the DB connection settings. To get the parameters and configure them correctly, do the following:
-
Get the addresses of the DB cluster hosts in the management console:
- Open the folder where the DB cluster was created.
- Select Managed Service for PostgreSQL.
- Select the cluster
joomla-pg-tutorial-db-cluster
. - Open the Hosts tab.
- In the Address (domain name) column, find the host addresses.
-
At the Database step, fill in the following fields in the Joomla web installer:
-
DB 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 delete a special test file. On the VM, go to the /var/www/html/installation
directory and delete the specified file from it.
Upload the website files
-
You can learn the IP address of the VM under Network on the VM page in the management console.
-
Connect to the VM over SSH.
-
Grant your user write access to the directory
/var/www/html
:UbuntuCentOS$ sudo chown -R "$USER":www-data /var/www/html
$ sudo chown -R "$USER":apache /var/www/html
-
Upload the website files to the VM over SCP:
Linux/macOSWindowsUse the
scp
command-line utility:$ scp -r <path to the file directory> <VM user name>@<VM IP address>:/var/www/html
Use the WinSCP program to copy the local file directory to the
/var/www/html
directory on the VM.
Configure the DNS
The domain name that you want to use for your website must be associated with the created joomla-pg-tutorial-web
VM.
The instructions below describe how to configure an external DNS service using reg.ru for the www.example.com
and example.com
domain names:
- An A record allows you to map the
example.com
domain name to its IP address. - A CNAME (Canonical Name) record for
www
allows you to access your website viawww.example.ru
.
To configure the external DNS service, do the following:
- You can learn the IP address of the VM under Network on the VM page in the management console.
- Log in to the control panel of the external DNS service. Go to the list of your domains and click on the required domain name.
- Follow the Zone management link in the Domain management section.
- Create or edit an A record:
- IP Address: your VM's public IP address.
- Subdomain:
@
(points to the main domain).
- Create a CNAME record with the following field values:
- Subdomain:
www
. - Canonical name:
@
or theexample.com.
domain with a dot at the end.
- Subdomain:
- Wait 15-20 minutes for DNS record changes to take effect. The waiting time may differ for your DNS service.
Check that the website is running
To test the website, open it in the browser at: http://<VM public IP address>
.
You can check the domain name the same way only 15-20 minutes after editing the DNS records.
How to delete created resources
To stop paying for your deployed server and DB, just delete the created VM joomla-pg-tutorial-web
and cluster Managed Service for PostgreSQL joomla-pg-tutorial-db-cluster
.
If you reserved a static public IP address specifically for this VM:
- Open the Virtual Private Cloud in your folder.
- Go to the IP addresses tab.
- Find the address you need, click , and select Delete.