{"id":15655271,"url":"https://github.com/garutilorenzo/wordpress-docker","last_synced_at":"2025-09-06T08:49:27.326Z","repository":{"id":154321835,"uuid":"416337444","full_name":"garutilorenzo/wordpress-docker","owner":"garutilorenzo","description":"Full stack (LEMP) Wordpress docker environment for dev and production use","archived":false,"fork":false,"pushed_at":"2021-10-18T10:31:12.000Z","size":43,"stargazers_count":27,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-04T05:46:06.343Z","etag":null,"topics":["devops","docker-compose","dockerfile","dokcer","hacktoberfest","lemp","lemp-stack","letsencrypt","nginx","phpmyadmin","ssl","wordpress","workflow"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/garutilorenzo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-12T12:55:53.000Z","updated_at":"2025-03-13T14:10:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"732dcc50-5bca-462a-b3c6-ebd3ed0d1a14","html_url":"https://github.com/garutilorenzo/wordpress-docker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garutilorenzo%2Fwordpress-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garutilorenzo%2Fwordpress-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garutilorenzo%2Fwordpress-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garutilorenzo%2Fwordpress-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/garutilorenzo","download_url":"https://codeload.github.com/garutilorenzo/wordpress-docker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252293129,"owners_count":21724962,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["devops","docker-compose","dockerfile","dokcer","hacktoberfest","lemp","lemp-stack","letsencrypt","nginx","phpmyadmin","ssl","wordpress","workflow"],"created_at":"2024-10-03T12:57:33.030Z","updated_at":"2025-05-04T05:46:08.258Z","avatar_url":"https://github.com/garutilorenzo.png","language":"Shell","readme":"# wordpress-docker\n\n[![Wordpress CI](https://github.com/garutilorenzo/wordpress-docker/actions/workflows/ci.yml/badge.svg)](https://github.com/garutilorenzo/wordpress-docker/actions/workflows/ci.yml)\n[![GitHub issues](https://img.shields.io/github/issues/garutilorenzo/wordpress-docker)](https://github.com/garutilorenzo/wordpress-docker/issues)\n![GitHub](https://img.shields.io/github/license/garutilorenzo/wordpress-docker)\n[![GitHub forks](https://img.shields.io/github/forks/garutilorenzo/wordpress-docker)](https://github.com/garutilorenzo/wordpress-docker/network)\n[![GitHub stars](https://img.shields.io/github/stars/garutilorenzo/wordpress-docker)](https://github.com/garutilorenzo/wordpress-docker/stargazers)\n\n# Table of Contents\n\n* [Requirements](#requirements)\n* [Environment setup](#environment-setup)\n* [Use the environment](#use-the-environment)\n* [Import an existing WP site](#import-an-existing-wp-site)\n* [WP Cli](#wp-cli)\n* [Fix permission problem](#fix-permission-problem)\n* [Nginx](#nginx)\n* [SSL](#ssl)\n  * [Certbot/Let's encrypt](#certbotlets-encrypt)\n  * [Owned SSL certificates](#owned-ssl-certificates)\n* [PhpMyAdmin](#phpmyadmin)\n* [MySQL dump](#mysql-dump)\n\n### Requirements\n\nTo use this environment you need [Docker](https://docs.docker.com/get-docker/) an [Docker compose](https://docs.docker.com/compose/install/) installed.\n\n### Environment setup\n\nYou can find all the settings in the *.env* file in the root folder of this repository. The default settings are:\n\n| Label   | Required | Default | Description |\n| ------- | -------- | ------- | ----------- |\n| `ENV` | `yes` | `PROD`      | Valid values are: PROD or DEV. Changing this varialbe the environment will use a different WP image. In DEV environment is used the docker image with embadded Apache, in prod env is used the php-fpm docker image  |\n| `WORDPRESS_IMAGE` | `yes`  | `wordpress`    | The [default](https://hub.docker.com/_/wordpress) docker image to use. |\n| `WORDPRESS_PROD_VERSION` | `yes`  | `php7.4-fpm`     | Production docker image version (php-fpm)|\n| `WORDPRESS_DEV_VERSION` | `yes`  | `php7.4`     | Development docker image version (embadded apache) |\n| `WORDPRESS_CLI_VERSION` | `yes`  | `cli-php7.4`     | WP client docker image version |\n| `WORDPRESS_DB_NAME` | `no`  | `wordpress`     | WP database name |\n| `WORDPRESS_TABLE_PREFIX` | `no`  | `wp_`     | WP mysql table prefix |\n| `WORDPRESS_DB_HOST` | `no`  | `myslq`     | MySQL container name |\n| `WORDPRESS_DB_USER` | `no`  | `wordpress`     | MySQL WP user  |\n| `WORDPRESS_DB_PASSWORD` | `no`  | `password`     | MySQL WP user |\n| `MARIADB_VERSION` | `no`  | `latest`     | MariaDB container version |\n| `MYSQL_ROOT_PASSWORD` | `no`  | `s3cretPassW0rd`     | Development docker image version (embadded apache) |\n| `MYSQL_DATA_DIR` | `no`  | `./wordpress-sql`     | Local path for MySQL backup/restore |\n| `MYSQL_DUMP_DIR` | `no`  | `./mysql-dumps`     | Local where dump_mysql.sh store the MySQL dumps |\n| `NGINX_VERSION` | `no`  | `latest`     | Nginx  container version |\n| `SERVER_NAME` | `yes` | `example.com`      | Second level domain name (Example: example.com)  |\n| `SERVER_ALT_NAME` | `yes`  | `www.example.com`    | Third level domain name (Example: www.example.com) |\n| `WP_CONTAINER_NAME` | `yes`  | `wordpress`     | WP container name (defined in docker-compose.yml) |\n| `SECURE_SUBNET` | `no`  | `192.168.0.0/16`     | Secure subnet to allow traffic to wp-admin, wp-login.php and xmlrpc.php  |\n| `NGINX_CONF_DIR` | `no`  | `./config/nginx/cfg/`     | Nginx custom configuration path |\n| `NGINX_TEMPLATE_DIR` | `no`  | `./config/nginx/tpl/`     | Nginx template configuration path |\n| `WORDPRESS_UID` | `no`  | `1000`     | UID of the user running docker |\n| `WORDPRESS_GID` | `no`  | `1000`     | GID of the user running docker |\n| `WORDPRESS_USER` | `no`  | `app`     | Username used inside the WP docer container |\n| `WORDPRESS_GROUP` | `no`  | `app`     | Group assigned to WORDPRESS_USER |\n| `CUSTOM_WORDPRESS_IMAGE` | `no`  | `my-wordpress`     | WP custom docker image name |\n\n### Use the environment\n\n#### Development\n\nIf you would like to use this environment for local test or if you are developing a new plugin or theme you have to use the develompment version. To use this version create a symlink from docker-compose-dev.yml to docker-compose.yml\n\n```\nln -s docker-compose-dev.yml docker-compose.yml\n```\n\nand change in the .env file the ENV value to DEV:\n\n```\nENV=DEV\n```\n\nyou can now start the environment with:\n\n```\ndocker compose up -d\n```\n\nyou can check the logs with:\n\n```\ndocker compose logs -f\n```\n\nNow you have:\n\n* wordpress listening on port 80 (with embadded Apache). Access your wordpress on http://localhost\n* PhpMyAdmin listening on port 8080. Access PMA on http://localhost:8080 (see PhpMyAdmin section)\n* MySQL running but is not listening on any interface\n* Wordpress CLI container available (see WP Cli section)\n\nIf you are developing a new theme or plugin is possible that you're facing a permission problem, if you check the files permission under wordpress-src you see that the files are owned by www-data:\n\n```\ndrwxr-xr-x  5 www-data www-data  4096 Oct 12 15:34 wordpress-src\n```\n\nTo fix this issue see the \"Fix permission problem\" section\n\n#### Production\n\nIf you are ready to spin up a production environment simply create a symlink from docker-compose-prod.yml to docker-compose.yml:\n\n```\nln -s docker-compose-prod.yml docker-compose.yml\n```\n\nand check in the .env file that the ENV variable is set to PROD:\n\n```\nENV=PROD\n```\n\nOn production environment you have to configure also nginx. To do so, check the environment variables attached to the nginx container.\n\nThe environment variables are:\n\n* SERVER_NAME: Second level domain name (Example: example.com)\n* SERVER_ALT_NAME: Third level domain name (Example: www.example.com)\n* WP_CONTAINER_NAME: WP container name (defined in docker-compose.yml)\n* SECURE_SUBNET: Secure subnet to allow traffic to wp-admin, wp-login.php and xmlrpc.php (Default 192.168.0.0/16)\n\nyou can now start the environment with:\n\n```\ndocker compose up -d\n```\n\nyou can check the logs with:\n\n```\ndocker compose logs -f\n```\n\nNow you have:\n\n* nginx listening on ports 80 and 443 (optional). (see nignx section)\n* wordpress running with php-fpm container\n* PhpMyAdmin running, traffic to PhpMyAdmin is filtered by nginx (see PhpMyAdmin section)\n* MySQL running but is not listening on any interface\n* Wordpress CLI container available (see WP Cli section)\n\n### Import an existing WP site\n\nIf you have a running WP site and you want to use this environment you have to extract your existing sources in *wordpress-src* directory and the MySQL dump in *wordpress-sql* directory.\n\n**NOTE** before spin up the environment, check wordpress-src directory permission. If you have build a [custom image](#fix-permission-problem) remember to:\n\n```\nchown -R uid:gid wordpress-src/\n```\n\nif you use the standard wordpress image all files and directory must be owned by user and group (www-data). Your system might be have a different uid and git for the www-data user and group (or you might don't have this user and group), so to fix the permission problem use the uid and gid directly:\n\n```\nchown -R 33:33 wordpress-src/\n```\n\n**MySQL NOTE** dump can be in plain text or gzipped. The extension must be *.sql or *.gz\n\n**MySQL NOTE2** dump will be restored only on the first startup. If you want to restore a new dump you have to:\n\n* stop mysql container (docker-compose stop mysql)\n* remove the mysql volume (docker volume rm wordpress-docker_mysql). **Tip** you can find the volume name with: *docker volume ls.*\n* place the new dump in wordpress-sql\n* start the container (docker-compose up -d)\n\n### WP Cli\n\nCheck the Wordpress Client referenche [here](https://developer.wordpress.org/cli/commands/)\n\nTo use the wordpress CLI use for example:\n\n```\ndocker-compose run --rm wordpress-cli wp core install --url=http://localhost --title=test --admin_user=admin --admin_email=test@example.com\nCreating wordpress-docker_wordpress-cli_run ... done\nAdmin password: \u0026kWu5@BldBHixvvaim\nWarning: Unable to create directory wp-content/uploads/2021/10. Is its parent directory writable by the server?\nSuccess: WordPress installed successfully.\n```\n\n### Fix permission problem\n\nTo fix the permission problem the solution is to build a custom image. This image will then run all the processes inside the container with a user with a user with the same uid and gid of your local computer's user.\n\nFirst we need to check our uid and gid (use the *id* command):\n\n```\nid\n\nuid=1000(your-local-user) gid=1000(your-local-group) groups=1000(your-local-group),4(adm),24(cdrom),27(sudo)\n```\n\nthen in the .env file adjust the variables:\n\n* WORDPRESS_UID\n* WORDPRESS_GID\n\nwith your uid and gid. Now we can build our custom image:\n\n```\nbash build.sh\n```\n\nthis will produce two new images, one for wordpress (my-wordpress:php7.4) and one for the wordpress cli (my-wordpress:cli-php7.4). A sample output will be:\n\n```\nStep 4/10 : ARG WORDPRESS_UID\n ---\u003e Using cache\n ---\u003e 7eb312bf432b\nStep 5/10 : ARG WORDPRESS_GID\n ---\u003e Using cache\n ---\u003e 917ace616147\nStep 6/10 : ARG WORDPRESS_USER\n ---\u003e Using cache\n ---\u003e aad8c3c33e3a\nStep 7/10 : ARG WORDPRESS_GROUP\n ---\u003e Using cache\n ---\u003e 14248a4f8db9\nStep 8/10 : COPY ./adduser.sh /\n ---\u003e Using cache\n ---\u003e 255a4a665ac6\nStep 9/10 : RUN /adduser.sh \u0026\u0026 rm -rf /adduser.sh\n ---\u003e Using cache\n ---\u003e 8e84c8cce8b2\nStep 10/10 : USER ${WORDPRESS_USER}\n ---\u003e Using cache\n ---\u003e d36fbaf33c9e\nSuccessfully built d36fbaf33c9e\nSuccessfully tagged my-wordpress:cli-php7.4\n```\n\nNow to use this new image you have to change the WORDPRESS_IMAGE in the .env file:\n\n```\nWORDPRESS_IMAGE=my-wordpress\n```\n\nNow stop the environment, fix wordpress-src directory permission and bring up the environment with the new image:\n\n```\ndocker-compose down\nsudo chown -R your-local-user:your-local-group wordpress-src\n[sudo] password for your-local-user:\n\ndocker-compose up -d\n```\n\n**NOTE** you can change the custom image name by editing the .env file and change the CUSTOM_WORDPRESS_IMAGE variable.\n\n### Nginx\n\nBy default Nginx will expose only the http port (port 80). The default configuration is config/nginx/tpl/nginx-http.conf.template. This template will be rendered on every nginx startup. For more information the nignx documentation is available [here](https://hub.docker.com/_/nginx)\n\nBy default this template use many security enhancements, removing access to many WP paths and files. You can find the configurations under: config/nginx/cfg/\n\nTo disable this security enhancements edit the config/nginx/tpl/nginx-http.conf.template and comment or delete the lines:\n\n```\n# Security\ninclude /etc/nginx/custom.conf.d/nginx-custom-configs.conf;\ninclude /etc/nginx/custom.conf.d/nginx-wp-hardening.conf;\n```\n\nIn the default template the following locations are protected:\n\n* /pma/ (PhpMyAdmin)\n* /xmlrpc.php\n* /wp-admin/\n* wp-login.php\n\nThe traffic to this location is filtered by the SECURE_SUBNET environment variable (Default 192.168.0.0/16). Only the client in this subnet will be able to access this locations.\n\nTo disable this filter edit the config/nginx/tpl/nginx-http.conf.template file and comment or delete this lines:\n\n```\nallow ${SECURE_SUBNET};\nallow 127.0.0.1; \ndeny all;\n```\n\n### SSL\n\nA configuration example is placed on config/nginx/tpl/nginx-https.conf.example to enable SSL rename this file with the .template extension.\n\n**Note** remember to delete or rename the nginx-http.conf.template\n\n#### Certbot/Let's encrypt\n\nUncomment certbot service in docker-compose.yml\n\nIf you have to create a new SSL certificate, modify init_letsencrypt.sh with your domain(s) name(s) and change the email variable.\nRequire the new certificate with:\n\n```console\nbash init_letsencrypt.sh\n```\n\nfor nginx auto reload, uncomment the *command* on the nginx service. This is necessary for auto reload nginx when certot renew the ssl certificates.\n\nNow restart nginx and certbot:\n\n```console\ndocker-compose up -d\n```\n\n#### Owned SSL certificates\n\nIf you have your own SSL certificate modifiy config/nginx/tpl/nginx-https.conf.example and adjust the nginx volumes in docker-compose.yml.\n\n**Note** remember to rename config/nginx/tpl/nginx-http.conf.example file with the .template extension.\n\nYou can now start the services with:\n\n```console\ndocker-compose up -d\n```\n\n### PhpMyAdmin\n\nThe default username is root, and the password is the value of MYSQL_ROOT_PASSWORD in the .env file\n\n#### Development\n\nYou can access phpMyAdmin at http://127.0.0.1:8080 \n\n#### Production\n\nYou can access phpMyAdmin at http://example.com/pma (access filtered by ip)\n\n\n### MySQL dump\n\nTo dump the current MySQL state you can use the dump.sh file. The dump will be saved in mysql-dumps directory (you can customize the dump directory in the .env file)\n\n```\nbash dump_mysql.sh \nls -la mysql-dumps/\n\n-rw-rw-r--  1 lorenzo lorenzo    473 Oct 18 12:21 wordpress.20211018122109.gz\n-rw-rw-r--  1 lorenzo lorenzo 299673 Oct 18 12:22 wordpress.20211018122247.gz\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarutilorenzo%2Fwordpress-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgarutilorenzo%2Fwordpress-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarutilorenzo%2Fwordpress-docker/lists"}