{"id":20892639,"url":"https://github.com/webandras/docker-wordpress","last_synced_at":"2025-05-12T22:31:53.077Z","repository":{"id":45569848,"uuid":"432855035","full_name":"webandras/docker-wordpress","owner":"webandras","description":"Docker setup for WordPress local development, custom domain, https, nginx reverse proxy","archived":false,"fork":false,"pushed_at":"2024-08-24T15:43:24.000Z","size":23885,"stargazers_count":10,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-24T16:56:53.573Z","etag":null,"topics":["docker","wordpress"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webandras.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-11-29T00:03:29.000Z","updated_at":"2024-08-24T15:39:34.000Z","dependencies_parsed_at":"2024-05-11T10:50:45.411Z","dependency_job_id":null,"html_url":"https://github.com/webandras/docker-wordpress","commit_stats":null,"previous_names":["webandras/docker-wordpress"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webandras%2Fdocker-wordpress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webandras%2Fdocker-wordpress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webandras%2Fdocker-wordpress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webandras%2Fdocker-wordpress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webandras","download_url":"https://codeload.github.com/webandras/docker-wordpress/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225157011,"owners_count":17429701,"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":["docker","wordpress"],"created_at":"2024-11-18T10:13:29.638Z","updated_at":"2024-11-18T10:13:30.319Z","avatar_url":"https://github.com/webandras.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WordPress Docker development template\n\nThis template is made for local development only.\n\nWordPress Core files are moved into a separate folder in this setup.\n\nFor the WordPress core, install path is `src/wp` folder, but the wp-config file used is in the root (\ncustomized with `bin/setup-wp` script, see later).\n\nTo put WP core to separate folder set `WP_CORE_SEPARATE` env variable to `\"true\"` (**DO NOT change it**)\n\n_Note: Previously, there was the option to set up WordPress the usual way (no separate wp folder), but it is removed\nnow._\n\nThe following Docker images are included:\n\n- [wordpress:php8.2-apache](https://hub.docker.com/_/wordpress)\n- [nginx:latest](https://hub.docker.com/_/nginx)\n- [mysql:8.0](https://hub.docker.com/_/mysql)\n- [phpmyadmin/phpmyadmin](https://hub.docker.com/r/phpmyadmin/phpmyadmin)\n- [sj26/mailcatcher:v0.10.0](https://hub.docker.com/r/sj26/mailcatcher)\n\n\nChange your docker PHP version in: `.docker/images/wordpress/Dockerfile`, or `.docker/images/wordpress/Dockerfile-ssl`.\nIt works with 8.0, 8.1 as well. WordPress 6.6 [already supports PHP 8.2]((https://make.wordpress.org/core/handbook/references/php-compatibility-and-wordpress-versions/)) (with possible exceptions)\n\n**Project structure:**\n\n- `.docker`: contains all docker-specific files and folders\n- `src`: the source code goes here\n\n\n## Install a new, or setup an existing WordPress site\n\n### HTTPS install\n\nUse the `master` branch which is the default!\n\n1. Set your environment variables in `.env`, change `APP_NAME` (also read the 5th point below!)\n2. Setup ssl for your custom domain `${APP_NAME}.local`\n\n```shell\nbin/setup-ssl\n```\n\nYou may need to make scripts in the `bin` folder, and the `.docker/images/nginx/ssl/mkcert-v1.4.3-linux-amd64`\nexecutable (https://github.com/FiloSottile/mkcert/releases).\n\nThe supplied mkcert version is for Debian/Ubuntu.\n\n3. Modify `.docker/images/nginx/conf.d/default.conf`: Change `server_name` to your custom domain (`${APP_NAME}.local`)!\n\n4. Add domain alias for 127.0.0.1 (e.g. `nano /etc/hosts` for Linux)\n\n5. Build docker project (on Linux make sure to configure Docker so that you can run it without sudo privileges):\n\n```shell\n(set -a;source .env;docker-compose -f docker-compose-ssl.yml up --build)\n```\n\nWith sudo privileges (not recommended):\n\n```bash\nset -a\nsource .env\nsudo -E docker-compose up --build\n```\n\n5. WordPress database installation with wp-cli, import db for existing sites\n\n- For a new site run this command (it will set up your database and configure your site automatically):\n\n```shell\nbin/setup-wp\n```\n\n- For an existing site, import sql dump or use PhpMyAdmin (however, the latter is not suitable for importing large\n  database sql dumps):\n\n```shell\nbin/mysql-import\n```\n\nThe sql dump should be placed into this folder with the same filename: `db/db.sql`\n\nMake sure to have the correct database name in the comments of the sql dump. Example:\n\n```sql\n-- MySQL dump 10.13  Distrib 8.0.31, for Linux (x86_64)\n--\n-- Host: localhost    Database: testdbname\n--\n-- Current Database: `testdbname`\n--\nCREATE\nDATABASE /*!32312 IF NOT EXISTS*/ `testdbname` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;\nUSE\n`testdbname`;\n```\n\nFor existing sites, replace domain in database tables (enter container first with bash):\n\n```shell\nbin/bash\nwp search-replace 'https://example.com' 'https://example.local' --skip-columns=guid\n```\n\n**Add your themes, plugins and other assets to `src\\wp-content/`**\n\nNo need to change any additional files. The `wp-config.php` loads all credentials from the `.env` file. Every bash\nscript in bin folder loads environment variables from `.env`.\n\nCreate a new admin user if needed, example:\n\n```shell\nbin/bash\nwp user create username name@example.com --role=administrator --user_pass=Password123!\n```\n\n\n### HTTP install\n\nInstallation is almost the same as for https. We just need to use another docker-compose file for the build:\n\n```shell\n(set -a;source .env;docker-compose -f docker-compose.yml up --build)\n```\n\n\n## Configure WordPress local site\n\n1. Install/update composer packages (composer.json is in the `/src` folder). Run\n\n```shell\nbin/composer update\n```\n\n_! NOTICE: Installing or updating WordPress with composer returns a non-breaking error. However, plugins and themes are\ninstalled properly despite the error. Need to be resolved. -\u003e error DISAPPEARED (2023-01-25)_\n\n2. Add/update `wp-config.php` constants, values etc. (optional, not needed generally)\n\n```bash\n# List all currently defined configuration props \nwp config list\n\n# Update salts used for hashing\nwp config shuffle-salts\n\n# Show debug information\nwp config set WP_DEBUG true --raw\nwp config set WP_DEBUG_LOG true --raw\nwp config set WP_DEBUG_DISPLAY true --raw\n\n# Force 'direct' filesystem method for WP (automatic detection doesn't work well in a Docker container)\nwp config set FS_METHOD \"'direct'\" --type=constant --add --raw\n\n# Disable core/plugin/theme modification\nwp config set \"DISALLOW_FILE_MODS\" true --type=constant --add --raw\n```\n\n\n## Customisations made to `wordpress` image\n\n- wp-cli, and composer 2 was installed. (The official image does not have it. There is a `wordpress:cli` image, but it\n  only contains the wp-cli. In this image, apache2 is also configured. This is the reason why it is used here.)\n- For convenient work in the terminal, vim and nano is also installed.\n- `php.ini` setting change for mailcatcher (you can change the email to any fake one)\n  `sendmail_path = /usr/bin/env catchmail -f wordpress@local.test`\n- upload_max_filesize = 20M\n\n\n## Composer\n\nCore, plugins and themes are installed/handled/updated/deleted with composer to keep track of the dependency versions.\n\nDo not update packages with the wp-cli, because it will lead to inconsistencies in versions defined in\ncomposer.json and the actual versions installed!\n\nModifying files on the wp-admin can be disabled (using the `DISABLE_FILE_MODS` constant) that will make changes to core,\nthemes and plugins impossible on the\nadmin dashboard:\n\n```bash\nbin/bash\nwp config set \"DISALLOW_FILE_MODS\" true --type=constant --add --raw\n```\n\nUpdate packages:\n\n```bash\nbin/composer update\n```\n\n\n## MySQL database management, PhpMyAdmin\n\n- Import database: `bin/mysql-import`\n- Export database: `bin/mysql-dump`\n\nAll sql files should be put into the `db` folder.\n\nNote: Auto-importing db dump is currently disabled. In `docker-compose.yml`, this is commented out:\n`./db:/docker-entrypoint-initdb.d # where to find the db dump data`\n\nIt is a better idea to use the `bin/mysql-import` script instead.\n\nMake sure to replace urls in data tables (like https://example.com -\u003e https://example.local). The easiest way is to use\nthe wp-cli:\n\n```shell\nbin/bash\nwp search-replace 'https://example.com' 'https://example.local' --skip-columns=guid\n```\n\nChange 'wp_' table prefix to a custom one. For example, use PhpMyAdmin: select all data tables and change table prefix\non the\nUI. [Read more](https://help.one.com/hc/en-us/articles/360002107438-Change-the-table-prefix-for-WordPress-).\nIn addition, you need to update the meta_keys in these tables (there may be more keys you need to change):\n\n```sql\nUPDATE NEWPREFIX_usermeta\nSET meta_key = 'NEWPREFIX_capabilities'\nWHERE meta_key = 'OLDPREFIX_capabilities';\nUPDATE NEWPREFIX_usermeta\nSET meta_key = 'NEWPREFIX_user_level'\nWHERE meta_key = 'OLDPREFIX_user_level';\nUPDATE NEWPREFIX_usermeta\nSET meta_key = 'NEWPREFIX_autosave_draft_ids'\nWHERE meta_key = 'OLDPREFIX_autosave_draft_ids';\nUPDATE NEWPREFIX_options\nSET option_name = 'NEWPREFIX_user_roles'\nWHERE option_name = 'OLDPREFIX_user_roles';\n```\n\nPhpMyAdmin service is accessible here: `http://localhost:1337`\n\n\n## Manage docker containers / Development\n\nMake sure the host ports that are bound to our container's internal ports are not in use by another container or host\nprocess.\n\nThe containers need to be built for the first time:\n\n```bash\n(set -a;source .env;docker-compose -f docker-compose.yml up --build)\n```\n\n```bash\n(set -a;source .env;docker-compose -f docker-compose-ssl.yml up --build)\n```\n\n- Start containers: `bin/start`\n- Stop containers: `bin/stop`\n- Down containers (this will remove and destroy containers): `bin/down`\n- Restart containers: `bin/restart`\n\n```bash\ndocker-compose down\n```\n\n\n## Bash scripts in `bin` folder\n\nUseful and makes it faster to run some common tasks. Check them out.\n\n\n## Useful WP CLI commands\n\n[Full documentation.](https://developer.wordpress.org/cli/commands/)\n\n```shell\n# CORE\nwp help\nwp core is-installed\nwp core version\nwp core check-update\n#wp core update -\u003e use composer instead\n#wp core download -\u003e use composer instead\nwp core update-db\n\n\n# REPLACE domain name - very useful\n# Search and replace but skip one column\nwp search-replace 'http://example.test' 'https://example.com' --skip-columns=guid\n\n# Create a POT file for the WordPress plugin/theme into the specified directory\nwp i18n make-pot plugins/your-plugin-name plugins/your-plugin-name/languages/your-textdomain.pot\n\n# Call get_bloginfo() to get the name of the site.\nwp shell\nget_bloginfo( 'name' );\n\n# Flushes the object cache.\nwp cache flush\n\n# Flush rewrite rules\nwp rewrite flush\n\n# Update permalink structure\nwp rewrite structure '/%year%/%monthnum%/%postname%'\n\n# List rewrite rules\nwp rewrite list --format=csv\n\n\n# CONFIG\n# Shuffle the salts for the hashes:\nwp config shuffle-salts\nwp config list\n\n# show debug information\nwp config set WP_DEBUG true --raw\nwp config set WP_DEBUG_LOG true --raw\nwp config set WP_DEBUG_DISPLAY true --raw\n\n# force 'direct' filesystem method for WP (automatic detection doesn't work well in a Docker container)\nwp config set FS_METHOD \"'direct'\" --type=constant --add --raw\n\n# disable core/plugin/theme modification\nwp config set \"DISALLOW_FILE_MODS\" true --type=constant --add --raw\n\n\n# PLUGINS\n# Activate plugin\nwp plugin activate hello\n\n# Deactivate plugin\nwp plugin deactivate hello\n\n# Delete plugin\n# wp plugin delete hello -\u003e use composer instead\n\n# Install the latest version from wordpress.org and activate\n# wp plugin install bbpress --activate  -\u003e use composer instead\n\n# Generate a new plugin with unit tests\nwp scaffold plugin sample-plugin\n\n\n# THEMES\n# Generate theme based on _s\nwp scaffold _s sample-theme --theme_name=\"Sample Theme\" --author=\"John Doe\"\n\n# Generate code for post type registration in given theme\nwp scaffold post-type movie --label=Movie --theme=simple-life\n\n# Get status of theme\nwp theme status twentysixteen\nwp theme activate\n\n# Install the latest version of a theme from wordpress.org and activate\n# wp theme install twentysixteen --activate  -\u003e use composer instead\n\n# Get details of an installed theme\nwp theme get twentysixteen --fields=name,title,version\n```\n\n\n## Deployment on shared hosting\n\n1. Create a new MySQL database\n2. Update `wp-config` with the new database credentials (database name, username, password). The host is `\"localhost\"`\n   most of\n   the time.\n3. Export your local database with PhpMyAdmin, or create a sql dump with MySQL in the terminal (for larger databases,\n   the latter is recommended). After that, import it into your live database.\n4. You have to rewrite the urls and some options with your live domain name (see `src/data/rewrite-domainname.sql`). Or,\n   you\n   can also use the `wp-cli` locally, and then export your local database (and rewrite them back to the local ones\n   afterward).\n5. Copy the content of the `src/` folder to your host through SFTP.\n6. Post-deployment: Setup SMTP, increase security (use WordFence firewall), etc.\n\nOccasionally, change your [salts](https://api.wordpress.org/secret-key/1.1/salt/) used for hashing.\n\n\n## Update .gitignore file!\n\nMake sure you NEVER commit the .env file and wp-config.php to version control. It also applies to your ssl\ncertificate keys you generated with mkcert!\n\nThese ignore rules are already added to `.gitignore`.\n\n**Good tip: Set up GitGuardian** to get notification about potential credential leaks.\n\n\n## Mailcatcher for local e-mail testing\n\n1. See the `mailcatcher` in the docker-compose files.\n\n2. Install `\"wpackagist-plugin/wp-mail-smtp\":\"4.0.1\"` with Composer inside the WordPress service if you don't have it:\n   `bin/composer require \"wpackagist-plugin/wp-mail-smtp\":\"4.0.1\"`.\n\n3. Configure SMTP:\n\nSetup \"from address\", and \"name\". Choose the \"Other SMTP\" option.\nSet these:\n\n- SMTP Host: **mailcatcher**\n- SMTP Port: **1025**\n\nNo need for encryption.\nAuto TLS -\u003e Off.\nAuthentication -\u003e None.\n\n4. Send out a test email (Tools menu point under WP Mail SMTP).\n\n5. Access Mailcatcher UI at `localhost:1080`\n\nGenerally, there is no need to configure anything else if you followed the instructions, or you didn't make other\nchanges. See the PHP section on the [mailcatcher website](https://mailcatcher.me/), or in\nthe [PHP documentation](https://www.php.net/manual/en/mail.configuration.php#ini.sendmail-path) for more info.\n\nThis is the `php.ini` file location inside the **wordpress** container: `/usr/local/etc/php`. This file is copied here\nfrom `.docker/images/wordpress/php.ini-development`.\n\nThis is the default setting for `sendmail_path`:\n`sendmail_path = /usr/bin/env catchmail -f wordpress@local.test`\n\n### Possible issues with catchmail\n\n**/usr/bin/env: 'catchmail': No such file or directory**\n\nYou can try to change the setting to this ([source](https://wesamly.wordpress.com/2015/10/27/mailcatcher-error-env-catchmail-no-such-file-or-directory/)):\n`sendmail_path = /usr/bin/env /usr/local/bin/catchmail -f some@example.com`\n\nOr you can use mhsendmail as an alternative with this setting:\n`sendmail_path = /usr/local/bin/mhsendmail`\n\n[msendmail install instructions.](https://github.com/SalsaBoy990/docker-wordpress/issues/4#issuecomment-2016944122)\n\n\n## License, credits\n\nMIT License\nCopyright (c) 2021-2023 András Gulácsi\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebandras%2Fdocker-wordpress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebandras%2Fdocker-wordpress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebandras%2Fdocker-wordpress/lists"}