A simple dev container template for WordPress plugin development.
- WP-CLI
- Composer
- Apache2
- Mock SMTP (Mailpit)
- PHP_CodeSniffer
- Ready to use NodeJS (NVM)
- Ready to use Playwright or Selenium (novnc)
- Xdebug
- phpinfo (http://localhost/phpinfo.php)
- adminer (http://localhost/adminer.php)
Important
Strongly recommend: if you use Linux, your uid should be 1000. Else docker may cause permission problems.
-
Install requirements:
- Visual Studio Code
- Dev Containers extension
- Docker environment (Linux PC is recommend)
Remote Development:
- Prepare Linux PC. Recommended RAM is 4GB or higher.
- Install requirements in your terminal PC:
- Configure server.
- Install docker.
- Setup Remote Tunnels or SSH (configure your router for forwarding ssh port).
- Setup WoL or remote power-on method, if you need.
- Connect to server.
- Recommended: Install Container Tools in server.
-
Create your project directory.
-
Open terminal and
cd /path/to/your-project. -
Clone this repository.
git clone https://github.com/chrono-meter/wp-plugin-devcontainer.git .devcontainer -
Create sub directories.
mkdir mysql wp-content -
Open your project directory in Visual Studio Code.
-
Edit wp-config-extra.php, devcontainer.json, docker-compose.yml, wordpress-base.Dockerfile or others as necessary.
-
Open dev container:
Ctrl+Shift+P(Command pallete) →Dev Containers: Open Folder in Container.... -
Check or open WordPress via forward port:
Ctrl+Shift+P(Command pallete) →Forward a Ports→WordPress (80)→ open link inForwarded Addresscolumn
-
Login into WordPress. Default username is
admin, password ispassword(If not set by environment variable).
To see emails that sent from WordPress, Ctrl+Shift+P (Command pallet) → Forward a Ports → Find forwarded 8025 port and open it in your browser.
See https://mailpit.axllent.org/.
To check emails in your test, use MailHog API v1 or MailHog API v2. There are NodeJS and PHP client libraries.
- WordPress Image
- devcontainer.json
devcontainerservice in .devcontainer/common.yml- docker-compose.yml
- Enter dev container console (shell):
Shift+EscorCtrl+Shift+@(new console) - Forward a Ports:
Ctrl+Shift+P(Command pallet) →Forward a Ports - Exit/Reopen/Rebuild dev container:
Ctrl+Shift+P(Command pallet) → typereopen
- Select and run task:
Shift+Alt+F10→ Select task - Run test:
Ctrl+Shift+P(Command pallet) →Tasks: Run Test Task - Run build tasks:
Ctrl+F9 - Find your favorite key bindings.
- Reload apache (if you don't want to restart dev container): Run
/etc/init.d/apache2 reloadin dev container's console
- Bookmark
javascript:(function() {document.cookie='XDEBUG_TRIGGER='+'VSCODE'+';path=/;';document.location.reload();setTimeout(function() {document.cookie='XDEBUG_TRIGGER='+''+';expires=Mon, 05 Jul 2000 00:00:00 GMT;path=/;';}, 100);})() - Set breakpoint.
- Start Xdebug:
Shift+Alt+F9orRun and Debugin Left sidebar →Listen for Xdebug - Open WordPress page that you want to debug.
- Open bookmarked JavaScript.
Do you get frustrated when your breakpoints don't work in Xdebug? First, calm down, before you waste your precious time.
- Install browser extension, then enable on your site.
- Unfortunately, the breakpoint that you set will be never reached on your request or execute condition. Set new breakpoint on prior line or upper function calling.
- Do
ping `php -r 'echo ini_get("xdebug.client_host");'`to check Xdebug client is reachable. - Finally, try to call
\xdebug_break();on the breakpoint. If this method doesn't work then your Xdebug configuration is broken.
I can't access http://localhost or https://localhost.
Please check if another vscode or devcontainer is occupying the port 80/443.
Add option --defaults for avoid wp db commands add --no-defaults option.
NOTE: This devcontainer adds ssl-verify-server-cert=FALSE into /etc/mysql/conf.d/ignore-ssl.cnf.
User Role Editor activation failure via wp-cli installation.
There are lacking caps:
- ure_create_roles
- ure_delete_roles
- ure_create_capabilities
- ure_delete_capabilities
- ure_manage_options # URE_KEY_CAPABILITY
- ure_reset_roles
So, we need to activate it manually:
wp plugin install --activate user-role-editor
wp eval 'do_action("activate_user-role-editor/user-role-editor.php");'