Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions features/server.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ Feature: Serve WordPress locally
When I run `curl -sS localhost:8181/license.txt > /tmp/license.txt`
And I run `cmp /tmp/license.txt license.txt`
Then STDOUT should be empty

Scenario: Passthrough arguments to PHP binary
Given a WP install
And I launch in the background `wp server --host=localhost --port=8182 -- -dmemory_limit=256M`

When I run `curl -sS localhost:8182/wp-admin/install.php`
Then the return code should be 0
45 changes: 36 additions & 9 deletions src/Server_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class Server_Command extends WP_CLI_Command {
* [--config=<file>]
* : Configure the server with a specific .ini file.
*
* [<passthrough>...]
* : Optional arguments to pass to the PHP binary. Any arguments after `--`
* will be passed through to the `php` command.
*
* ## EXAMPLES
*
* # Make the instance available on any address (with port 8080)
Expand All @@ -57,9 +61,16 @@ class Server_Command extends WP_CLI_Command {
* Document root is /
* Press Ctrl-C to quit.
*
* # Pass extra parameters to the PHP binary
* $ wp server --docroot=public -- -dzend_extension=xdebug.so
* PHP 7.4.0 Development Server started at Wed Nov 10 18:00:00 2025
* Listening on http://localhost:8080
* Document root is /var/www/public
* Press Ctrl-C to quit.
*
* @when before_wp_load
*/
public function __invoke( $_, $assoc_args ) {
public function __invoke( $args, $assoc_args ) {
$defaults = array(
'host' => 'localhost',
'port' => 8080,
Expand All @@ -86,14 +97,30 @@ public function __invoke( $_, $assoc_args ) {
if ( ! file_exists( $router_path ) ) {
WP_CLI::error( "Couldn't find router.php" );
}
$cmd = Utils\esc_cmd(
'%s -S %s -t %s -c %s %s',
WP_CLI::get_php_binary(),
$assoc_args['host'] . ':' . $assoc_args['port'],
$docroot,
$assoc_args['config'],
Utils\extract_from_phar( $router_path )
);

// Build the command with passthrough arguments
$cmd_format = '%s';
$cmd_args = array( WP_CLI::get_php_binary() );

// Add passthrough arguments before the -S flag
if ( ! empty( $args ) ) {
foreach ( $args as $arg ) {
if ( '--' === $arg ) {
continue;
}
$cmd_format .= ' %s';
$cmd_args[] = $arg;
}
}

// Add the server flags
$cmd_format .= ' -S %s -t %s -c %s %s';
$cmd_args[] = $assoc_args['host'] . ':' . $assoc_args['port'];
$cmd_args[] = $docroot;
$cmd_args[] = $assoc_args['config'];
$cmd_args[] = Utils\extract_from_phar( $router_path );

$cmd = Utils\esc_cmd( $cmd_format, ...$cmd_args );

$descriptors = array( STDIN, STDOUT, STDERR );

Expand Down
Loading