[5 Mins Docker] User Docker to Create Wordpress Site with SQLiter (No MySQL Needed) - NETSEC

Latest

Learning, Sharing, Creating

Cybersecurity Memo

Saturday, May 4, 2024

[5 Mins Docker] User Docker to Create Wordpress Site with SQLiter (No MySQL Needed)

Deploying WordPress is not a easy task which you will need to install web service, database and all dependencies. And usually you will need to deal with MySQL/MariaDB installation and be familiar with creating db and users, which make it even more complex and consume more resources by running DB in backend. 

Can we using sQLite to run WordPress? Answer is yes. Here is one project I found from Github and DockerHub: WordPress with SQLite, ready to use out of the box.



 

Benefits to use SQLite:

Scenario:
On the lower end of the spectrum, there are small and simple sites. These are numerous and consist of all the blogs, company pages, and sites that don’t have thousands of users or thousands of posts, etc. These websites don’t always need the complexities of a MySQL/MariaDB database. The requirement of a dedicated MySQL server increases their hosting cost and the complexity of installation. On lower-end servers, it also decreases performance since the same “box” needs to cater to both a PHP and a MySQL/MariaDB server.

SQLite is the perfect fit:
  • It is the most widely used database worldwide
  • It is cross-platform and can run on any device
  • It is included by default on all PHP installations (unless explicitly disabled)
  • WordPress’s minimum requirements would be a simple PHP server, without the need for a separate database server.
  • SQLite support enables lower hosting costs, decreases energy consumption, and lowers performance costs on lower-end servers.

Steps


1 Get your own VPS, which you can get one from Azure, GCP or Oracle


2 Update system, install docker and docker-compose

We are using Ubuntu 22.04 LTS version as an example.

  • apt update
  • apt install docker.io
  • apt install docker-compose

3 Lauch Docker which has Wordpress and SQlite

Method 1: Use the following command to quickly launch the wordpress with port 8080

docker run --rm -it -d -p 8080:80 -v `pwd`/wordpress:/var/www/html soulteary/sqlite-wordpress:6.5.2



Method 2: You can also use docker compose to start wordpress:

version: '3'
services:
  wordpress:
    image: soulteary/sqlite-wordpress:6.5.2
    restart: always
    ports:
      - 8080:80
    volumes:
      - ./wordpress:/var/www/html

Save the file as docker-compose.yml and then execute docker compose up, then use browser access to localhost:8080.

4 Open Firewall Rule in your cloud environment for port 8080

Browser to open url https://<VPS Public IP>:8080


Use Your Own Domain for your Wordpress

 

1  Create dns A record in your DNS admin center
I am using cloudflare. 


2 Use NPM (Nginx Proxy Manager) to create a proxyed host record


3 Enable SSL for your NPM 


4 Change Your Wordpress site settings.



Self Hosted Docker Installation Pre-requirements

Free resources you might need to complete this docker project:


Pre-installed services:

  • Docker, 
    • apt update
    • apt install docker.io
    • apt install docker-compose
    • apt upgrade docker.io
    • mkdir /root/data/docker_data/<docker_name>
  • Docker-Compose (Using Ubuntu OS for the commands)
    • Docker-compose down
    • Optional command : use following command to backup your Docker data. You might need to change your folder name based on your docker configuraiton
      • cp -r /root/data/docker_data/<docker_name> /root/data/docker_data_backup/<docker_name>
    • docker-compose pull
    • docker-compose up -d
    • docker image prune
  • Portainer (Optional)
    • docker volume create portainer_data
    • docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
  • Install some applications: apt install wget curl sudo vim git (Optional)
  • aapanel with Nginx (Optional)
  • Nginx Proxy Manager (Optional)
  • Install screen (Optional)
    • Install screen (Depends on the Linux Distribution if it came pre installed or not) : yum install screen
    • Initiate a Screen : screen or  screen -S <screen name> <command to execute>
    • Detach from the screen : "CTRL+A,D" not "CTRL+A+D"
    • List all the screen currently working : screen -ls
    • Reattach to a screen : screen  -r  <session number> or screen -r <screen name>
    • Kill specific screen: screen -X -S <screen name> quit
    • Kill all screens : pkill screen

Monitoring Usage

  • Docker stats

Remove Docker and Related folders

  • docker stop <Docker Name> # stop the docker but not remove anything. 
  • docker rm -f <Docker Name>  # remove speficic container, but will not delete mapped volumes
  • rm -rf /root/data/docker_data/<Docker Mapped Volumns>  # remove all mapped volumes

Restrick Journal Log File Size:

  • journalctl --vacuum-size=100M
  • Limit it to 25M:
nano /etc/systemd/journald.conf
SystemMaxUse=25M
systemctl restart systemd-journald.service


or 
sudo bash -c 'echo "SystemMaxUse=100M" >> /etc/systemd/journald.conf'
sudo systemctl restart systemd-journald



Enable IPv6 and Limit Log File Size (Ubuntu)

Special command to cleans all logs and you don't need to stop the containers.

  • sudo sh -c 'truncate -s 0 /var/lib/docker/containers/*/*-json.log'
Add customized self defined IPv6 address segment to enable container's IPv6 fucntion. And limit log file's size and numbers in case log file to fill all hard drive's space. 

cat > /etc/docker/daemon.json << EOF
{
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "20m",
        "max-file": "3"
    },
    "ipv6": true,
    "fixed-cidr-v6": "fd00:dead:beef:c0::/80",
    "eixperimental":true,
    "ip6tables":true
}
EOF

Restart Docker service:

systemctl restart docker

Limit number of log files:

cat /etc/logrotate.d/rsyslog
/var/log/syslog
/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages
{
    rotate 4
    weekly
    missingok
    notifempty
    compress
    delaycompress
    sharedscripts
    postrotate
        /usr/lib/rsyslog/rsyslog-rotate
    endscript
}

You can change 4 to some other value, such as 1, so that only one file is stored.


Videos

 
[5 Min Docker] Create Free Wordpress Site Without DB (Using SQLite With Much Less RAM Usage)





References


No comments:

Post a Comment