diff --git a/packages/env/README.md b/packages/env/README.md index c10bbdcf62dcbd..97afe66a561a93 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. diff --git a/packages/env/lib/config/config.js b/packages/env/lib/config/config.js index 401077c495f30d..42a7bc4ef44091 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 a0877fcb059451..17bbc2d296b270 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/test/__snapshots__/config.js.snap b/packages/env/lib/config/test/__snapshots__/config.js.snap index 230796119d6e19..51a2fb04102a72 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, diff --git a/packages/env/lib/config/validate-config.js b/packages/env/lib/config/validate-config.js index c3aa849e6322d1..4ddf8e9a4f865b 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 0cbd70c4ab22b9..c00bc13e199622 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(