Skip to content

Conversation

Copy link

Copilot AI commented Feb 2, 2026

Running wp config create enters an infinite loop when WordPress cannot be loaded (e.g., mysql unavailable or DB authentication fails), repeatedly displaying "Error: 'wp-config.php' not found."

Root Cause

The create() method lacks the @when before_wp_load annotation. Without it, WP-CLI attempts to bootstrap WordPress before executing the command, which requires the wp-config.php file that doesn't exist yet.

Changes

  • Added @when before_wp_load annotation to Config_Command::create()

This aligns with all other methods in the class (edit, path, list, get, set, delete, has, shuffle-salts), which already have this annotation.

/**
 * Generates a wp-config.php file.
 * ...
 * @when before_wp_load
 */
public function create( $_, $assoc_args ) {
Original prompt

This section details on the original issue you should resolve

<issue_title>Infinite loop... Error: 'wp-config.php' not found. Infinite loop... </issue_title>
<issue_description>## Bug Report

Describe the current, buggy behavior

I have written a bash script to quickly install and setup wordpress on my AlmaLinux 8.7 server.

When the mysql command is missing (by accident or by choice, when the DB is remote and not local), then executing wp-cli causes it to enter an infinite loop! I managed to replicate the same infinite loop even if the mysql is installed, but the remote DB can't be accessed due to authentication error.

Here is how I call wp-cli from my bash script:

wp config create					\
	--path="${WPPATH}"				\
	--locale="${WPLOCALE}"				\
	--dbname="${WPDBNAME}"				\
	--dbhost="${WPDBHOST}"				\
	--dbcharset=utf8mb4				\
	--dbcollate=utf8mb4_unicode_ci			\
	--dbuser="${WPDBUSER}"				\
	--dbpass="${WPDBPASS}"				\
	--extra-php <<PHP

${STAGEVARS}

PHP

The console output looks like:

$ ./install-script.sh 
Downloading WordPress 6.1.1 (en)...
Using cached file '/home/user/.wp-cli/cache/core/wordpress-6.1.1.tar.gz'...
Success: WordPress downloaded.
/usr/bin/env: ‘mysql’: No such file or directory
Error: 'wp-config.php' not found.
Either create one manually or use `wp config create`.
Error: 'wp-config.php' not found.
Either create one manually or use `wp config create`.
Error: 'wp-config.php' not found.
Either create one manually or use `wp config create`.
Error: 'wp-config.php' not found.
Either create one manually or use `wp config create`.
Error: 'wp-config.php' not found.
Either create one manually or use `wp config create`.
Error: 'wp-config.php' not found.
Either create one manually or use `wp config create`.
Error: 'wp-config.php' not found.
Either create one manually or use `wp config create`.
Error: 'wp-config.php' not found.
Either create one manually or use `wp config create`.
Error: 'wp-config.php' not found.
Either create one manually or use `wp config create`.
Error: 'wp-config.php' not found.
Either create one manually or use `wp config create`.
Error: 'wp-config.php' not found.
Either create one manually or use `wp config create`.
Error: 'wp-config.php' not found.
(... to infinity and beyond ...)

Describe how other contributors can replicate this bug

  • Install a minimal AlmaLinux 8.7 system
  • Install PHP 8.0 packages
  • Create a user (useradd -m user)
  • Give shell access to the new user (usermod -s /bin/bash user)
  • Switch to the new user (su - user)
  • As the new user, download and install wp-cli under ~/bin
  • run wp-cli config create as above
  • watch it loop

Describe what you would expect as the correct outcome

No infinite loop! Maybe stop the config procedure with an error, or proceed and use an alternative to the mysql command.

Let us know what environment you are running this on

$ wp cli info
OS:	Linux 4.18.0-425.3.1.el8.x86_64 wp-cli/config-command#1 SMP Tue Nov 8 14:08:25 CST 2022 x86_64
Shell:	/bin/bash
PHP binary:	/usr/bin/php
PHP version:	8.0.20
php.ini used:	/etc/php-cli.ini
MySQL binary:	
MySQL version:	
SQL modes:	
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/home/user/bin
WP-CLI packages dir:	
WP-CLI cache dir:	/home/user/.wp-cli/cache
WP-CLI global config:	
WP-CLI project config:	
WP-CLI version:	2.7.1

$ which -a wp
~/bin/wp

$ stat $(which wp)
  File: /home/user/bin/wp
  Size: 6729511   	Blocks: 13144      IO Block: 4096   regular file
Device: fd00h/64768d	Inode: 8585464     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: ( 1001/user)   Gid: ( 1001/user)
Access: 2022-12-09 13:59:29.395412168 +0000
Modify: 2022-12-09 13:59:12.445309729 +0000
Change: 2022-12-09 13:59:23.846378617 +0000
 Birth: 2022-12-09 13:59:11.708305270 +0000

$ wp package list
+------+---------+---------+--------+----------------+
| name | authors | version | update | update_version |
+------+---------+---------+--------+----------------+
+------+---------+---------+--------+----------------+

Provide additional context/Screenshots

Not applicable.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber Thanks for the report, @LauraTaylorUK !

Feel free to submit a pull request, if you'd like.</comment_new>
<comment_new>@
Nobody cares, closing.</comment_new>
<comment_new>@danielbachhuber
@LauraTaylorUK I think this is still worth fixing...


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix infinite loop in wp-cli execution Fix infinite loop in wp config create by adding @when before_wp_load annotation Feb 2, 2026
Copilot AI requested a review from swissspidy February 2, 2026 17:37
@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite loop... Error: 'wp-config.php' not found. Infinite loop...

2 participants