项目作者: samk-dev

项目描述 :
Local development environment for WordPress with Docker && Docker Compose
高级语言: Dockerfile
项目地址: git://github.com/samk-dev/docker-wp.git
创建时间: 2021-06-26T15:59:38Z
项目社区:https://github.com/samk-dev/docker-wp

开源协议:

下载


Docker WP

⚠️ still work in progress ⚠️

Local development setup for WordPress using Docker && Docker Compose with Nginx - PHP-FPM - MySql - PHP MyAdmin - Mailhog - Self-Signed SSL Certificates

Getting Started

We should set our enviornment variables and generate our self-signed ssl certificates. If you don’t want to enable ssl certificates please comment or remove the follwoing code to avoid errors. docker-compose.yml lines: 13 and 18 - etc/config/nginx.conf lines: 83 to the end of file

We adjust the variables in .env to suite our project the default ports are:

  • Ngnix Http: 80
  • Ngnix Https: 443
  • PHP-FPM: 9001
  • NodeJS: 3000
  • MySql: 3306
  • PHP MyAdmin: 8080
  • Mailhog Server: 1025
  • Mailhog UI: 8025
  • Portainer: 8000

Preparing Stuff

  1. # Clone the repository
  2. git clone git@github.com:samk-dev/docker-wp.git
  3. # Navigate to docker-wp
  4. cd docker-wp
  5. # Rename .env-example to .env
  6. mv .env-example .env
  7. ## Generate Self-Signed SSL Certificate ##
  8. ## This is not required if you don't need https and you did comment/remove the ssl settings ##
  9. # Give excution permissions to the script
  10. chmod u+x chmod u+x etc/scripts/self-signed-init.sh
  11. # Execute the script
  12. ./etc/scripts/self-signed-init.sh localhost

Starting Up Containers

from the project root run docker-compose up -d this will build and run the containers. Prepare yourself a ☕️ because it will take some time

From any web browser access:

Connect to the Database

The variables refrenced in the examples are the values you set in .env @ project root

wp-config.php

When running docker-compose up the first install will already fill the db credentials for you, so if you want to modify change the wp-config settings

When installing WordPress set the email as: dev@mailhog.local

  1. /** MySQL settings - You can get this info from your web host **/
  2. /** The name of the database for WordPress */
  3. define( 'DB_NAME', $MYSQL_DATABASE );
  4. /** MySQL database username */
  5. define( 'DB_USER', $MYSQL_ROOT_USER );
  6. /** MySQL database password */
  7. define( 'DB_PASSWORD', $MYSQL_ROOT_PASSWORD );
  8. /** MySQL hostname */
  9. define( 'DB_HOST', '<container_name>:<container_port>' );
  10. /** Database Charset to use in creating database tables. */
  11. define( 'DB_CHARSET', 'utf8' );
  12. /** The Database Collate type. Don't change this if in doubt. */
  13. define( 'DB_COLLATE', '' );

Connect to the Database using PHP MyAdmin

  • Server: mysql:${PORT_MYSQL}
  • Username: ${MYSQL_ROOT_USER}
  • Password: ${MYSQL_ROOT_PASSWORD}

Connect to the Database using database clients like Table Plus

  • Host: 127.0.0.1
  • Port: ${PORT_MYSQL}
  • Database: ${MYSQL_DATABASE}
  • User: ${MYSQL_ROOT_USER}
  • Password: ${MYSQL_ROOT_PASSWORD}

Access containers shell:

You can access any container shell by using the command docker exec -it ${CONTAINER_NAME} sh and exit to exit

Example by installing Sage 10 Starter Theme by the guys @ root.io:

  1. # Access WP container
  2. docker exec -it docker-wp-dev sh
  3. # Navigate to wp-content/themes
  4. cd wp-content/themes
  5. # Install Sage
  6. composer create-project roots/sage your-theme-name dev-master
  7. # Navigate to your-theme-name
  8. cd your-theme-name
  9. # Install all the necessary dependencies to run the build process
  10. yarn
  11. # OR
  12. npm install

⚠️ HMR is not working … working on a fix ⚠️

Mailhog Configuration

  • Install WordPress Mail SMTP Plugin
  • Navigate to WP Mail SMTP > Settings and Select PHP as mailer option
  • Navigate to WP Mail SMTP > Tools > Email Test
    in Send To set the address to dev@mailhog.local as a result you’de see a warning, ignore it and check mailhog to see the email

Xdebug Configuration

  • Inside etc/config/wordpress.ini change xdebug.remote_host to your local machine ip address
  • Restart appserver container docker restart appserver if you changed the service name make sure to refrence it instead of appserver
  • From php/wp container shell run php -i | grep Xdebug you should see xdebug version ++ more information