Transferring a WordPress website from a different hosting provider to Yandex Cloud
WordPress
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 or transfer from another hosting provider.
To transfer a WordPress CMS website to Yandex Cloud:
- Make a backup of the site.
- Prepare your cloud.
- Create a virtual machine for WordPress.
- Connect to the VM.
- Install and configure additional components.
- Import the database.
- Transfer the site files.
- Configure the DNS.
- Create a SSL certificate.
- Check that the website is running.
Make a backup of the site
Make a backup of the site and database files using one of the following methods:
- Using various plugins for WordPress (for example BackWPup
or Updraft Plus ). - 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 database using the phpMyAdmin
panel.
This method is longer and will take 5 to 20 minutes because you need to copy numerous small files that make up your site.
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 Yandex Cloud 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 the selected folder has a cloud network with a subnet in at least one availability zone. 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 website in WordPress includes:
- Fee for continuously running VM (see Yandex Compute Cloud pricing).
- A fee for using a dynamic or public IP address (see Yandex Virtual Private Cloud pricing).
- A fee for public DNS queries and zones (see Yandex Cloud DNS pricing).
Create a virtual machine for WordPress
To create a VM:
-
Open the folder page in the management console
. -
In the upper-right corner, click Create resource and select Virtual machine.
-
In the Name field, enter the VM name
wordpress-vm
.- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
-
Select an availability zone to place the VM in. If you do not know which availability zone you need, leave the default one.
-
Under Image/boot disk selection, go to the Cloud Marketplace tab and select LAMP, an image that includes the appropriate set of components: the Linux OS, Apache web server, MySQL DBMS, and PHP interpreter.
-
Under Disks, select the disk type and set the size.
-
Under Computing resources:
- Choose a VM platform.
- Specify the required number of vCPUs and the amount of RAM.
For a regular WordPress site, the minimum configuration is enough:
- Platform: Intel Ice Lake.
- Guaranteed vCPU share: 20%.
- vCPU: 2.
- RAM: 1 GB.
-
Under Network settings, select the network and subnet to connect the VM to. If you do not have a network or subnet, create them on the VM creation page.
-
Under Public address, keep Auto to assign your VM a random external IP address from the Yandex Cloud pool, or select a static address from the list if you reserved one in advance.
-
Enter the VM access information:
- Select a service account or create a new one.
- 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, see Connecting to a Linux VM via SSH.
Alert
Once created, the VM will be assigned an IP address and a host name (FQDN) for connections. If you selected No address in the Public address field, you won't be able to access the VM from the internet.
-
Click Create VM.
It may take a few minutes to create the VM. When the VM status changes to
RUNNING
, you can upload the website files.
Connect to the VM
You can connect to a VM using the SSH protocol when it is running (the VM's status is RUNNING
). To do this, you can use the ssh
utility in Linux/macOS/Windows 10 and PuTTY
To connect to a VM, you must specify its public address.
To copy a VM's public address:
-
Open the folder page in the management console
. -
Select Compute Cloud.
-
In the menu on the left, select Virtual machines.
-
Locate the created VM and click on its name.
-
Under Network, copy the address from the Public IPv4 field.
Run the connection to a virtual machine.
Install and configure additional components
Before you transfer your files, do the following:
- Install the text editor
nano
. You need it to edit some of the configuration files. - Install and configure
phpMyAdmin
to manage the site database.
Install the nano editor
Run this command:
sudo apt install nano
Wait for the editor to be installed.
Install phpMyAdmin
-
Run the following commands:
sudo apt-get update sudo apt-get install phpmyadmin php-mbstring php-gettext
-
During the installation process, select the server to install
phpMyAdmin
on. SelectApache2
and press the space bar on the keyboard: the*
symbol appears next toApache2
. Click Enter. -
Configure access of
phpMyAdmin
to the database. To do this, answer the questionConfigure database for phpmyadmin with dbconfig-common?
with<yes>
. You can skip entering the password, the system will automatically generate it. To copy the generated password, run the command:sudo cat /root/default_passwords.txt
The text of the file must contain the following data:
MYSQL_PASS=DOEC21WECnhF1 MYSQL_ROOT_PASS=KjZKrQV7efFGk MYSQL_USER=wordpress MYSQL_DB=wordpress Apache Web Auth: login: admin password: ***************
Copy and save the contents of the
default_passwords.txt
file to my computer. -
Enable the
mbstring
extension for PHP:sudo phpenmod mbstring
-
To accept all changes, restart Apache:
sudo systemctl restart apache2
-
Open
phpMyAdmin
in the browser. In the address bar, enterhttp://<public address of the VM>/phpmyadmin
.To log in to
phpMyAdmin
use the following data:User: root Password: generated by the system (from the default_passwords.txt file)
Configure phpMyAdmin
Set up an additional password to log in to the phpMyAdmin
panel. To enable the use of access settings in .htaccess
, edit the phpmyadmin.conf
file.
-
Run this command:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
-
Add the
AllowOverride All
line to thephpmyadmin.conf
file:<Directory /usr/share/phpmyadmin> Options SymLinksIfOwnerMatch DirectoryIndex index.php AllowOverride All
-
Save the changes in the
phpmyadmin.conf
file. To do this, click Ctrl + O and Enter. To exit the file, press Ctrl + X. -
Restart Apache:
sudo systemctl restart apache2
-
Create
.htaccess
:sudo nano /usr/share/phpmyadmin/.htaccess
-
Copy the lines to
.htaccess
:AuthType Basic AuthName "Restricted Files" AuthUserFile /etc/phpmyadmin/.htpasswd Require valid-user
-
Save the changes to the file.
-
Create
.htpasswd
:sudo htpasswd -c /etc/phpmyadmin/.htpasswd <username>
Set the desired password and repeat it.
-
Restart Apache:
sudo systemctl restart apache2
Now, when you log in to phpMyAdmin, you will need to enter an additional username and password specified in the .htpasswd
file.
Import the database
-
Open the WordPress configuration file of your website. To do this, unpack the archive and open
wp-config.php
in the root folder. Find the values of theDB_USER
,DB_NAME
, andDB_PASSWORD
parameters:define('DB_USER', 'UsernameTEST'); define('DB_NAME', 'database_wordpress'); define('DB_PASSWORD', 'MySecretPassword');
-
Log in to phpMyAdmin: enter the following in the browser address bar:
http://<VM's public address/phpmyadmin`
-
Go to the User accounts section and add a user account with the following parameters:
- Username: Insert a value of
DB_USER
fromwp-config.php
. - Hostname: Leave the default value
%
. - Password: Insert a value for
DB_PASSWORD
fromwp-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.
- Username: Insert a value of
-
Go to the Databases section. Complete the Database name field with a value for
DB_NAME
fromwp-config.php
. Select theutf8_general_ci
encoding. Click Create. -
Import the database from a backup:
- In the left column, select the database you created.
- Click Import and select the saved database backup. If the database backup exceeds the default limit of 2 MB, edit the configuration file
php.ini
where this restriction is set.
-
Run this command:
sudo nano /etc/php/X.X/apache2/php.ini
X.X
: php version. Possible values5.6
,7.0
,7.1
,7.2
,7.3
,7.4
,8.0
, and8.1
. -
Edit the parameters:
upload_max_filesize
: The maximum size of the uploaded file.post_max_size
: The maximum amount ofPOST
method data allowed.
upload_max_filesize = 80M post_max_size = 80M
-
Save the changes: Press Ctrl + O and Enter. To exit the file, press Ctrl + X.
-
Restart Apache:
sudo systemctl restart apache2
-
Repeat the database import operation.
Disable phpMyAdmin
All the main migration activities on the database are performed. In order not to expose phpMyAdmin
to attacks from outside, disable the utility:
sudo a2disconf phpmyadmin.conf && sudo /etc/init.d/apache2 restart
You can use the terminal to work with the database.
Transfer the site files
To transfer backup files to a virtual machine, use the FileZilla
-
Open FileZilla.
-
Go to File → Site manager and add a new website.
-
Select SFTP and enter the public IP address of the virtual machine. Under Logon type, select File with the key.
-
Specify the user created when configuring the VM and select the key file (located in the
/Users/<user_name>/.ssh/
folder).The FTP client doesn't see the hidden folder by default. Press Cmd + Shift + G and select the
id_ed25519
file without thepub
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. -
Click Connect and enter the passphrase that you created at the beginning of the work. You'll be connected to the VM.
-
Find the
/var/www/html
folder on the VM and copy the backup file there. You don't need to copy index.html.UbuntuBy default, this folder requires 755 rights. To copy the archive file of the site from your hard drive to the
html
folder, change the rights to the folder:sudo chmod 777 /var/www/html
Unpack the backup:
cd /var/www/html tar -xvf FILENAME.tar.gz
Instead of
FILENAME
, specify the name of the archive file of the site.Alert
You should unpack all the files to the root directory
html
, not to the subdirectory/var/www/html/wordpress
.Delete the backup file so that it does not take up space:
rm FILENAME.tar.gz
Return the rights to the folders:
html
and subfolders:755
.- For all files inside
html
:644
. - For
wp-config.php
, an individual access level:600
.
cd var/www/ sudo find ./ -type d -exec chmod 0755 {} \; sudo find ./ -type f -exec chmod 0644 {} \; sudo chmod 600 wp-config.php
The
f
parameter: Searches for all files inside folders. Thed
parameter: Searches for all folders insidehtml
.
Configure the DNS
Use Cloud DNS to manage the 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
.
Install the SSL certificate using Let's Encrypt®
To install the certificate, use Let’s Encrypt
Install the Let's Encrypt client
-
Enter the following command in the terminal:
sudo apt-get update && sudo apt-get install software-properties-common
-
Add the
unverse
andcertbot
repositories:sudo add-apt-repository universe && sudo add-apt-repository ppa:certbot/certbot
Click Enter.
-
Install the Let's Encrypt client:
sudo apt-get update && sudo apt-get install certbot python-certbot-apache
-
Click Y and Enter.
Get an SSL certificate
-
Enter the command:
sudo certbot --apache
-
In the interface, enter the name of your domain
example.com
orwww.example.com
. -
Decide if you need to redirect all pages from
http
onhttps
when opening a website. Select2
: Redirect to https. -
Test your site: Enter
https://www.ssllabs.com/ssltest/analyze.html?d=example.com
in the address bar of the browser.
Perform auto-update
The certificate is issued for 90 days. You need to to update it regularly. Configure the update schedule using cron
:
-
Enter the following command in the terminal:
sudo crontab -e
-
In the dialog, select the first item from the list.
-
Add a line of code to the very end of the file:
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.
Check that the website is running
WordPress sites sometimes have a problem opening internal links when switching from one host to another.
In this case, check whether the .htaccess
file exists in your site's root folder: var/www/html/.htaccess
.
If there is no file, create it.
-
Enter the following command in the terminal:
sudo nano /var/www/html/.htaccess
-
Add a code:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
-
Save the changes: Ctrl + O and Enter. To exit, press Ctrl + X.
Check the website. If the links don't open, it means the support of the .htaccess
file was disabled in Apache
.
To enable the support of .htaccess
:
-
Enter the command:
sudo nano /etc/apache2/sites-available/000-default.conf
-
Add a code:
<Directory /var/www/html> AllowOverride All Order allow,deny allow from all </Directory>
-
As a result:
<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>
-
Restart Apache:
sudo systemctl restart apache2