WordPress development tricks
Expanding on Moving a WordPress instance by hand, here’s my list of hacks and tricks necessary for managing local WordPress instances.
Send PHP development server (‘wp server’) logs to a separate file
- In php-cli’s
php.ini
(should be somewhere under/etc/php
), set:log_errors = On
error_log = /var/log/php_errors.log sudo chmod 777 /var/log/php_errors.log
(yeah, whatever)
Catch emails
- Install mailcatcher:
gem install mailcatcher
(requiresrubygems
package to be installed) - In php-cli’s
php.ini
, setsendmail_path = /usr/bin/env catchmail
- At the very bottom of
wp-config.php
, below where it loadswp-settings.php
, put:
if (defined('WP_CLI')) {
WP_CLI::add_wp_hook('wp_mail_from', function () {
return '[email protected]';
});
} else {
add_filter('wp_mail_from', function () {
return '[email protected]';
});
}
(otherwise WordPress will fail to send emails, saying “Invalid address: (From): wordpress@localhost”)
Use more workers for the PHP development server
This may make things faster, but it may also slow things down to a crawl. Give it a shot.
Simply append PHP_CLI_SERVER_WORKERS=N
before the wp server
command, like so:
PHP_CLI_SERVER_WORKERS=50 wp server
Kill and restart a hanging PHP development server
If you see pages infinitely loading, just CTRL-C
the development server and kill all its workers before trying to restart it by doing:
pkill -f 8080 # <-- Replace '8080' with whatever port you used
Disable Dark Reader
Both in Firefox and Chrome, something in the browser plugin Dark Reader’s logic triggers multiple background loads of the index, which really slows things down when using PHP’s development server.
Fix uploads not working even though file permissions are OK
This could be caused by the upload_path
setting in the wp_options
table. To fix, clear the field:
UPDATE wp_options SET option_value = '' WHERE option_name = 'upload_path';