This guide will help you set up a local development environment for the ActivityPub WordPress plugin. You'll learn how to clone the repository, install dependencies, and run a local WordPress instance for development and testing.
-
Node.js (v18 or later)
node --version # Check version -
npm (comes with Node.js)
npm --version # Check version -
Docker Desktop
- Download Docker Desktop
- Ensure Docker is running before using npm run env commands
-
Composer (for PHP dependencies)
# Install via Homebrew (macOS) brew install composer # Or download directly curl -sS https://getcomposer.org/installer | php
-
Git with SSH key setup
- We recommend setting up a public SSH key with GitHub for more secure authentication.
- See GitHub's SSH key guide
# Check SSH key ssh -T git@github.com
Fork the repository to your own GitHub account and clone it to your local machine:
git clone git@github.com:YOUR-USERNAME/wordpress-activitypub.git
cd wordpress-activitypub-
Install JavaScript dependencies:
npm install
-
Install PHP dependencies:
composer install
Note: npm install automatically runs npm run prepare, which sets up pre-commit hooks in .githooks/pre-commit. These hooks automatically format code and check standards before commits.
Start the local WordPress environment using wp-env:
npm run env-startThis will start a local WordPress environment with the ActivityPub plugin installed and activated.
Once the environment is running:
- Frontend: http://localhost:8888
- Admin: http://localhost:8888/wp-admin
- Username:
admin - Password:
password
When you're done developing:
npm run env-stopwp-env uses .wp-env.json for configuration. The default setup includes:
{
"phpVersion": "8.0",
"plugins": [ "." ],
"config": {
"WP_DEBUG": true,
"WP_DEBUG_LOG": true,
"WP_DEBUG_DISPLAY": true,
"SCRIPT_DEBUG": true
}
}Available npm scripts:
npm run env-start→ Start environmentnpm run env-stop→ Stop environmentnpm run env-test→ Run PHPUnit testsnpm run env -- <command>→ Pass any wp-env command
# Start environment
npm run env-start
# Stop environment
npm run env-stop
# Restart environment
npm run env-stop
npm run env-start
# Run PHPUnit tests
npm run env-test
# Run WP-CLI commands
npm run env -- run cli wp user list
npm run env -- run cli wp plugin list
# Access MySQL
npm run env -- run cli wp db cli
# View logs
npm run env -- logsUse npm run env -- to pass any wp-env command and its parameters:
# Run WP-CLI with additional arguments
npm run env -- run cli wp user create testuser test@example.com --role=editor
# View logs with follow flag
npm run env -- logs --follow
# Any wp-env command can be passed through
npm run env -- <wp-env-command> [options]Test with different WordPress versions by updating .wp-env.json:
{
"core": "WordPress/WordPress#6.4"
}Change PHP version in .wp-env.json:
{
"phpVersion": "7.4"
}# List running containers
docker ps
# View container logs
docker logs $(docker ps -q --filter name=wordpress)
# Access container shell
docker exec -it $(docker ps -q --filter name=wordpress) bash# Check Docker resource usage
docker system df
# Clean up unused resources
docker system prune -aDefault ports:
- WordPress: 8888
- MySQL: (mapped to random external port)
Change ports in .wp-env.json:
{
"port": 8080,
"testsPort": 8081
}You can run the test suite using either npm or composer:
# Using npm
npm run env-start
npm run env-test
# Using composer
wp-env start
composer run test:wp-envBoth commands support additional PHPUnit arguments. Add them after --:
# Run a specific test
npm run env-test -- --filter=test_migrate_to_4_1_0
# Run tests in a specific file
npm run env-test -- tests/phpunit/tests/includes/class-test-migration.php
# Run tests with a specific group
npm run env-test -- --group=migration
# Run tests with verbose output
npm run env-test -- --verbose
# The same works with composer
composer run test:wp-env -- --filter=test_migrate_to_4_1_0Common PHPUnit arguments:
--filter- Run tests matching a pattern--group- Run tests with a specific @group annotation--exclude-group- Exclude tests with a specific @group annotation--verbose- Output more verbose information--debug- Display debugging information
For comprehensive testing guidance, see Testing Reference.
The coverage configuration is already set up in phpunit.xml.dist to analyze the code in the includes directory. To generate code coverage reports, you'll need to start wp-env with Xdebug enabled for coverage:
# Start the environment with Xdebug enabled
npm run env-start -- --xdebug=coverage# Run tests with code coverage
npm run env-test -- --coverage-textThe above will display a text-based coverage report in your terminal. For a more detailed HTML report:
# Generate HTML coverage report in Docker
npm run env-test -- --coverage-html ./coverage# Open the coverage report in your default browser (macOS)
open coverage/index.htmlThe HTML report will be generated directly in the coverage directory in your local filesystem. The index.html file can then be opened in a browser, showing a detailed analysis of which lines of code are covered by tests.
Error: "Docker is not running"
Solution:
# Start Docker Desktop application
open -a Docker # macOS
# Wait for Docker to start, then retry
npm run env-startError: "Port 8888 is already in use"
Solution:
# Find process using port
lsof -i :8888 # macOS/Linux
# Kill the process
kill -9 <PID>
# Or use different port
npm run env-start -- --port=8889Error: "Permission denied" errors
Solution:
# Ensure Docker has permissions
sudo usermod -aG docker $USER # Linux
# Restart terminal and retryIssue: wp-env runs slowly
Solutions:
-
Increase Docker resources:
- Docker Desktop → Preferences → Resources
- Increase CPUs and Memory
-
Use mutagen for file sync (macOS):
brew install mutagen-io/mutagen/mutagen
-
Exclude node_modules from sync
Error: "Error establishing database connection"
Solution:
# Restart containers
npm run env-stop
npm run env-startIssue: ActivityPub plugin not active
Solution:
# Manually activate
npm run env -- run cli wp plugin activate activitypub
# Check activation
npm run env -- run cli wp plugin list --status=active# Set debug environment variable
DEBUG=wp-env:* npm run env-startCreate wp-config.php additions in .wp-env.json:
{
"config": {
"WP_DEBUG": true,
"WP_DEBUG_LOG": true,
"WP_DEBUG_DISPLAY": false,
"SCRIPT_DEBUG": true,
"WP_ENVIRONMENT_TYPE": "local",
"WP_MEMORY_LIMIT": "256M"
}
}{
"mappings": {
"wp-content/mu-plugins": "./mu-plugins",
"wp-content/themes/custom": "./custom-theme"
}
}Run multiple instances:
# Start on different ports
WP_ENV_PORT=8888 npm run env-start # Instance 1
WP_ENV_PORT=9999 npm run env-start # Instance 2For better performance on macOS:
-
Use Docker Desktop's VirtioFS:
- Docker Desktop → Settings → General
- Enable "Use the new Virtualization framework"
- Enable "VirtioFS accelerated directory sharing"
-
Limit watched files:
{ "excludePaths": [ "node_modules", "vendor", ".git" ] }
# Optimize database tables
npm run env -- run cli wp db optimize
# Clear transients
npm run env -- run cli wp transient delete --allWP_ENV_HOME- wp-env home directoryWP_ENV_PORT- WordPress portWP_ENV_TESTS_PORT- Tests portWP_ENV_LIFECYCLE_SCRIPT- Lifecycle script path
Create .env.local for custom variables:
# .env.local
AP_TEST_TIMEOUT=10000
AP_DEBUG_MODE=trueLoad in tests:
if ( file_exists( '.env.local' ) ) {
$dotenv = Dotenv\Dotenv::createImmutable( __DIR__ );
$dotenv->load();
}Once your environment is set up:
- Review the Testing Reference for testing guidance
- Check out Code Linting and Quality for code standards
- Read CONTRIBUTING.md for contribution guidelines