[Yandex Cloud documentation](../../index.md) > [Tutorials](../index.md) > Application solutions > Creating a website > WordPress website > Migrating a WordPress website from a third-party hosting provider to Yandex Cloud

# Transferring a WordPress website from a different hosting provider to Yandex Cloud

[WordPress](https://wordpress.com) is an open-source content management system.

With WordPress, you can create news sites, personal or corporate blogs, business websites, online stores, and other services.

It allows you to launch your website with minimal effort using one of the many available templates or your own design. Ready-made plugins help you easily add new blocks or features to a created service.

In Yandex Cloud, you can quickly [create a website on WordPress](wordpress/index.md) or transfer from another hosting provider.

To transfer a WordPress website to Yandex Cloud:
1. [Make a backup of the site](#create-backup)
1. [Get your cloud ready](#before-begin).
1. [Create a virtual machine for WordPress](#create-vm).
1. [Connect to the VM](#connect-vm).
1. [Install and configure additional components](#additional-components).
1. [Import the database](#import-db).
1. [Transfer the site files](#transfer-files).
1. [Configure DNS](#configure-dns).
1. [Create a SSL certificate](#setting-ssl).
1. [Test the website](#check-site).

## Make a backup of the site {#create-backup}

Create a backup of the website and DB files using one of the following methods:
* Using various WordPress plugins, e.g., [BackWPup](https://wordpress.org/plugins/backwpup) or [Updraft Plus](https://wordpress.org/plugins/updraftplus).
* Using built-in tools from the hosting control panel for your website.
* Copying all the files to your hard drive using an FTP client and exporting the DB using [phpMyAdmin](https://www.phpmyadmin.net/).

  This method is longer and will take 5 to 20 minutes because you need to copy numerous small files that make up your site.

## Get your cloud ready {#before-begin}

Sign up for Yandex Cloud and create a [billing account](../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../billing/quickstart/index.md) and [link](../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../resource-manager/concepts/resources-hierarchy.md).

Make sure the selected [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) has a [cloud network](../../vpc/concepts/network.md#network) with a [subnet](../../vpc/concepts/network.md#subnet) in at least one [availability zone](../../overview/concepts/geo-scope.md). To do this, select **Virtual Private Cloud** on the folder dashboard. If the list contains a network, click its name to see the list of subnets. If the subnets or network you need are not listed, [create them](../../vpc/quickstart.md).

### Required paid resources {#paid-resources}

The cost of maintaining a WordPress website includes:
* Fee for a continuously running [VM](../../compute/concepts/vm.md) (see [Yandex Compute Cloud pricing](../../compute/pricing.md)).
* Fee for a static or dynamic [public IP address](../../vpc/concepts/address.md#public-addresses) (see [Yandex Virtual Private Cloud pricing](../../vpc/pricing.md)).
* Fee for public DNS queries and [zones](../../dns/concepts/dns-zone.md) (see [Yandex Cloud DNS pricing](../../dns/pricing.md)).

## Create a VM for WordPress {#create-vm}

To create a VM:
1. On the [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) dashboard in the [management console](https://console.yandex.cloud), click ![plus](../../_assets/console-icons/plus.svg) **Create resource** and select `Virtual machine instance`.
1. Under **Boot disk image**, in the **Product search** field, enter `LAMP` and select the [LAMP](https://yandex.cloud/en/marketplace/products/yc/lamp) public image containing the required components: Linux, Apache web server, MySQL® DBMS, and PHP interpreter.
1. Under **Location**, select an [availability zone](../../overview/concepts/geo-scope.md) where your VM will reside. If you are not sure which availability zone you need, leave the default selection.
1. Under **Disks and file storages**, select the [disk type](../../compute/concepts/disk.md#disks_types) and set the required size.
1. Under **Computing resources**, navigate to the `Custom` tab and specify the [platform](../../compute/concepts/vm-platforms.md), number of vCPUs, and amount of RAM:

    * **Platform**: `Intel Ice Lake`
    * **vCPU**: `2`
    * **Guaranteed vCPU performance**: `20%`
    * **RAM**: `1 GB`

1. Under **Network settings**:

   * In the **Subnet** field, select the network and subnet to which you want to connect your VM. If the [network](../../vpc/concepts/network.md#network) or [subnet](../../vpc/concepts/network.md#subnet) you need does not exist yet, [create it](../../vpc/operations/subnet-create.md).
   * In the **Public IP address** field, select a static IP address from the list, or leave `Auto` to assign your VM a random external IP address from the Yandex Cloud pool.

1. Under **Access**, select **SSH key** and specify the VM access credentials:

   * In the **Login** field, enter a username. Do not use `root` or other reserved usernames. For operations requiring root privileges, use the `sudo` command.
   * In the **SSH key** field, select the SSH key saved in your [organization user](../../organization/concepts/membership.md) profile.
     
     If there are no SSH keys in your profile or you want to add a new key:
     
     1. Click **Add key**.
     1. Enter a name for the SSH key.
     1. Select one of the following:
     
         * `Enter manually`: Paste the contents of the public SSH key. You need to [create](../../compute/operations/vm-connect/ssh.md#creating-ssh-keys) an SSH key pair on your own.
         * `Load from file`: Upload the public part of the SSH key. You need to create an SSH key pair on your own.
         * `Generate key`: Automatically create an SSH key pair.
         
           When adding a new SSH key, an archive containing the key pair will be created and downloaded. In Linux or macOS-based operating systems, unpack the archive to the `/home/<user_name>/.ssh` directory. In Windows, unpack the archive to the `C:\Users\<user_name>/.ssh` directory. You do not need additionally enter the public key in the management console.
     
     1. Click **Add**.
     
     The system will add the SSH key to your organization user profile. If the organization has [disabled](../../organization/operations/os-login-access.md) the ability for users to add SSH keys to their profiles, the added public SSH key will only be saved in the user profile inside the newly created resource.

1. Under **General information**, specify the VM name: `wordpress-vm`.

    {% note alert %}

    Once created, the VM gets an IP address and a [host name (FQDN)](../../compute/concepts/network.md#hostname) for connections. If you selected `No address` in the **Public IP address** field, you will not be able to access the VM from the internet.

    {% endnote %}

1. Under **Advanced**, select a [service account](../../iam/concepts/users/service-accounts.md) or create a new one.
1. Click **Create VM**.

   It may take a few minutes to create your VM. When the VM [status](../../compute/concepts/vm-statuses.md) changes to `RUNNING`, you can [upload the website files](#upload-files).

## Connect to the VM {#connect-vm}

You can connect to a VM over SSH once it gets the `RUNNING` status. To do this, you can use the `ssh` utility in Linux/macOS/Windows 10 and [PuTTY](https://www.chiark.greenend.org.uk/~sgtatham/putty/) in Windows 7/8.

To connect to the VM, specify its public IP address.

To copy the VM's public IP address:
1. Open the folder page in the [management console](https://console.yandex.cloud).
1. Navigate to **Compute Cloud**.
1. In the left-hand panel, select ![image](../../_assets/console-icons/server.svg) **Virtual machines**.
1. Find the created VM and click its name.
1. Under **Network**, copy the IP address from the **Public IPv4 address** field.

[Connect to the VM](../../compute/operations/vm-connect/ssh.md).

## Install and configure additional components {#additional-components}

Before you transfer your files, do the following:
* Install the `nano` text editor. You will need it to edit some of the configuration files.
* Install and configure `phpMyAdmin` to manage the website DB.

### Install the nano editor {#install-nano}

{% list tabs group=operating_system %}

- Ubuntu {#ubuntu}

  Run this command:

  ```bash
  sudo apt install nano
  ```

  Wait for the editor to be installed.

{% endlist %}

### Install phpMyAdmin {#install-phpmyadmin}

{% list tabs group=operating_system %}

- Ubuntu {#ubuntu}

  1. Run the following commands:

     ```bash
	 sudo apt-get update
	 sudo apt-get install phpmyadmin php-mbstring php-gettext
	 ```

  1. During the installation process, select the server to install `phpMyAdmin` on. Select `Apache2` and press the **space** bar on the keyboard: the `*` icon will appear next to `Apache2`. Press **Enter**.
  1. Set up `phpMyAdmin` access to the DB. When prompted `Configure database for phpmyadmin with dbconfig-common?`, choose `<yes>`. You can skip entering the password, the system will automatically generate it. To copy the generated password, run the command:

     ```bash
	 sudo cat /root/default_passwords.txt
	 ```

	 The text of the file must contain the following data:

	 ```text
	 MYSQL_ROOT_PASS=KjZKrQV7efFGk
	 ```

	 Copy and save the password: `MYSQL_ROOT_PASS`. You will need it later.
  1. Enable the `mbstring` extension for PHP:

     ```bash
	 sudo phpenmod mbstring
	 ```

  1. To accept all changes, restart Apache:

     ```bash
	 sudo systemctl restart apache2
	 ```

  1. Open `phpMyAdmin` in the browser. In the address bar, enter `http://<VM_public_IP_address>/phpmyadmin`.

	 To log in to `phpMyAdmin`, use the following data:

	 ```text
	 User: root
	 Password: system-generated (MYSQL_ROOT_PASS from the default_passwords.txt file)
	 ```

{% endlist %}

### Configure phpMyAdmin {#setting-phpmyadmin}

Set up an additional password to log in to the `phpMyAdmin` panel. Edit the `phpmyadmin.conf` file to enable the use of access settings in `.htaccess`.

{% list tabs group=operating_system %}

- Ubuntu {#ubuntu}

  1. Run this command:

     ```bash
	 sudo nano /etc/apache2/conf-available/phpmyadmin.conf
	 ```

  1. Add the `AllowOverride All` line to the `phpmyadmin.conf` file:

     ```text
	 <Directory /usr/share/phpmyadmin>
	 Options SymLinksIfOwnerMatch
	 DirectoryIndex index.php
	 AllowOverride All
	 ```

  1. Save the changes to the `phpmyadmin.conf` file. To do this, press **Ctrl** + **O** and **Enter**. To exit the file, press **Ctrl** + **X**.
  1. Restart Apache:

     ```bash
	 sudo systemctl restart apache2
	 ```

  1. Create `.htaccess`:

     ```bash
	 sudo nano /usr/share/phpmyadmin/.htaccess
	 ```

  1. Copy these lines to `.htaccess`:

     ```text
	 AuthType Basic
	 AuthName "Restricted Files"
	 AuthUserFile /etc/phpmyadmin/.htpasswd
	 Require valid-user
	 ```

  1. Save the changes to the file.
  1. Create `.htpasswd`:

     ```bash
	 sudo htpasswd -c /etc/phpmyadmin/.htpasswd <username>
	 ```

	 Set the desired password and repeat it.
  1. Restart Apache:

     ```bash
	 sudo systemctl restart apache2
	 ```

  Now, when logging in to phpMyAdmin, you will need to enter an additional username and password specified in the `.htpasswd` file.

{% endlist %}

## Import the DB {#import-db}

{% list tabs group=operating_system %}

- Ubuntu {#ubuntu}

  1. Open your website’s WordPress configuration file. To do this, unpack the archive and open the `wp-config.php` file in the root folder. Find the values of the `DB_USER`, `DB_NAME`, and `DB_PASSWORD` parameters:

     ```bash
	 define('DB_USER', 'UsernameTEST');
	 define('DB_NAME', 'database_wordpress');
	 define('DB_PASSWORD', 'MySecretPassword');
	 ```

  1. Log in to phpMyAdmin — enter the following in the browser address bar:

     ```http request
     http://<VM_public_IP_address>/phpmyadmin`
     ```

  1. Go to the **User accounts** section and add a user account with the following parameters:
     * **Username**: Insert a value for `DB_USER` from `wp-config.php`.
     * **Host name**: Leave the default value, `%`.
     * **Password**: Insert a value for `DB_PASSWORD` from `wp-config.php`.
     * **Global privileges**: Enable the **Mark all** option.

     Leave the other default parameters when creating a user. At the bottom of the screen, click **Forward**.
  1. Go to the **Databases** section. Fill in the **Database name** field with a value for `DB_NAME` from `wp-config.php`. Select the `utf8_general_ci` encoding. Click **Create**.
  1. Import the DB from a backup:
     * In the left column, select the DB you created.
     * Click **Import** and select the saved DB backup. If the DB backup exceeds the default limit of 2 MB, edit the `php.ini` configuration file where this limit is set.
     1. Run this command:

	    ```bash
	    sudo nano /etc/php/X.X/apache2/php.ini
	    ```

	    `X.X`: PHP version. Possible values: `5.6`, `7.0`, `7.1`, `7.2`, `7.3`, `7.4`, `8.0`, `8.1`.
	 1. Edit the parameters:
	    * `upload_max_filesize`: Maximum size of the uploaded file.
	    * `post_max_size`: Maximum message size for the `POST` method.

	    ```bash
	    upload_max_filesize = 80M
	    post_max_size = 80M
	    ```

	 1. Save the changes: Press **Ctrl**+**O** and **Enter**. To exit the file, press **Ctrl**+**X**.
	 1. Restart Apache:

	    ```bash
	    sudo systemctl restart apache2
	    ```

	 1. Repeat the DB import operation.

{% endlist %}

### Disable phpMyAdmin {#disable-phpmyadmin}

All the main DB migration activities are performed. Disable the utility to avoid outside attacks on `phpMyAdmin`:

{% list tabs group=operating_system %}

- Ubuntu {#ubuntu}

  ```bash
  sudo a2disconf phpmyadmin.conf && sudo /etc/init.d/apache2 restart
  ```

{% endlist %}

You can use the terminal to work with the DB.

## Transfer the site files {#transfer-files}

To transfer backup files to a VM, use the [FileZilla](https://filezilla-project.org/) FTP client:
1. Open FileZilla.
1. Go to **File** → **Site manager** and add a new website.
1. Select SFTP and enter the VM's public IP address. Under **Logon type**, select **File with the key**.
1. Specify the user created when configuring the VM and select the key file (located in the `/Users/<username>/.ssh/` folder).

   The FTP client does not see the hidden folder by default. Press **Cmd** + **Shift** + **G** and select the `id_ed25519` file without the `pub` extension. A message is displayed that the file is not supported. The FTP client will offer to convert it to the desired format. Click **Yes**. Save the converted file in a convenient location.
1. Click **Connect** and enter the passphrase that you created at the beginning of the work. As a result, you will connect to the VM.
1. Find the `/var/www/html` folder on the VM and paste the backup file there. You do not need to copy index.html.

   {% list tabs group=operating_system %}

   - Ubuntu {#ubuntu}

     By default, 755 rights are set for this folder. To copy the site archive file from your hard drive to the `html` folder, change the permissions for the folder:

     ```bash
     sudo chmod 777 /var/www/html
     ```

     Unpack the backup:

     ```bash
     cd /var/www/html
     tar -xvf FILENAME.tar.gz
     ```

     Instead of `FILENAME`, specify the name of the site archive file.

     {% note alert %}

     You should unpack all the files to the `html` root directory, not to the `/var/www/html/wordpress` subdirectory.

     {% endnote %}

	 Delete the backup file so that it does not take up space:

     ```bash
     rm FILENAME.tar.gz
     ```

     Return the rights for the folders:
     * `html` and subfolders: `755`.
     * For all files inside `html`: `644`.
     * For `wp-config.php` separately, access level: `600`.

     ```bash
     cd var/www/
     sudo find ./ -type d -exec chmod 0755 {} \;
     sudo find ./ -type f -exec chmod 0644 {} \;
     sudo chmod 600 wp-config.php
     ```

     `f` parameter: Searches for all files within folders. `d` parameter: Searches for all folders within `html`.

   {% endlist %}

## Configure DNS {#configure-dns}

Use Cloud DNS to manage the domain.

The tutorial below describes configuring DNS for the `example.com` domain name.

### Add a DNS zone {#create-dns-zone}

{% list tabs group=instructions %}

- Management console {#console}

   To add a [public DNS zone](../../dns/concepts/dns-zone.md#public-zones):
   1. Navigate to **Cloud DNS** in the [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) where you need to create a [DNS zone](../../dns/concepts/dns-zone.md).
   1. Click **Create zone**.
   1. Specify the DNS zone settings:
      * **Zone**: `example.com.`. Or specify your registered domain.
      * **Type**: `Public`.
      * **Name**: `example-zone-1`.
   1. Click **Create**.

{% endlist %}

### Add resource records {#create-dns-records}

Create DNS records in the public zone:

{% list tabs group=instructions %}

- Management console {#console}

   1. Under **Network** on the [VM](../../compute/concepts/vm.md) page in the [management console](https://console.yandex.cloud), find the VM's [public IP address](../../vpc/concepts/address.md#public-addresses).
   1. Create an [A](../../dns/concepts/resource-record.md#a) record:
      * Open the **Cloud DNS** section of the folder containing the `example.com` DNS zone.
      * Select the `example.com` DNS zone from the list.
      * Click **Create record**.
      * Specify the record settings:
         * **Name**: Leave empty.
         * **Type**: Leave set to `A`.
         * **Data**: Enter your VM's public address.
         * **TTL (in seconds)** (record time to live): Keep the default value.
      * Click **Create**.
   1. Create a [CNAME](../../dns/concepts/resource-record.md#cname) record:
      * Select the `example.com` DNS zone from the list.
      * Click **Create record**.
      * Specify the record settings:
         * **Name**: `www`.
         * **Type**: Select `CNAME`.
         * **Data**: Enter `example.com`.
         * **TTL (in seconds)** (record time to live): Keep the default value.
      * Click **Create**.

{% endlist %}

### Delegate the domain name {#delegate-domain}

Delegation is the transfer of authority from the registrar's servers to yours. For a domain, [NS](../../dns/concepts/resource-record.md#ns) resource records (`ns1.yandexcloud.net` and `ns2.yandexcloud.net`) are created.

To delegate a domain, specify its DNS servers in the registrar's account.

Delegation does not take effect immediately. Internet provider servers normally update records within 24 hours (86,400 seconds). This depends on the TTL value which specifies how long domain records are cached.

You can check domain delegation using [Whois](https://www.reg.com/whois/check_site) or the `dig` utility:

```bash
dig +short NS example.com
```

Result:

```text
ns2.yandexcloud.net.
ns1.yandexcloud.net.
```

### Test the website {#test-site}

To test the site, enter its IP address or domain name in your browser:
* `http://<VM_public_IP_address>`.
* `http://www.example.com`.

## Install the SSL certificate using Let's Encrypt® {#setting-ssl}

Use [Let’s Encrypt](https://letsencrypt.org/) to install the [certificate](../../certificate-manager/concepts/managed-certificate.md). Let's Encrypt is a certificate authority that issues free [SSL certificates](https://wikipedia.org/wiki/SSL).

### Install the Let's Encrypt client {#install-client}

{% list tabs group=operating_system %}

- Ubuntu {#ubuntu}

  1. Enter the following command in the terminal:

     ```bash
	 sudo apt-get update && sudo apt-get install software-properties-common
	 ```

  1. Add the `universe` and `certbot` repositories:

     ```bash
     sudo add-apt-repository universe && sudo add-apt-repository ppa:certbot/certbot
     ```

     Press **Enter**.
  1. Install the Let's Encrypt client:

     ```bash
     sudo apt-get update && sudo apt-get install certbot python-certbot-apache
     ```

  1. Press **Y** and **Enter**.

{% endlist %}

### Get an SSL certificate {#get-ssl}

{% list tabs group=operating_system %}

- Ubuntu {#ubuntu}

  1. Enter this command:

     ```bash
     sudo certbot --apache
     ```

  1. In the interface, enter the name of your domain: `example.com` or `www.example.com`.
  1. Indicate whether to redirect all pages from `http` to `https` when opening your website. Select `2` to redirect to https.
  1. Test your website: paste `https://www.ssllabs.com/ssltest/analyze.html?d=example.com` to your browser's address bar.

{% endlist %}

### Perform auto-update {#self-update}

The certificate is issued for 90 days. You need to update it regularly. Configure the update schedule using `cron`:

{% list tabs group=operating_system %}

- Ubuntu {#ubuntu}

  1. Enter the following command in the terminal:

     ```bash
	 sudo crontab -e
	 ```

  1. In the dialog, select the first item from the list.
  1. Add a line of code to the very end of the file:

     ```bash
	 30 2 * * 1 /usr/bin/certbot renew >> /var/log/le-renew.log
	 ```

     As a result, an SSL certificate is scheduled to be updated every Monday at 2:30 am. The result will be recorded in a log file.

{% endlist %}

## Test the website {#check-site}

WordPress sites sometimes have a problem opening internal links when switching from one hosting to another. Check whether the `.htaccess` file exists in your website's root folder `var/www/html/.htaccess`.

If there is no file, create it.

{% list tabs group=operating_system %}

- Ubuntu {#ubuntu}

  1. Enter the following command in the terminal:

     ```bash
	 sudo nano /var/www/html/.htaccess
	 ```

  1. Add program code:

     ```html
	 <IfModule mod_rewrite.c>
	   RewriteEngine On
	   RewriteBase /
	   RewriteRule ^index\.php$ - [L]
	   RewriteCond %{REQUEST_FILENAME} !-f
	   RewriteCond %{REQUEST_FILENAME} !-d
	   RewriteRule . /index.php [L]
	 </IfModule>
	 ```

  1. Save the changes: **Ctrl**+**O** and **Enter**. To exit, press **Ctrl**+**X**.

{% endlist %}

Test the website. If the links do not open, it means that support for the `.htaccess` file is disabled in `Apache`.

To enable `.htaccess` support:

{% list tabs group=operating_system %}

- Ubuntu {#ubuntu}

  1. Enter this command:

     ```bash
	 sudo nano /etc/apache2/sites-available/000-default.conf
	 ```

  1. Add program code:

     ```text
	 <Directory /var/www/html>
	   AllowOverride All
	   Order allow,deny
	   allow from all
	 </Directory>
	 ```

  1. As a result:

     ```html
	 <VirtualHost *:80 [::]:80>
	   ServerAdmin webmaster@localhost
	   DocumentRoot /var/www/html
	   <Directory /var/www/html>
	     AllowOverride All
		 Order allow,deny
		 allow from all
	   </Directory>
	   ErrorLog ${APACHE_LOG_DIR}/error.log
	   CustomLog ${APACHE_LOG_DIR}/access.log combined
	 </VirtualHost>
	 ```

  1. Restart Apache:

     ```bash
	 sudo systemctl restart apache2
	 ```

{% endlist %}