Joomla-based website with PostgreSQL

To set up a static website on Joomla:

Before you start

Before creating a VM and a DB cluster:

  1. Go to the Yandex.Cloud management console and select the folder where you want to perform the operations.
  2. 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, click the Yandex Virtual Private Cloud tile 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.

Creating a VM for Joomla

To create a VM:

  1. On the folder page of the management console, click Create resource and select Virtual machine.

  2. In the Name field, enter the VM name: joomla-pg-tutorial-web.

  3. Select the availability zone to locate the VM in.

  4. Select the Ubuntu or CentOS public image.

  5. In the Computing resources section, select the type of core usage (partial or full) and specify the necessary number of vCPUs and amount of RAM.

    The minimum configuration is enough for functional testing:

    • Guaranteed vCPU share: 5%.
    • vCPU: 1.
    • RAM: 1 GB.
  6. In the Network settings section, select the subnet to connect the VM to when creating it.

  7. 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 SSH connection yourself. To generate keys, use third-party tools, such as ssh-keygen utilities on Linux and macOS or PuTTygen on Windows.
  8. Click Create VM.

Creating the VM may take several minutes.

When a VM is being created, it is assigned an IP address and hostname (FQDN). This data can be used for SSH access.

Creating a PostgreSQL DB cluster

  1. On the folder page, click Create resource and select PostgreSQL cluster.
  2. In the Name field, enter the cluster name: joomla-pg-tutorial-db-cluster.
  3. In the DB class section, select s1.nano.
  4. In the Storage size section, enter 10 GB.
  5. In the Database section:
  6. In the DB name field, enter joomla-pg-tutorial-db.
  7. In the Username field, enter joomla.
  8. In the Password field, enter the password you will use to access the DB.
  9. In the Network list, select the network your VM is connected to.
  10. In the Hosts section, add two more hosts in the other availability zones. When creating hosts, do not enable Public access to them.
  11. Click Create cluster.

Creating the DB cluster may take several minutes.

Installing Joomla and additional components

After the joomla-pg-tutorial-web VM's status changes to RUNNING, do the following:

  1. In the Network section on the VM page of the management console, find the VM's public IP address.

  2. Connect to the VM via SSH. You can use the ssh tool on Linux and macOS and 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.

  3. 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
    
  4. Install additional components:

    $ 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 ~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
    
    $ 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 ~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
    
    $ 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 ~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-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-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
    

Configuring Apache2 web server

  1. Perform the basic configuration of Apache2:

    $ 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/
    
  2. Specify the virtual host settings in the Apache2 configuration file. You can edit the file using the nano utility:

    $ 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>
    
  3. Restart the web server:

    $ sudo service apache2 restart
    
    $ sudo service httpd restart
    
  4. 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
    

Configuring 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:

  1. Get the addresses of the DB cluster hosts in the management console:

    1. Open the folder where the DB cluster was created.
    2. Click the Managed Service for PostgreSQL tile.
    3. Select the cluster joomla-pg-tutorial-db-cluster.
    4. Open the Hosts tab.
    5. In the Address (domain name) column, find the host addresses.
  2. At the Database step, fill in the following fields in the Joomla web installer:

    • DB type: PostgreSQL.

    • DB server name:

      host=<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.

Uploading website files

  1. In the Network section on the VM page of the management console, find the VM's public IP address.

  2. Connect to the VM via SSH. You can use the ssh tool on Linux and macOS and 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.

  3. Grant your user write rights to the directory /var/www/html:

    $ sudo setfacl -m u:<your user's name>:w /var/www/html
    
  4. Upload the website files to the VM via the SCP.

    Use the scp command-line utility:

    $ scp -r <path to the file directory> <your user's name>@<VM's IP address>:/var/www/html
    

    Use the WinSCP program to copy the local file directory to the /var/www/html directory on the VM.

Configuring 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 as an example reg.ru for www.example.com and example.com domain names:

  • A record of the A type 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 via www.example.ru.

To configure an external DNS server, do the following:

  1. In the Network section on the VM page of the management console, find the VM's public IP address.
  2. 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.
  3. Follow the Zone management link in the Domain management section.
  4. Create or edit an A record:
    • IP Address — your VM's public IP address.
    • Subdomain: @ (points to the main domain).
  5. Create a CNAME record with the following field values:
    • Subdomain: www.
    • Canonical name: @ or the example.com. domain with a dot at the end.
  6. Wait 15-20 minutes for DNS record changes to take effect. The waiting time may differ for your DNS service.