Deploying containers in a swarm environment: Wordpress Migration

Pregunta'ns botó anglès

More manuals

Wordpress Migration

Export the Wordpress Files

Find the Document Root path.

cat /etc/apache2/sites-enabled/<nom-web>.conf | grep Document

When you know which directory is the data located in, you have to copy them to the NFS mounting point.

scp -rp DocumentRoot_path/* your_user@server_name.s.upf.edu:/mnt/vmdata/research_group/project_name/html

Copy the .htaccess file:

scp -rp DocumentRoot_path/.htaccess your_user@server_name.s.upf.edu:/mnt/vmdata/research_group/project_name/html

This file interacts with the Apache service and it is in charge of subdomain redirections. If this file is not copied, you will only see the main page of the site (index.php). .htaccess has content similar to this one:

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

Export the Database

The next step consists of knowing which database and credentials are used by Wordpress. wp-config.php file provides this information:

cat <DocumentRoot>/wp-config.php

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name');
 

/** MySQL database username */
define('DB_USER', 'user');
 
/** MySQL database password */
define('DB_PASSWORD', 'user_password');
 
/** MySQL hostname */
define('DB_HOST', 'localhost');

 

Then, export the database content with "mysqldump" command.

mysqldump -u user -p database_name > DatabaseDump.sql

 

Finally, copy the .sql file inside the project name folder of the NFS mounting point. Never copy it inside the mysql folder if you have not run the mysql container.

scp -rp DatabaseDump.sql your_user@server.s.upf.edu:/mnt/vmdata/research_group/project_name

Stack Creation

First of all, you will need to obtain the Wordpress version and MySQL version numbers.

<DocumentRoot>/wp-includes/version.php

mysql -V

Create the stack following these steps.

After that, configure yor Compose file. You need to create two services: HTML and MySQL.

  • HTML:
    • Use the wordpress:php7.3-apache image.
    • Add all this environment parameters: database host connection type, Wordpress credentials (user and password), and database name.
    • Define the port number.
    • Point the Wordpress files to /var/www/html.
  • MySQL:
    • Use the mysql:version image.
    • Add MySQL credentials.
    • Store database data to /var/lib/mysql.

Here, you have the Wordpress template. Since it is a .yml file extension, be careful with indents if you copy-paste some parts.

Database Import

Modify the wp-config.php file. Change 'localhost' to 'db':

/** MySQL hostname */
define('DB_HOST', 'db');

Move the DatabaseDump.sql inside mysql folder when its container is running and all configuration files created. 

mv DatabaseDump.sql  mysql/DatabaseDump.sql

Access to Console and export the database.

mysql -u root -p database_name < /var/lib/mysql/DatabaseDump.sq

Test

Test your application connecting to docker.sb.upf.edu:XXXX, where XXXX is the number port given to you in the CAU. 

If everything works fine, we will change the load balancer configuration to point to this port and all deployed docker servers.