Fix incorrect home/siteurl when WP-CLI runs from root filesystem#307
Draft
Fix incorrect home/siteurl when WP-CLI runs from root filesystem#307
Conversation
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix incorrect home and siteurl in core install command
Fix incorrect home/siteurl when WP-CLI runs from root filesystem
Feb 4, 2026
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes malformed home/siteurl values during wp core install when WP-CLI is executed from the filesystem root by ensuring WordPress’s URL guessing logic sees server paths that reflect the --url value.
Changes:
- Override
$_SERVER['PHP_SELF']/$_SERVER['SCRIPT_NAME'](and conditionally$_SERVER['SCRIPT_FILENAME']) during installation based on the parsed--urlpath. - Normalize URL paths to an
index.php-style script path for WordPress’s install-time URL detection. - Add Behat coverage for installs with
--urlvalues with and without a path component.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/Core_Command.php |
Adjusts server superglobals during install so WP’s wp_guess_url() derives the correct base URL. |
features/core-install.feature |
Adds scenarios asserting home/siteurl values for URLs with and without a path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix "core install" URL when wp-cli is executed from root filesystem
Resolves the issue where
wp core installdefines incorrect home and siteurl values when WP-CLI is executed from the root of the filesystem.Problem
When WP-CLI phar is located at the root of the filesystem (e.g.,
/wp) and WordPress is installed at a different path (e.g.,/home/customer/website), thewp core installcommand sets incorrecthomeandsiteurlvalues. Instead of using the URL provided via the--urlparameter (e.g.,https://website.domain.tld), it produces malformed URLs likehttps://website.domain.tldhome/customer/website.Root Cause
WordPress's internal URL detection functions (like
wp_guess_url()) use$_SERVER['PHP_SELF']and$_SERVER['SCRIPT_NAME']to determine the script path. When WP-CLI is executed from/wp, these variables contain/wp(the path to the WP-CLI phar) rather than the WordPress installation path, which causes incorrect URL construction duringwp_install().Solution
Before calling
wp_install(), the fix sets$_SERVER['PHP_SELF'],$_SERVER['SCRIPT_NAME'], and$_SERVER['SCRIPT_FILENAME']to match the URL path provided via the--urlparameter instead of the WP-CLI executable location.Changes
do_install()method inCore_Command.phpto set proper$_SERVERvariablespathinfo()for secure file extension detectionUtils\trailingslashit()for safe path constructiondefined('ABSPATH')check--requirefileTesting
example.com) and with paths (example.com/subdir)--requireto set problematic$_SERVERvalueswp core multisite-install(which callsdo_install())Security
pathinfo()instead of string matching for robust file extension detectionUtils\trailingslashit()for safe path construction to prevent path traversal issuesOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.