WordPress, Git and Docker

Viewed 1340

I have just started playing around with WordPress and I have a few questions:

  1. I would like to track my changes using Git. As far as I have researched, I should track only: 'wp-config.php' and 'wp-content' directory. Is there another way of tracking changes on a WP project?
  2. Everytime I clone the project, it greets me with the setup phase. I noticed that the changes are not really saved, i.e. deleting a plugin or creating a page. After looking in the database I noticed that WP stores pages and more info inside the database. How could I track this kind of changes?

Notes: I have created a development environment using Docker & Docker-Composer as follows. I would like to add pages and make configuration and then upload the changes to the git repository. The only problem is that WP saves the changes to the database. How should I handle this?

version: '3'

services:
  mysql:
    image: mysql:8
    container_name: "MySQL-Database"
    restart: always
    command: "--default-authentication-plugin=mysql_native_password"
    environment:
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    volumes:
      - ./mysql_data:/var/lib/mysql

  excelsior:
    build: ./excelsior-app/
    container_name: "Wordpress-Server"
    depends_on: 
      - mysql
    restart: always
    volumes:
      - ./excelsior-app/wp-content:/var/www/html/wp-content
    environment:
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    ports:
      - 8080:80
      - 443:443

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: "PHP-MyAdmin"
    depends_on: 
      - mysql
    restart: always
    ports:
      - 3333:80
    environment:
      PMA_HOST: mysql
      MYSQL_ROOT_PASSWORT: wordpress 

'excelsior' as follows:

FROM wordpress

COPY wp-config.php /var/www/html/
1 Answers

The reason WordPress stores it's data in a DB is because most of this data is in binary format, media, pictures, tables, indices.

Git works well tracking changes in text source code files, Git is not built to store any type of binary / media / data files, because there is no concept of tracking changes in a media / binary files.

So Git will be a good place to store the PHP scripts and configuration files and track the changes you make to those files.

For the purpose of backup and restore or even copying the latest development content from one WordPress server to another you can use the export tool and export all of the content to one XML file and then save it as a backup to be used to restore your entire WordPress content to a specific state in time.

Related