devgiants/docker-wordpress

Ready-To-Start LAMP stack with Wordpress, WP-CLI and PHPMyAdmin


Keywords
wordpress, phpmyadmin, wp-cli, lamp, docker
License
MIT

Documentation

Ready-To-Start LAMP stack with Wordpress, WP-CLI and PHPMyAdmin

This boilerplate is a ready-to-start customizable LAMP stack with Wordpress, WP-CLI and PHPMyAdmin integration. Warning : for Linux users only.

Installation

Use composer create-project command :

composer create-project devgiants/docker-wordpress target-dir 1.5.0

This will clone the stack in your directory

Requirements

Mac users : During installation, the script requires the use of envsubst which is not installed by default on MacOS. You can install it directly with Homebrew:

brew install gettext
brew link --force gettext 

Configuration

Custom parameters

.env file

First of all, specify parameters needed for the project

Directories
  • WORDPRESS_HOST_RELATIVE_APP_PATH: This is the relative path from project initial path. Default to ./. Note: a volume will be created on this path in order to persist Wordpress app files.
  • LOGS_DIR: The logs directory.
Host
  • HOST_USER: Your current username. Needed to ensure creation (directories...) with your current user to preserve mapping between container and host
  • HOST_UID: Your current user host ID (uid). This is mandatory to map the UID between PHP container and host, in order to let you edit files both in container an through host volume access.
  • HOST_GID: Your current main group host ID (gid). (Not used so far)
Wordpress
  • PROJECT_NAME: The project name : used as Wordpress site name. IMPORTANT : as this is used for setting the theme directory as well, keep this name with underscores (i.e : project_test)

  • ADMIN_USER: the first user to be created

  • ADMIN_PASSWORD: the first user password. IMPORTANT: Keep it enclosed with double quotes.

  • PROJECT_REPO: the git repo address

  • WP_CLI_CACHE_DIR: WP-CLI cache directory. Leave it this way.

Database
  • MYSQL_HOST: The database host. Has to be equal to database container name in docker-compose.yml file (default mysql).
  • MYSQL_DATABASE: The database name you want
  • MYSQL_DATABASE_PREFIX: THe database prefix you want for your Wordpress installation
  • MYSQL_USER: THe database user you want to use (will be created on container creation)
  • MYSQL_PASSWORD: the database password you want
  • MYSQL_HOST_PORT: the host port you want to bind Mysql Server in container to.
  • MYSQL_PORT: the MySQL instance port. Careful, this is the MySQL port in container. Default to 3306
  • MYSQL_HOST_VOLUME_PATH: default ./docker/data/mysql/5.7. This is the volume which will store database.
Ports

You can have multiple projects using this boilerplate, but without changing ports, only one project can be up at a time, because port 80 is used to expose Apache.

  • APPLICATION_WEB_PORT: default to 80.
  • PHP_MY_ADMIN_PORT: default to 81.

Usage

There are 2 ways to use this : initialisation and day-to-day usage. A Makefile is created to help manipulate things

Initialisation

Blank project

Just execute make install to completly setup blank project. Please look to other entry points in Makefile to see what you can do

Project with Sage 9 theme

Just execute make sage to set a complete project with Sage 9.

Day-to-day usage

  • Execute make up for bringing project live
  • Execute make down for stopping and removing container instances.
  • Execute make bash-php for a shell in PHP container with www-data user.

Note : All volumes set will ensure to persist both app files and database.

Reset from scratch

If you want to reset everything, just

  1. Run docker-compose down.
  2. Remove the WORDPRESS_HOST_RELATIVE_APP_PATH and the MYSQL_HOST_VOLUME_PATH.
  3. Then goes back on make install.

Wordpress

Accessible on localhost by default.

Important note : to execute wp-cli, be sure to connect to php container with www-data user. The mapping described above targets www-data on container. Command to use : make bash-php

PhpMyAdmin

Accessible on localhost:81 by default. Use MYSQL_USER and MYSQL_PASSWORD to connect.