Start web page

How to start a web page locally from sql and directory zip.

Required resources:

  • local user wordpress
  • disable login to user with sudo passwd -l wordpress
  • webpage.zip and webpage.sql files
  • directory /someplace/wordpress, in continuation export X=/someplace/wordpress
  • cd X; unzip -x webpage.zip should give you $X/webpage directory
  • mkdir $X/mysqlto host webpage
  • since docker container runs as some curious user, chmod a+w $X

Start the database

mariadb-compose.yaml:

#Use root/example as user/password credentials
version: '3.1'

services:

  db:
    image: mariadb
    restart: always
    environment:
      MARIADB_ROOT_PASSWORD: db.root.pswd

    volumes:
      - /someplace/wordpress/mysql:/var/lib/mysql

docker-compose -f mariadb-compose.yaml up
This also creates the database with the root password given

Find IP of newly created db instance:

docker network ls
docker inspect id

In my case, the container was labeled config_db_1, and by looking at output of docker inspect, the relevant ip was 172.18.0.2

To connect, I installed mysql-client locally (ie on host) and did

#>mysql -h 172.18.0.2 -pdb.root.pswd -u root
mysql>

Using the same settings, import the sql file

#>mysql -h 172.18.0.2 -pdb.root.pswd -u root < webpage.sql

The last missing piece is the user in wp-config.php. Look for lines

/** The name of the database for WordPress */
define('DB_NAME', 'webpage');

/** MySQL database username */
define('DB_USER', 'webpage.user');

/** MySQL database password */
define('DB_PASSWORD', 'webpage.user.pwd');

Create user webpage.user and grant all privileges on webpage database:

create user 'webpage.user'@'%' identified by 'webpage.user.pwd';
grant all privileges on webpage.* to 'webpage.user'@'%';

Check if connection works:

#>mysql -h 172.18.0.2 -pwebpage.user.pwd -u webpage.user webpage

Discussion