Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Use cases
  • Web service
    • All use cases
    • Static website in Object Storage
    • Website on LAMP or LEMP stack
    • Fault-tolerant website with load balancing from Yandex Network Load Balancer
    • Fault-tolerant website using DNS load balancing
    • Joomla-based website with PostgreSQL
    • WordPress website
    • WordPress website on a MySQL database
    • 1C-Bitrix website
  • Online stores
    • All use cases
    • 1C-Bitrix online store
    • Opencart online store
  • Data archive
    • All use cases
    • Single-node file server
    • Configuring an SFTP server on Centos 7
    • Backup to Object Storage via Acronis Backup
    • Backup to Object Storage via CloudBerry Desktop Backup
    • Backup to Object Storage via Duplicati
    • Backup to Object Storage via Bacula
    • Digitizing archives in Yandex Vision
  • Test environment
    • All use cases
    • Testing applications with GitLab
    • Creating test VMs using GitLab CI
    • High-performance computing on preemptible VMs
  • Infrastructure management
    • All use cases
    • Getting started with Terraform
    • Uploading Terraform states to Object Storage
    • Getting started with Packer
    • VM images building automation using Jenkins
    • Continuous deployment of containerized applications using GitLab
    • Creating a cluster of 1C:Enterprise Linux servers with a Managed Service for PostgreSQL cluster
    • Creating a cluster of 1C:Enterprise Windows servers with MS SQL Server
    • Migrating to Yandex.Cloud using Hystax Acura
    • Emergency recovery in Yandex.Cloud using Hystax Acura
    • Configuring a fault-tolerant architecture in Yandex.Cloud
  • Windows in Yandex.Cloud
    • All use cases
    • Deploying Active Directory
    • Deploying Microsoft Exchange
    • Deploying Remote Desktop Services
    • Deploying an Always On availability group
    • Deploying an Always On availability group with an internal network load balancer
  • Network routing
    • All use cases
    • Routing through a NAT instance
    • Creating a VPN tunnel
    • Installing a Cisco CSR1000v virtual router
    • Installing a Mikrotik CHR virtual router
    • Creating a VPN connection using OpenVPN
  • Data visualization and analytics
    • All use cases
    • Visualizing data from a CSV file
    • Visualizing data from a ClickHouse database
    • Visualizing data from Yandex.Metrica
    • Visualizing data from Yandex.Metrica Logs API
    • Publishing a chart with a map from a CSV file to DataLens Public
    • Visualizing data from AppMetrica
    • Visualizing geodata from a CSV file
  • Internet of things
    • Use cases for the internet of things
    • Status monitoring of geographically distributed devices
    • Monitoring sensor readings and event notifications
  1. Web service
  2. WordPress website on a MySQL database

WordPress website on a MySQL database cluster

  • Before you start
    • Required paid resources
  • Create a virtual machine for WordPress
  • Create a MySQL database cluster
  • Configure Nginx web server
  • Install WordPress and additional components
  • Configure WordPress
  • Check that the website is running
  • Configure DNS (if you have a domain name)
  • How to delete created resources

The following instructions explain how to deploy a website in WordPress CMS on a database cluster running MySQL in the Yandex.Cloud infrastructure.

To set up a WordPress website based on a MySQL cluster:

  1. Before you start.
  2. Create a VM for WordPress.
  3. Create a MySQL database cluster.
  4. Configure Nginx web server.
  5. Install WordPress and additional components.
  6. Set up WordPress.
  7. Check that the website is running.
  8. Configure DNS.

If you no longer need the website, delete all its resources.

Before you start

  1. Go to the management console. Then log in to Yandex.Cloud or sign up if don't already have an account.
  2. On the billing page, make sure you linked a billing account, and it has the ACTIVE or TRIAL_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.

Required paid resources

The cost for supporting your website in WordPress with a MySQL cluster includes:

  • A fee for a continuously running VM (see Yandex Compute Cloud pricing).
  • A fee for the MySQL database cluster (see pricing Yandex Managed Service for MySQL).
  • A fee for using a dynamic or static external IP address (see Yandex Virtual Private Cloud pricing).

Create a virtual machine for WordPress

To create a VM:

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

  2. In the Name field, enter a name for the VM: wp-mysql-tutorial-web.

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

  4. Under Images from Cloud Marketplace, click Select. Select a public image of Debian 10, Ubuntu 18.04, or CentOS 7.

  5. Under Computing resources:

    • Choose a platform.
    • Specify the number of vCPUs and amount of RAM:
      • vCPU: 2.
      • Guaranteed vCPU share: 5%.
      • RAM: 1 GB.
  6. In the Network settings section, select the network and subnet to connect the VM to. If you don't have a network or subnet, create them right on the VM creation page.

  7. In the Public address field, leave the Auto value to assign a random external IP address from the Yandex.Cloud pool, or select a static address from the list if you reserved one in advance.

  8. 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 the SSH connection yourself. Learn how to connect to VMs via SSH.

    Alert

    The IP address and host name (FQDN) to connect to the VM are assigned on VM creation. If you selected No address in the Public address field, you won't be able to access the VM from the internet.

  9. Click Create VM.

Creating the VM may take several minutes. When the VM's status changes to RUNNING, you can proceed to the next step.

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

Create a MySQL database cluster

  1. On the folder page in the management console, click Create resource and select MySQL Cluster.

  2. In the Name field, enter the cluster name: wp-mysql-tutorial-db-cluster.

  3. Under Host class, select s2.small.

  4. Under Storage size, enter 10 GB.

  5. Under Database, enter:

    • In the Name field, enter: wp-mysql-tutorial-db.
    • In the Username field, enter wordpress.
    • In the Password field, enter the password you will use to access the DB.
    • In the Network list, select the network your VM will connect to.
  6. Under Hosts, add two more hosts in the other availability zones. When creating hosts, do not enable Public access to them.

  7. Under DBMS settings, click Settings.

    In the Default authentication plugin field, select mysql_native_password and click Save.

  8. Click Create cluster.

Creating the DB cluster may take several minutes.

Configure Nginx web server

After the wp-mysql-tutorial-web VM changes its status to RUNNING:

  1. You can learn the IP address of the VM under Network on the VM page in the management console.

  2. 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.

  3. Install Nginx, PHP-FPM process manager, and additional packages:

    Debian/Ubuntu
    CentOS
    $ sudo apt-get update -qq
    $ sudo apt-get install -y nginx-full php-fpm php-mysql
    $ sudo systemctl enable nginx
    
    $ sudo yum -y install epel-release
    $ sudo yum -y install nginx
    $ sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
    $ sudo yum -y --enablerepo=remi-php72 install php php-mysql php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    $ sudo yum -y --enablerepo=remi-php72 install php-fpm
    $ sudo systemctl enable nginx
    $ sudo systemctl enable php-fpm
    
  4. Use the Nginx configuration files to configure the web server:

    Debian
    Ubuntu
    CentOS
    1. You can edit the file in the nano editor:

      $ sudo nano /etc/nginx/sites-available/wordpress
      
    2. Make the file look like:

      server {
          listen 80 default_server;
      
          root /var/www/wordpress;
          index index.php;
      
          server_name <DNS server name>
      
          location / {
              try_files $uri $uri/ =404;
          }
      
          error_page 404 /404.html;
          error_page 500 502 503 504 /50x.html;
          location = /50x.html {
              root /usr/share/nginx/html;
          }
      
          location ~ \.php$ {
              try_files $uri =404;
              fastcgi_split_path_info ^(.+\.php)(/.+)$;
              fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include fastcgi_params;
          }
      }
      
    3. Enable launch for your site:

      $ sudo rm /etc/nginx/sites-enabled/default
      $ sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
      
    1. You can edit the file in the nano editor:

      $ sudo nano /etc/nginx/sites-available/wordpress
      
    2. Make the file look like:

      server {
          listen 80 default_server;
      
          root /var/www/wordpress;
          index index.php;
      
          server_name <DNS server name>
      
          location / {
              try_files $uri $uri/ =404;
          }
      
          error_page 404 /404.html;
          error_page 500 502 503 504 /50x.html;
          location = /50x.html {
              root /usr/share/nginx/html;
          }
      
          location ~ \.php$ {
              try_files $uri =404;
              fastcgi_split_path_info ^(.+\.php)(/.+)$;
              fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include fastcgi_params;
          }
      }
      
    3. Enable launch for your site:

      $ sudo rm /etc/nginx/sites-enabled/default
      $ sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
      

    You can edit the files nginx.conf and wordpress.conf in the nano editor:

    1. Open nginx.conf:

      $ sudo nano /etc/nginx/nginx.conf
      
    2. Make the file look like:

      user nginx;
      worker_processes auto;
      error_log /var/log/nginx/error.log;
      pid /run/nginx.pid;
      include /usr/share/nginx/modules/*.conf;
      
      events {
          worker_connections 1024;
      }
      
      http {
          log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                            '$status $body_bytes_sent "$http_referer" '
                            '"$http_user_agent" "$http_x_forwarded_for"';
      
          access_log  /var/log/nginx/access.log  main;
      
          sendfile            on;
          tcp_nopush          on;
          tcp_nodelay         on;
          keepalive_timeout   65;
          types_hash_max_size 2048;
      
          include             /etc/nginx/mime.types;
          default_type        application/octet-stream;
      
          include /etc/nginx/conf.d/*.conf;
      }
      
    3. Open wordpress.conf:

      $ sudo nano /etc/nginx/wordpress.conf
      
    4. Make the file look like:

      server {
          listen 80 default_server;
      
          root /usr/share/nginx/wordpress/;
          index index.php;
      
          server_name <DNS server name>
      
          location / {
              try_files $uri $uri/ =404;
          }
      
          error_page 404 /404.html;
          error_page 500 502 503 504 /50x.html;
          location = /50x.html {
              root /usr/share/nginx/html;
          }
      
          location ~ \.php$ {
              try_files $uri =404;
              fastcgi_split_path_info ^(.+\.php)(/.+)$;
              fastcgi_pass 127.0.0.1:9000;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include fastcgi_params;
          }
      }
      

Install WordPress and additional components

  1. Download and unpack the latest WordPress version:

    Debian/Ubuntu
    CentOS
    $ wget https://wordpress.org/latest.tar.gz
    $ tar -xzf latest.tar.gz
    $ mv wordpress/wp-config-sample.php wordpress/wp-config.php
    $ sudo mv wordpress /var/www/wordpress
    $ sudo chown -R www-data:www-data /var/www/wordpress
    
    $ curl https://wordpress.org/latest.tar.gz --output latest.tar.gz
    $ tar -xzf latest.tar.gz
    $ mv wordpress/wp-config-sample.php wordpress/wp-config.php
    $ sudo mv wordpress /usr/share/nginx/wordpress
    $ sudo chown -R nginx:nginx /usr/share/nginx/wordpress/
    

    Change the SELinux settings:

    $ sudo semanage fcontext -a -t httpd_sys_content_t "/usr/share/nginx/wordpress(/.*)?"
    $ sudo semanage fcontext -a -t httpd_sys_rw_content_t "/usr/share/nginx/wordpress(/.*)?"
    $ sudo restorecon -R /usr/share/nginx/wordpress
    $ sudo setsebool -P httpd_can_network_connect 1
    
  2. Get WordPress security keys:

    $ curl -s https://api.wordpress.org/secret-key/1.1/salt/
    

    Save the command output. You will need the keys in the next step.

  3. Add the security keys to the WordPress configuration file wp-config.php. You can edit files in the nano editor:

    Debian/Ubuntu
    CentOS
    $ sudo nano /var/www/wordpress/wp-config.php
    
    $ sudo nano /usr/share/nginx/wordpress/wp-config.php
    

    Replace the configuration section for the values from the previous step:

    define('AUTH_KEY',         't vz,|............R lZ5]');
    define('SECURE_AUTH_KEY',  '@r&pPD............dK-A%=');
    define('LOGGED_IN_KEY',    '%6TuLl............9>/dNE');
    define('NONCE_KEY',        'DO(u.H............$?ja-e');
    define('AUTH_SALT',        '|G Vo<............Xeb.~y');
    define('SECURE_AUTH_SALT', 'Y5tIYA............7Lxf8J');
    define('LOGGED_IN_SALT',   'gR]>WZ............<>|;YY');
    define('NONCE_SALT',       '=]nQIb............HLT2:9');
    
  4. Go to the cluster connection configuration section wp-mysql-tutorial-db-cluster:

    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    
    define( 'DB_NAME', '<DB_NAME>' );
    /** MySQL database username */
    define( 'DB_USER', '<DB_USER>' );
    
    /** MySQL database password */
    define( 'DB_PASSWORD', '<DB_PASSWORD>' );
    
    /** MySQL hostname */
    define( 'DB_HOST', '<DB_HOST>' );
    

    Replace the placeholders in the file:

    • <DB_NAME> — with the DB name, wp-mysql-tutorial-db.
    • <DB_USER> — with the wordpress username.
    • <DB_PASSWORD> — with the password specified when creating a DB cluster.
    • <DB_HOST> — with the host in the format c-<master ID>.rw.mdb.yandexcloud.net. To find out the master ID, get the list of hosts via the CLI and copy CLUSTER ID with the MASTER role.
  5. Restart Nginx and PHP-FPM:

    Debian
    Ubuntu
    CentOS
    $ sudo systemctl restart nginx.service 
    $ sudo systemctl restart php7.3-fpm.service
    
    $ sudo systemctl restart nginx.service 
    $ sudo systemctl restart php7.2-fpm.service
    
    $ sudo systemctl restart nginx.service 
    $ sudo systemctl restart php-fpm.service
    

Configure WordPress

  1. You can learn the IP address of the VM under Network on the VM page in the management console.

  2. Open the VM by entering its address in your browser.

  3. Select the language and click Continue.

  4. Fill out information to access the website:

    • Enter any name for the website (for example, yc-wordpress).

    • Specify the username to be used to log in to the admin panel (for example, yc-user).

    • Enter the password to be used to log in to the admin panel.

    • Enter your email address.

  5. Click Install WordPress.

  6. If the installation is successful, click Log in.

  7. Log in to the website with the username and password specified in the previous steps. This opens the admin panel, where you can start working with your website.

Check that the website is running

To check that the website is running, visit the public IP address of the VM in the browser.

Configure DNS (if you have a domain name)

To link the website to your domain, configure DNS at your registrar as follows:

  • A record: @ subdomain (use the VM's public IP address as the address).
  • CNAME record: www subdomain (use a domain with a dot at the end as the canonical name, like example.com).

How to delete created resources

To stop paying for your deployed website, just delete the VM wp-mysql-tutorial-web and MySQL cluster wp-mysql-tutorial-db-cluster.

If you reserved a static public IP address specifically for this VM:

  1. Open the Virtual Private Cloud in your folder.
  2. Go to the IP addresses tab.
  3. Find the address you need, click , and select Delete.
In this article:
  • Before you start
  • Required paid resources
  • Create a virtual machine for WordPress
  • Create a MySQL database cluster
  • Configure Nginx web server
  • Install WordPress and additional components
  • Configure WordPress
  • Check that the website is running
  • Configure DNS (if you have a domain name)
  • How to delete created resources
Language
Careers
Privacy policy
Terms of use
© 2021 Yandex.Cloud LLC