When starting a new WordPress project there are several steps I find to be repetitive. In an attempt to minimize this repetition, I created a boilerplate that leverages the use of Docker Containers. You can download this boilerplate on my GitHub account.
Replace mydomainname.com in the .env file with a value of your choice. This value is used to:
- Create a database in the **mariadb** Container.
- Configure the WordPress Container to use the newly created database.
- Name Docker Containers for easy identification.
NOTE: The MariaDB Container is simply named mariadb.
Reasoning for MariaDB Container Name
The MariaDB Container is simply named mariadb and takes just over 350MB of disk space brand new. Rather that create a new Docker Containers for each WordPress project, I manually create a new database on the same Container. To do this I use a database management tool such as DataGrip from JetBrains to authenticate as the root user as defined in the docker-compose.yml file. Of course you can use any other favorite tool of your choice. Rather than creating a new username and password for the new database created I use the same as the one that already exists. Because this is intended for local development only, using this method is not much of a problem. When the project is migrated to production then appropriate changes will be needed.
Create a Database
Make sure the mariadb Docker Container is running. Using your database management tool of choice, authenticate as the root user. Then create a new database accordingly. In the example below the default username of wordpress is used. If this is the second or higher database created on the existing Container, the user will already exist and be assigned a password. All that is left next is to grant the user privileges to the new database.
CREATE DATABASE 'newdomainname.com'; GRANT ALL PRIVILEGES ON 'newdomainname.com'.* TO 'wordpress'@'%'; FLUSH PRIVILEGES;
Default User Information
Both the WordPress and MariaDB Docker Containers make use of variables. Below are their default values.
- MYSQL_DATABASE=mydomainname.com - MYSQL_ROOT_PASSWORD=root_password - MYSQL_USER=wordpress - MYSQL_PASSWORD=wordpress
- WORDPRESS_DB_NAME=mydomainname.com - WORDPRESS_DB_HOST=db:3306 - WORDPRESS_DB_USER=wordpress - WORDPRESS_DB_PASSWORD=wordpress
Next I want WP CLI to automatically complete the post database creation process rather than manually entering initial site information data. WP CLI should also automatically install and activate any plugins I will needed for development. For example, if needed, WooCommerce should automatically be installed and activated as a ready to use plugin without further manual intervention.