|
| 1 | +## 🎨 WordPress Docker Example |
| 2 | +[](https://www.repostatus.org/#active) |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +- WordPress Setup with Docker. |
| 9 | +- mysql |
| 10 | +- phpMyAdmin |
| 11 | + |
| 12 | +## Setup |
| 13 | +Run this from root |
| 14 | +```bash |
| 15 | +docker-compose -f docker-compose.yml up -d |
| 16 | +``` |
| 17 | + |
| 18 | +*WordPress* will be available on [http://localhost:8020](http://localhost:8020) |
| 19 | + |
| 20 | +*[phpMyAdmin](https://github.com/phpmyadmin/phpmyadmin)*: You can access php myadmin on [http://localhost:8183](http://localhost:8183) |
| 21 | +```shell script |
| 22 | +port: mysql:3306 |
| 23 | +username: root |
| 24 | +password: root |
| 25 | +``` |
| 26 | + |
| 27 | +phpmyadmin docker image already comes with the username `root` and we have set the mysql password in the dockerfile |
| 28 | + |
| 29 | +* If you happen to use your own WordPress setup, be sure to install and activate plugins from composer.json and add your own WordPress site URL |
| 30 | +in an .env file, You can check the .env-example file for reference. |
| 31 | + |
| 32 | +## Development ( Developers only ) |
| 33 | + |
| 34 | +1. When we change the composer.json, run from root |
| 35 | +```shell script |
| 36 | +docker-compose -f docker-compose.yml down && \ |
| 37 | +docker-compose -f docker-compose.yml up -d |
| 38 | +``` |
| 39 | + |
| 40 | +First line command will stops and removes all the docker containers and second line command will restart all containers. |
| 41 | +Notice that `-d` is to run in detach mode and you can always remove that flag, and run the command so you can see the live logs. |
| 42 | +Or you can check the logs for |
| 43 | + |
| 44 | +2. Check the logs |
| 45 | +While the above command is running in detached mode ( -d ), you can run this command in a new terminal tab to see the live logs. |
| 46 | +```shell script |
| 47 | +docker logs -f container-name |
| 48 | +``` |
| 49 | + |
| 50 | +e.g. |
| 51 | +```bash |
| 52 | +docker container ls |
| 53 | +``` |
| 54 | + |
| 55 | +#### result |
| 56 | +```shell script |
| 57 | +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 58 | +d0b4a3b0074f wordpress:latest "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:8000->80/tcp backend_wordpress_1 |
| 59 | +aad078ebe131 mysql:5.7 "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp, 33060/tcp backend_db_1 |
| 60 | +``` |
| 61 | +Here container-name is `backend_db_1` or `backend_wordpress_1` |
| 62 | + |
| 63 | +3. If you make changes to docker-compose.yml file, run the following: |
| 64 | + |
| 65 | +If you happend to change the port in `docker-compose.yml` make sure to delete the `db` directory and then run below. |
| 66 | + |
| 67 | +```shell script |
| 68 | +docker-compose -f docker-compose.yml down && \ |
| 69 | +docker-compose -f docker-compose.yml up -d |
| 70 | +``` |
| 71 | + |
| 72 | +## Debugging |
| 73 | + |
| 74 | +1. If you get 404 on requests, check to see that the .htaccess file in wordpress directory has the rules |
| 75 | + |
| 76 | +```shell script |
| 77 | +# BEGIN WordPress |
| 78 | +# The directives (lines) between "BEGIN WordPress" and "END WordPress" are |
| 79 | +# dynamically generated, and should only be modified via WordPress filters. |
| 80 | +# Any changes to the directives between these markers will be overwritten. |
| 81 | +<IfModule mod_rewrite.c> |
| 82 | +RewriteEngine On |
| 83 | +RewriteBase / |
| 84 | +RewriteRule ^index\.php$ - [L] |
| 85 | +RewriteCond %{REQUEST_FILENAME} !-f |
| 86 | +RewriteCond %{REQUEST_FILENAME} !-d |
| 87 | +RewriteRule . /index.php [L] |
| 88 | +</IfModule> |
| 89 | + |
| 90 | +# END WordPress |
| 91 | +``` |
| 92 | + |
| 93 | +## References for Docker Images. |
| 94 | + |
| 95 | +1. [phpMyAdmin](https://github.com/fuadajip/dockercompose-mysql-phpmyadmin/blob/master/docker-compose.yml) |
0 commit comments