From f01c2f1ea89e271359cba7dc4ef19f9efd1c7769 Mon Sep 17 00:00:00 2001 From: Hiroshi Urabe Date: Tue, 1 Jun 2021 17:52:56 +0900 Subject: [PATCH 1/3] Write the value of phpConfig in .htaccess. --- packages/env/lib/config/config.js | 1 + packages/env/lib/config/parse-config.js | 1 + packages/env/lib/config/validate-config.js | 6 ++++++ packages/env/lib/wordpress.js | 11 +++++++++++ 4 files changed, 19 insertions(+) diff --git a/packages/env/lib/config/config.js b/packages/env/lib/config/config.js index 401077c495f30..42a7bc4ef4409 100644 --- a/packages/env/lib/config/config.js +++ b/packages/env/lib/config/config.js @@ -86,6 +86,7 @@ module.exports = async function readConfig( configPath ) { WP_SITEURL: 'http://localhost', WP_HOME: 'http://localhost', }, + phpConfig: {}, env: { development: {}, // No overrides needed, but it should exist. tests: { diff --git a/packages/env/lib/config/parse-config.js b/packages/env/lib/config/parse-config.js index a0877fcb05945..17bbc2d296b27 100644 --- a/packages/env/lib/config/parse-config.js +++ b/packages/env/lib/config/parse-config.js @@ -47,6 +47,7 @@ module.exports = function parseConfig( config, options ) { parseSourceString( sourceString, options ) ), config: config.config, + phpConfig: config.phpConfig, mappings: Object.entries( config.mappings ).reduce( ( result, [ wpDir, localDir ] ) => { const source = parseSourceString( localDir, options ); diff --git a/packages/env/lib/config/validate-config.js b/packages/env/lib/config/validate-config.js index c3aa849e6322d..4ddf8e9a4f865 100644 --- a/packages/env/lib/config/validate-config.js +++ b/packages/env/lib/config/validate-config.js @@ -83,6 +83,12 @@ function validateConfig( config, envLocation ) { ); } + if ( typeof config.phpConfig !== 'object' ) { + throw new ValidationError( + 'Invalid .wp-env.json: "phpConfig" must be an object.' + ); + } + return config; } diff --git a/packages/env/lib/wordpress.js b/packages/env/lib/wordpress.js index 0cbd70c4ab22b..c00bc13e19962 100644 --- a/packages/env/lib/wordpress.js +++ b/packages/env/lib/wordpress.js @@ -64,6 +64,17 @@ async function configureWordPress( environment, config, spinner ) { for ( const pluginSource of config.env[ environment ].pluginSources ) { setupCommands.push( `wp plugin activate ${ pluginSource.basename }` ); } + const phpConfig = Object.entries( config.env[ environment ].phpConfig ) + .map( ( [ key, value ] ) => { + const phpConfigValue = + typeof value === 'string' ? `"${ value }"` : value; + return `php_value ${ key } ${ phpConfigValue }`; + } ) + .join( '\n' ); + + setupCommands.push( + `wp eval "insert_with_markers( get_home_path().'.htaccess', 'wp-env', '${ phpConfig }' );"` + ); if ( config.debug ) { spinner.info( From ec25721dbeba15148d7b9cdcba41d910596a1003 Mon Sep 17 00:00:00 2001 From: Hiroshi Urabe Date: Tue, 1 Jun 2021 18:50:36 +0900 Subject: [PATCH 2/3] update snapshot --- packages/env/lib/config/test/__snapshots__/config.js.snap | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/env/lib/config/test/__snapshots__/config.js.snap b/packages/env/lib/config/test/__snapshots__/config.js.snap index 230796119d6e1..51a2fb04102a7 100644 --- a/packages/env/lib/config/test/__snapshots__/config.js.snap +++ b/packages/env/lib/config/test/__snapshots__/config.js.snap @@ -23,6 +23,7 @@ Object { }, "coreSource": null, "mappings": Object {}, + "phpConfig": Object {}, "phpVersion": null, "pluginSources": Array [], "port": 2000, @@ -46,6 +47,7 @@ Object { }, "coreSource": null, "mappings": Object {}, + "phpConfig": Object {}, "phpVersion": null, "pluginSources": Array [], "port": 1000, From f0e97af9ef605a14ab14bba4147ec3a9052ab8b1 Mon Sep 17 00:00:00 2001 From: Hiroshi Urabe Date: Wed, 2 Jun 2021 17:50:45 +0900 Subject: [PATCH 3/3] update documentation. --- packages/env/README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/env/README.md b/packages/env/README.md index c10bbdcf62dcb..97afe66a561a9 100644 --- a/packages/env/README.md +++ b/packages/env/README.md @@ -392,6 +392,7 @@ You can customize the WordPress installation, plugins and themes that the develo | `"port"` | `integer` | `8888` (`8889` for the tests instance) | The primary port number to use for the installation. You'll access the instance through the port: 'http://localhost:8888'. | | `"config"` | `Object` | See below. | Mapping of wp-config.php constants to their desired values. | | `"mappings"` | `Object` | `"{}"` | Mapping of WordPress directories to local directories to be mounted in the WordPress instance. | +| `"phpConfig"` | `Object` | `"{}"` | PHP configuration directives. _Note: the port number environment variables (`WP_ENV_PORT` and `WP_ENV_TESTS_PORT`) take precedent over the .wp-env.json values._ @@ -548,6 +549,29 @@ If you need a plugin active in one environment but not the other, you can use `e } ``` +#### Custom PHP Configuration. + +You can customize the configuration of PHP via `phpConfig`. + +```json +{ + "phpConfig": { + "memory_limit": "512M", + "post_max_size": "512M", + "upload_max_filesize": "512M" + } +} +``` + +The settings will be added to `.htaccess`. + +```apacheconf +php_value memory_limit 512M +php_value post_max_size 512M +php_value upload_max_filesize 512M +``` + + #### Custom Port Numbers You can tell `wp-env` to use a custom port number so that your instance does not conflict with other `wp-env` instances.