Moving WordPress on LightSail to Raspberry Pi 4

AWS



I found WordPress site which in on Raspberry Pi 4.
– This is Japanese tweet of mine.
So I am interested in running WordPress on my own Raspberry Pi 4 too.



This moving will be cost down of about 5 USD.

Actually electric cost of running Raspberry Pi will be there which is about less than 4 USD.
However I also run Nextcloud on Raspberry Pi so can think no problem.

System architecture

Current LightSail architecture is below.
I use bitnami WordPress multisite as it is.



My intension is below.
Setting reverse proxy in front of WordPress.
It may be negative impact from performance perspective, let’s see later.


reverse proxy’s docker-compose

You can find docker-compose recipe here.

GitHub - kurofuku/reverse-proxy
Contribute to kurofuku/reverse-proxy development by creating an account on GitHub.



This is simple structure.
Port number 9080 can be customized as you like.

version: '3.1'

services:

  https-portal:
    image: steveltn/https-portal:latest
    restart: always
    ports:
      - '80:80'
      - '443:443'
    environment:
      ACCESS_LOG: 'stdout'
      CUSTOM_NGINX_SERVER_CONFIG_BLOCK: 'proxy_read_timeout 300;'
      #STAGE: 'production'
      #FORCE_RENEW: 'true'
      DOMAINS: >-
       yasufumi-yokoyama.gq -> http://192.168.1.20:8080
       ,www.yasufumi-yokoyama.gq -> http://192.168.1.20:8080
       ,linuxfun.org -> http://192.168.1.20:9080
       ,www.linuxfun.org -> http://192.168.1.20:9080
      SERVER_NAMES_HASH_BUCKET_SIZE: 64
    volumes:
      - https-portal-data:/var/lib/https-portal

volumes:
  https-portal-data:



I used https-portal as reverse proxy base which is easy to use.
– HTTPS support with Let’s Encrypt
– Forwarding another container with watching status of container

GitHub - SteveLTN/https-portal: A fully automated HTTPS server powered by Nginx, Let's Encrypt and Docker.
A fully automated HTTPS server powered by Nginx, Let's Encrypt and Docker. - GitHub - SteveLTN/https-portal: A fully aut...

I will change STAGE: ‘production’ when my service is stable.



My intension is to add cache function to reverse-proxy or nginx of WordPress.



BTW, yasufumi-yokoyama.gq runs Nextcloud service.



 WordPress’s docker-compose

This is also available on github.

GitHub - kurofuku/wordpress-container
Contribute to kurofuku/wordpress-container development by creating an account on GitHub.



Reverse proxy forwards request to this service with 9080 then nginx listen 9080.
This container doesn’t have HTTPS because reverse-proxy already has.

version: '3.1'

services:
  nginx:
   image: nginx:latest
   restart: always
   links:
    - wordpress
   ports: 
    - 9080:80
   volumes:
    - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    - ./nginx/conf.d:/etc/nginx/conf.d
    - ./html:/var/www/html
    
  wordpress:
   build:
    context: wordpress
   links:
    - db
   restart: always
   volumes:
    - ./html:/var/www/html

  db:
   image: jsurf/rpi-mariadb:latest
   restart: always
   environment:
    MYSQL_ROOT_PASSWORD: root
    MYSQL_USER: wordpress
    MYSQL_PASSWORD: wordpress
    MYSQL_DATABASE: bitnami_wordpress
   volumes:
    - ./mysql:/var/lib/mysql



There is wordpress Dockerfile.
Only mandatory extensions are added.

FROM            php:fpm-buster

RUN             \
                apt -y update && \
                apt -y install default-mysql-client && \
                docker-php-ext-install mysqli && docker-php-ext-enable mysqli && \
                echo "Build complete." 



Backing up data from LightSail

We shall back up below data,

- Web contents which is html, php, or image
- mysql database


Web contents

Please do these command sets.

cd /opt/bitnami/apps/wordpress/htdocs/
sudo tar jcf wordpress.tar.bz2 .



I found many web sites mention

You only need to back up wp-content folder

But configuration of multisite couldn’t be copied.
So I backed up whole wordpress folder.

Backing up mysql database

Please do this command.

mysqldump -u root --single-transaction -p bitnami_wordpress > bitnami_wordpress.linuxfun.org.sql

I set database name as ‘bitnami_wordpress’ which is database name in mysql on LightSail.

Specifying database name is mandatory.
Firstly I executed without database name but other database like ‘mysql’ was also backed up..

Restoring to Raspberry Pi

First you need to copy data you backed up.

Web contents

First extract compressed data.

cd html
sudo tar jxf wordpress.tar.bz2 .
sudo chown -R www-data:www-data .



Second we need to modify wp-config.php.

Below is database configuration.

- define( 'DB_NAME', 'bitnami_wordpress' );
- define( 'DB_USER', 'bn_wordpress' );
- define( 'DB_PASSWORD', 'yourpassword' );
- define( 'DB_HOST', 'localhost:3306' );
+ define( 'DB_NAME', 'bitnami_wordpress' );
+ define( 'DB_USER', 'wordpress' );
+ define( 'DB_PASSWORD', 'wordpress' );
+ define( 'DB_HOST', 'db:3306' );



Below is to avoid mixed contents problem.

+ if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
+         $_SERVER['HTTPS'] = 'on';
+ }

  /** Sets up WordPress vars and included files. */
  require_once ABSPATH . 'wp-settings.php';  



Below is to replace LightSail specific environment variables.

- define('WP_TEMP_DIR', '/opt/bitnami/apps/wordpress/tmp');
+ define('WP_TEMP_DIR', '/tmp/wordpress');
// Below are for WP Super Cache
- define( 'WPCACHEHOME', '/opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/wp-super-cache/' );
+ define( 'WPCACHEHOME', '/var/www/html/wp-content/plugins/wp-super-cache/' );



That’s it for web contents. 

Database

Please do these commands.

sudo cp bitnami_wordpress.linuxfun.org.sql mysql
sudo docker-compose exec db /bin/bash

# Below are container inside
sed -i 's/utf8mb4_unicode_ci/utf8mb4_unicode_ci/g' /var/lib/mysql/bitnami_wordpress.linuxfun.org.sql
mysql -u root -p bitnami_wordpress < /var/lib/mysql/bitnami_wordpress.linuxfun.org.sql



 Somehow I need to change collation manually.

Below is LightSail. 

mysql --version
/opt/bitnami/mysql/bin/mysql.bin  Ver 8.0.20 for Linux on x86_64 (MySQL Community Server - GPL)

This is Raspberry Pi.

mysql --version
mysql  Ver 15.1 Distrib 10.3.27-MariaDB, for debian-linux-gnueabihf (armv8l) using readline 5.2



 That’s it for database.
If all went fine you can see top page of your blog!

Smoke test

 

It seems the same.
<—LightSail Raspberry Pi—>
You can see red triangle warning because https-portal isn’t configured as production.

 



I operated both site from Chromebook,

LightSail responds after 1 sec or 2 secs.
Raspberry Pi sometimes responds after more than 3 secs.


This is caused by CPU power.
Below is LightSail.

cat /proc/cpuinfo 
(snip)
model name      : Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz



 On the other hand Raspberry Pi’s CPU is Cortex-A72 1.5GHz.

Raspberry Pi 4 Model B specifications – Raspberry Pi
Your tiny, dual-display, desktop computer …and robot brains, smart home hub, media centre, networked AI core, factory co...

 



I took screenshot of LightHouse which is benchmark tool in Chrome Developer Tools.

This is the result of Desktop environment.
<— LightSail Raspberry Pi—>
I have no idea why Raspberry Pi has higher score??
– Maybe Raspberry Pi is in the same Wi-Fi network, so traffic is better than LightSail?? 



This is Mobile environment.
<— LightSail Raspberry Pi—>
Raspberry Pi has higher score too.

Conclusion

 How was it?

I will improve by introducing cache or others!

Comments

Copied title and URL