Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp-env: Edit PHP configuration with htaccess from .wp-env.json. #32363

Closed
wants to merge 3 commits into from
Closed
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
24 changes: 24 additions & 0 deletions packages/env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/env/lib/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions packages/env/lib/config/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions packages/env/lib/config/test/__snapshots__/config.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Object {
},
"coreSource": null,
"mappings": Object {},
"phpConfig": Object {},
"phpVersion": null,
"pluginSources": Array [],
"port": 2000,
Expand All @@ -46,6 +47,7 @@ Object {
},
"coreSource": null,
"mappings": Object {},
"phpConfig": Object {},
"phpVersion": null,
"pluginSources": Array [],
"port": 1000,
Expand Down
6 changes: 6 additions & 0 deletions packages/env/lib/config/validate-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 11 additions & 0 deletions packages/env/lib/wordpress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down