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 website to Yandex Cloud:
- Make a backup of the site
- Get your cloud ready.
- Create a virtual machine for WordPress.
- Connect to the VM.
- Install and configure additional components.
- Import the database.
- Transfer the site files.
- Configure DNS.
- Create a SSL certificate.
- Test the website.
Make a backup of the site
Create a backup of the website and DB files using one of the following methods:
-
Using various WordPress plugins, e.g., 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 DB using phpMyAdmin
.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
Sign up for Yandex Cloud and create a billing account:
- Navigate to the management console
and log in to Yandex Cloud or create a new account. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVEorTRIAL_ACTIVEstatus. If you do not have a billing account, create one and link a cloud to it.
If you have an active billing account, you can navigate to the cloud page
Learn more about clouds and folders here.
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 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 maintaining a WordPress website includes:
- Fee for a continuously running VM (see Yandex Compute Cloud pricing).
- Fee for using a dynamic or static public IP address (see Yandex Virtual Private Cloud pricing).
- Fee for public DNS queries and zones (see Yandex Cloud DNS pricing).
Create a VM for WordPress
To create a VM:
-
On the folder dashboard of the management console
, click Create resource and selectVirtual machine instance. -
Under Boot disk image, in the Product search field, enter
LAMPand select the LAMP public image containing the required components: Linux, Apache web server, MySQL® DBMS, and PHP interpreter. -
Under Location, select the availability zone your VM will reside in. If you are not sure which one to choose, leave the default.
-
Under Disks and file storages, select the disk type and set the required size.
-
Under Computing resources, navigate to the
Customtab and specify the platform, number of vCPUs, and RAM size:- Platform:
Intel Ice Lake - vCPU:
2 - Guaranteed vCPU performance:
20% - RAM:
1 GB
- Platform:
-
Under Network settings:
- In the Subnet field, select the network and subnet to connect your VM to. If the required network or subnet is not there, create it.
- Under Public IP address, leave
Autoto assign a random external IP address to your VM from the Yandex Cloud pool. Alternatively, select a static address from the list if you reserved one.
-
Under Access, select SSH key and specify the VM access credentials:
- In the Login field, enter the username. Do not use
rootor other reserved usernames. To perform operations requiring root privileges, use thesudocommand. -
In the SSH key field, select the SSH key saved in your organization user profile.
If there are no SSH keys in your profile or you want to add a new key:
-
Click Add key.
-
Enter a name for the SSH key.
-
Select one of the following:
-
Enter manually: Paste the contents of the public SSH key. You need to create 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>/.sshdirectory. In Windows, unpack the archive to theC:\Users\<user_name>/.sshdirectory. You do not need additionally enter the public key in the management console.
-
-
Click Add.
The system will add the SSH key to your organization user profile. If the organization has disabled 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.
-
- In the Login field, enter the username. Do not use
-
Under General information, specify the VM name:
wordpress-vm.Alert
Once created, the VM gets an IP address and a host name (FQDN) for connections. If you selected
No addressin the Public IP address field, you will not be able to access the VM from the internet. -
Under Advanced, select a service account or create a new one.
-
Click Create VM.
It may take a few minutes to create your VM. When the VM status changes to
RUNNING, you can upload the website files.
Connect to the 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
To connect to the VM, specify its public IP address.
To copy the VM's public IP address:
- Open the folder page in the management console
. - Select Compute Cloud.
- In the left-hand panel, select
Virtual machines. - Find the created VM and click its name.
- Under Network, copy the IP address from the Public IPv4 address field.
Install and configure additional components
Before you transfer your files, do the following:
- Install the
nanotext editor. You will need it to edit some of the configuration files. - Install and configure
phpMyAdminto manage the website DB.
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
phpMyAdminon. SelectApache2and press the space bar on the keyboard: the*icon will appear next toApache2. Press Enter. -
Set up
phpMyAdminaccess to the DB. When promptedConfigure 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:sudo cat /root/default_passwords.txtThe text of the file must contain the following data:
MYSQL_ROOT_PASS=KjZKrQV7efFGkCopy and save the password:
MYSQL_ROOT_PASS. You will need it later. -
Enable the
mbstringextension for PHP:sudo phpenmod mbstring -
To accept all changes, restart Apache:
sudo systemctl restart apache2 -
Open
phpMyAdminin the browser. In the address bar, enterhttp://<VM_public_IP_address>/phpmyadmin.To log in to
phpMyAdmin, use the following data:User: root Password: system-generated (MYSQL_ROOT_PASS from the default_passwords.txt file)
Configure 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.
-
Run this command:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf -
Add the
AllowOverride Allline to thephpmyadmin.conffile:<Directory /usr/share/phpmyadmin> Options SymLinksIfOwnerMatch DirectoryIndex index.php AllowOverride All -
Save the changes to the
phpmyadmin.conffile. To do this, press 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 these 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 logging in to phpMyAdmin, you will need to enter an additional username and password specified in the .htpasswd file.
Import the DB
-
Open your website’s WordPress configuration file. To do this, unpack the archive and open the
wp-config.phpfile in the root folder. Find the values of theDB_USER,DB_NAME, andDB_PASSWORDparameters: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_public_IP_address>/phpmyadmin` -
Go to the User accounts section and add a user account with the following parameters:
- Username: Insert a value for
DB_USERfromwp-config.php. - Host name: Leave the default value,
%. - Password: Insert a value for
DB_PASSWORDfromwp-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 for
-
Go to the Databases section. Fill in the Database name field with a value for
DB_NAMEfromwp-config.php. Select theutf8_general_ciencoding. Click Create. -
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.iniconfiguration file where this limit is set.
-
Run this command:
sudo nano /etc/php/X.X/apache2/php.iniX.X: PHP version. Possible values:5.6,7.0,7.1,7.2,7.3,7.4,8.0,8.1. -
Edit the parameters:
upload_max_filesize: Maximum size of the uploaded file.post_max_size: Maximum message size for thePOSTmethod.
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 DB import operation.
Disable phpMyAdmin
All the main DB migration activities are performed. Disable the utility to avoid outside attacks on phpMyAdmin:
sudo a2disconf phpmyadmin.conf && sudo /etc/init.d/apache2 restart
You can use the terminal to work with the DB.
Transfer the site files
To transfer backup files to a VM, use the FileZilla
-
Open FileZilla.
-
Go to File → Site manager and add a new website.
-
Select SFTP and enter the VM's public IP address. 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/<username>/.ssh/folder).The FTP client does not see the hidden folder by default. Press Cmd + Shift + G and select the
id_ed25519file without thepubextension. 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. As a result, you will connect to the VM.
-
Find the
/var/www/htmlfolder on the VM and paste the backup file there. You do not need to copy index.html.UbuntuBy default, 755 rights are set for this folder. To copy the site archive file from your hard drive to the
htmlfolder, change the permissions for the folder:sudo chmod 777 /var/www/htmlUnpack the backup:
cd /var/www/html tar -xvf FILENAME.tar.gzInstead of
FILENAME, specify the name of the site archive file.Alert
You should unpack all the files to the
htmlroot directory, not to the/var/www/html/wordpresssubdirectory.Delete the backup file so that it does not take up space:
rm FILENAME.tar.gzReturn the rights for the folders:
htmland subfolders:755.- For all files inside
html:644. - For
wp-config.phpseparately, 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.phpfparameter: Searches for all files within folders.dparameter: Searches for all folders withinhtml.
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
To add a public DNS zone:
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 containing the
example.comDNS zone. - Select the
example.comDNS 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.
- Open the Cloud DNS section of the folder containing the
- Create a CNAME record:
- Select the
example.comDNS 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.
- Name:
- Click Create.
- Select the
Delegate the domain name
Delegation is the transfer of authority from the registrar's servers to yours. For a domain, 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 Whoisdig utility:
dig +short NS example.com
Result:
ns2.yandexcloud.net.
ns1.yandexcloud.net.
Test the website
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®
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
universeandcertbotrepositories:sudo add-apt-repository universe && sudo add-apt-repository ppa:certbot/certbotPress Enter.
-
Install the Let's Encrypt client:
sudo apt-get update && sudo apt-get install certbot python-certbot-apache -
Press Y and Enter.
Get an SSL certificate
-
Enter this command:
sudo certbot --apache -
In the interface, enter the name of your domain:
example.comorwww.example.com. -
Indicate whether to redirect all pages from
httptohttpswhen opening your website. Select2to redirect to https. -
Test your website: paste
https://www.ssllabs.com/ssltest/analyze.html?d=example.comto your browser's address bar.
Perform auto-update
The certificate is issued for 90 days. You need 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.logAs 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.
Test the website
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.
-
Enter the following command in the terminal:
sudo nano /var/www/html/.htaccess -
Add program 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.
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:
-
Enter this command:
sudo nano /etc/apache2/sites-available/000-default.conf -
Add program 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