Lightweight Wordpress on Alpine with php-fpm ondemand and SQLite instead of MySQL.
docker pull milanb/wordpress-sqlite
Docker Hub milanb/wordpress-sqlite
Can be used in conjunction with wordpress-nginx (Docker Hub milanb/wordpress-nginx) to provide a full lightweight Wordpress solution.
Example docker-compose.yml for both:
version: '2'
services:
wp:
image: milanb/wordpress-sqlite
environment:
- WP_HOME=https://mysite.com
- WP_SITEURL=https://mysite.com
volumes:
- db:/var/www/db
- uploads:/var/www/html/wp-content/uploads
restart: always
http:
image: milanb/wordpress-nginx
links:
- wp:wordpress
volumes_from:
- wp
ports:
- "8081:80"
volumes:
db:
external: true
uploads:
external: true
- Tar/Zip up the web root directory e.g.
/var/www/html
- Get a dump of the MySQL database for example with
mysqldump
- Use mysql2sqlite to convert your MySQL dump to a new SQLite database
- Change the domain name in
ingress.yaml
and then apply to a new namespace withkubectl apply -f kubernetes/
- When the pod is up and running, copy your backups into the container with commands like
kubectl cp -c wordpress db.db wordpress-0:/var/www/db/
kubectl cp -c wordpress backup.zip wordpress-0:/var/www/
- You can then "exec" into the container with
kubectl exec -it -c wordpress wordpress-0 -- /bin/bash
- Now you're in the container you need to ensure that the database has the right owner with
chown www-data. /var/www/db/db.db
- Extracting the backup is a little more fiddly but you can do something like
rm -r *
mv ../backup.zip .
unzip backup.zip
rm backup.zip
chown -R www-data. .
- You now need to modify your old Wordpress installation to use SQLite. First copy the driver PHP file to the right location with
cp /usr/src/wordpress/wp-content/db.php wp-content/
- You will now need to edit the wp-config.php file. You can either use
vi
in the container for this, orkubectl cp
it out, edit it in your favourite editor and thenkubectl cp
it back in. Just make sure it is still owned bywww-data:www-data
. For my environment I had to remove theDB_NAME
,DB_USER
,DB_PASSWORD
andDB_HOST
definitions and add in the following lines
define('DB_FILE', 'db.db');
define('DB_DIR', '/var/www/db/');
- Because I'm using HTTPS behind a Kubernetes Ingress I also found I had to add these lines to
wp-config
to get everything working correctly
// Reverse proxy https fix
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS'] = 'on';
if (isset($_SERVER['HTTP_X_FORWARDED_HOST']))
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];