Add configuration options for Apache & PHP in Local app

There are 3 issues present in the default Apache and PHP 8 configuration on Windows.

  1. 500 Error when trying to upload files (plugins, media, etc)
  2. Temp folder missing/not configured
  3. (minor) Xdebug entries filling up php\error.log

All 3 of these could be resolved with changes to the default setup along with providing user configuration through the Local app.

Issue 1: 500 Error

The apache\site-error.log contains entries like the following:

[Thu Aug 18 20:30:45.242297 2022] [fcgid:warn] [pid 27196:tid 1240] [client 127.0.0.1:63542] mod_fcgid: read timeout from pipe, referer: SITE_ADDRESS/wp-admin/
[Thu Aug 18 20:30:45.243267 2022] [core:error] [pid 27196:tid 1240] [client 127.0.0.1:63542] End of script output before headers: admin-ajax.php, referer: SITE_ADDRESS/wp-admin/
[Thu Aug 18 20:33:46.742199 2022] [fcgid:warn] [pid 27196:tid 1240] [client 127.0.0.1:65462] mod_fcgid: HTTP request length 134700 (so far) exceeds MaxRequestLen (131072), referer: SITE_ADDRESS/wp-admin/plugin-install.php

As you can see, the default configuration only allows a 128KB upload. This is insufficient for Wordpress admin due to the size of Plugins, Themes, and the like. Additionally, many media files exceed that size.

Issue 2: Temp folder

When an upload does succeed, it gives an error on the page about the temp folder. This is because it’s not configured within PHP.

[19-Aug-2022 00:49:10 UTC] PHP Warning:  File upload error - unable to create a temporary file in Unknown on line 0

Issue 3: Xdebug logging

By default, PHP is configured to load Xdebug with the mode set to debug. This is a nuisance if we have no interest in debugging. In my case, my local site is being used for configuration and design purposes before using it on a live site. I don’t have a need for debugging, profiling, tracing, etc. Instead, it just continuously floods the log with entries such as the following.

[19-Aug-2022 00:26:28 UTC] Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9000 (fallback through xdebug.client_host/xdebug.client_port) :-(
[19-Aug-2022 00:26:30 UTC] Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: 127.0.0.1:9000 (from HTTP_X_FORWARDED_FOR HTTP header), localhost:9000 (fallback through xdebug.client_host/xdebug.client_port) :-(
[19-Aug-2022 00:26:31 UTC] Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: 127.0.0.1:9000 (from HTTP_X_FORWARDED_FOR HTTP header), localhost:9000 (fallback through xdebug.client_host/xdebug.client_port) :-(
[19-Aug-2022 00:26:31 UTC] Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9000 (fallback through xdebug.client_host/xdebug.client_port) :-(
...
[19-Aug-2022 00:29:12 UTC] Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: ::1:9000 (from HTTP_X_FORWARDED_FOR HTTP header), localhost:9000 (fallback through xdebug.client_host/xdebug.client_port) :-(

This resulted in the PHP entries being hidden hundreds of lines in, such as the Warning in Issue 2 as well as important ones such as the Fatal error and stack trace that was caused by Wordpress.

[19-Aug-2022 00:55:40 UTC] PHP Fatal error:  Uncaught ArgumentCountError: 3 arguments are required, 2 given in D:\Local-Sites\sitename\app\public\wp-admin\includes\class-bulk-upgrader-skin.php:156

Resolutions

  1. Edit (SITE_FOLDER)\conf\php\php.ini.hbs
    a. In the if os.windows section, add values for sys_temp_dir and upload_temp_dir. Example:
    local-php-ini-1
    b. Add/edit the value for upload_max_size. Optionally, adjust the post_max_size as well.
  2. Edit (SITE_FOLDER)\conf\apache\modules.conf.hbs and add/edit the following. The value is bytes. It should be equal to or lesser than the upload_max_size from php.ini. I added it to the end of my config.
<IfModule mod_fcgid.c>
    FcgidMaxRequestLen 51200000
</IfModule>
  1. (optional) Configure Xdebug in (SITE_FOLDER)\conf\php\php.ini.hbs
    a. If it’s not wanted at all, comment out the entire section (prefix with a semicolon - ;)
    b. If it should just be silenced with close to 0 overhead, turn it off with xdebug.mode=off
    c. If it’s wanted, but the log keeps giving Time-out errors, change the port number to match your site. You can also change the mode to any valid value as listed in the Official Documentation
    local-php-ini-2
  2. Restart the site.

Recommendations

There needs to be a way, or multiple ways, to configure these values that are a problem from the start. All of them were missing for me (except for the Xdebug section), so I assume they all need to be added. It would be preferable if all were implemented, but being able to change it at the site level would be sufficient.

  1. Change the default Apache and PHP configurations during the install/deploy process before starting the site.
    • php.ini.bs
      • sys_temp_dir and upload_temp_dir - Set to the system temp folder.
      • upload_max_size should be set to a reasonable value, or set it to match post_max_size.
      • Default Xdebug to xdebug.mode=off.
      • Set xdebug.port to match the deployed site’s value – the same one found in route.SITE_DOMAIN.conf
    • apache\modules.conf.hbs
      • Add the <IfModule mod_fcgid.c> block and set FcgidMaxRequestLen to the same or lesser value of upload_max_size in php.ini.hbs, but represented in bytes. Official Documentation
  2. Provide the option to set the values (paths and sizes) in the “New Site Defaults” in Preferences.
    local-site-defaults
  3. Provide the option to re-configure at the site level. A new tab or section can be added as shown. If changes are made and saved, inform the user to restart the site.
  4. Add a way to open the config files directly in Notepad (or whatever the system text editor is) similar to the “Go to site folder” link. If you want to go extra, add an option in “Preferences” to select an editor. For instance, I use Notepad++ instead of regular Notepad.
    • The options can be links, or a dropdown can be added for “Configuration” with “php.ini.bs”, “modules.conf.hbs”, etc. as options.
    • It can be in the application menu similar to the “Reveal…” options and use the currently selected site to determine which one to open. Disable the menu options if one isn’t selected (no local sites, not on the “Local sites” screen).

I see that recent releases have incorporated some changes that are related to this request. Still, they are defaults in the configuration and can’t be modified through the UI:

Local 6.5.2 (Nov 15)
Xdebug’s mode is now set to “debug, develop” to enable more complete stack traces on errors.

This is related to Issue #3. In my case, it still would be a problem. I know that Flywheel’s target audience is WP developers as I found in the requests, but even they may want to disable the verbose output when not making code changes. I occasionally work on plug-ins, so the output can sometimes be useful for me as well, but I don’t want it by default, and it would be nice if we can change it on-the-fly through the site configuration instead of opening the config file and manually changing it.

Local 6.5.1 (Nov 1)
Resolved an issue that prevented users from uploading media to their site when using Apache on Windows.

I assume this addresses the main issues in this request. I haven’t made a new instance to check. Still, if configuration in the UI still isn’t available, it would be nice to have.

1 Like