Skip to content

fix: Replace wp --allow-root with runuser for safer command execution#27

Merged
vitormattos merged 1 commit into
mainfrom
fix/wordpress-entrypoint-runuser
May 14, 2026
Merged

fix: Replace wp --allow-root with runuser for safer command execution#27
vitormattos merged 1 commit into
mainfrom
fix/wordpress-entrypoint-runuser

Conversation

@vitormattos
Copy link
Copy Markdown
Member

Description

This fix replaces all wp --allow-root calls with runuser -u www-data -- wp in the WordPress entrypoint script to execute WordPress CLI commands as the www-data user instead of root.

Problem

The container was failing with a loop error:

Error: YIKES! It looks like you're running this as root. You probably meant to run this as the user that your WordPress installation exists under.

The --allow-root flag was not reliably preventing this error on container startup.

Solution

Using runuser to execute commands as the www-data user is a more secure approach and avoids the wp-cli root execution rejection.

Changes

  • wordpress_is_installed(): Changed to use runuser
  • wp-config.php generation: Changed to use runuser
  • replace_url_occurrences(): Changed to use runuser
  • install_plugin(): Changed to use runuser
  • install_plugin_archive(): Changed to use runuser
  • finalize_custom_plugin(): Changed to use runuser

Testing

After merging:

  1. Rebuild the image: docker compose build --no-cache wordpress
  2. Start the stack: docker compose up -d
  3. Verify no root execution errors appear in container logs

Replace all 'wp --allow-root' calls with 'runuser -u www-data -- wp' to execute
WordPress CLI commands as the www-data user instead of root. This approach is
more secure and avoids the loop error that occurs when wp-cli rejects root
execution.

Affected functions:
- wordpress_is_installed()
- wp-config.php generation
- replace_url_occurrences()
- install_plugin()
- install_plugin_archive()
- finalize_custom_plugin()

This ensures the entrypoint script runs properly on container startup.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
@vitormattos vitormattos merged commit 7eb7021 into main May 14, 2026
2 checks passed
@vitormattos vitormattos deleted the fix/wordpress-entrypoint-runuser branch May 14, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant