@@ -34,6 +34,10 @@ class Server_Command extends WP_CLI_Command {
3434 * [--config=<file>]
3535 * : Configure the server with a specific .ini file.
3636 *
37+ * [<passthrough>...]
38+ * : Optional arguments to pass to the PHP binary. Any arguments after `--`
39+ * will be passed through to the `php` command.
40+ *
3741 * ## EXAMPLES
3842 *
3943 * # Make the instance available on any address (with port 8080)
@@ -57,6 +61,13 @@ class Server_Command extends WP_CLI_Command {
5761 * Document root is /
5862 * Press Ctrl-C to quit.
5963 *
64+ * # Pass extra parameters to the PHP binary
65+ * $ wp server --docroot=public -- -dzend_extension=xdebug.so
66+ * PHP 7.4.0 Development Server started at Wed Nov 10 18:00:00 2025
67+ * Listening on http://localhost:8080
68+ * Document root is /var/www/public
69+ * Press Ctrl-C to quit.
70+ *
6071 * @when before_wp_load
6172 */
6273 public function __invoke ( $ _ , $ assoc_args ) {
@@ -86,14 +97,27 @@ public function __invoke( $_, $assoc_args ) {
8697 if ( ! file_exists ( $ router_path ) ) {
8798 WP_CLI ::error ( "Couldn't find router.php " );
8899 }
89- $ cmd = Utils \esc_cmd (
90- '%s -S %s -t %s -c %s %s ' ,
91- WP_CLI ::get_php_binary (),
92- $ assoc_args ['host ' ] . ': ' . $ assoc_args ['port ' ],
93- $ docroot ,
94- $ assoc_args ['config ' ],
95- Utils \extract_from_phar ( $ router_path )
96- );
100+
101+ // Build the command with passthrough arguments
102+ $ cmd_format = '%s ' ;
103+ $ cmd_args = array ( WP_CLI ::get_php_binary () );
104+
105+ // Add passthrough arguments before the -S flag
106+ if ( ! empty ( $ _ ) ) {
107+ foreach ( $ _ as $ arg ) {
108+ $ cmd_format .= ' %s ' ;
109+ $ cmd_args [] = $ arg ;
110+ }
111+ }
112+
113+ // Add the server flags
114+ $ cmd_format .= ' -S %s -t %s -c %s %s ' ;
115+ $ cmd_args [] = $ assoc_args ['host ' ] . ': ' . $ assoc_args ['port ' ];
116+ $ cmd_args [] = $ docroot ;
117+ $ cmd_args [] = $ assoc_args ['config ' ];
118+ $ cmd_args [] = Utils \extract_from_phar ( $ router_path );
119+
120+ $ cmd = Utils \esc_cmd ( $ cmd_format , ...$ cmd_args );
97121
98122 $ descriptors = array ( STDIN , STDOUT , STDERR );
99123
0 commit comments