Challenge: WP CLI and PHP Composer is displaying PHP extension errors
Solution: adjust php.ini settings for display_startup_errors
The XAMPP server or localwp by freewheel are often used by developers to set up a PHP project locally. Running shell commands is often a necessity (WP CLI command line or PHP Composer). LocalWP offering “Open Site Shell” where commands can be executed.
Depending on the selected PHP version (5.6.39, 7.3.5, 7.4.1 or 8.00), some PHP startup warnings can appear in the console. This can be frustrating because pipe linux commands use standard output and a warning can interfere with command execution.
We have a site set up on localhost, our server is NGINX with PHP 7.4.1 enabled. Our environment is Windows with localWP application running in the background. How to fix PHP warnings when executing console commands? You will find a solution in this article.
Missing PHP extensions or issues with loading them are common error messages. “The specified module could not be found” for php_imagick.dll is a popular one. You might see other warnings similar to those:
Warning: PHP Startup: Unable to load dynamic library 'php_imagick.dll' (tried: C:/Program Files (x86)/Localwp/resources/extraResources/lightning-services/php-7.4.1+18/bin/win64/ext\php_imagick.dll (The specified module could not be found.), C:/Program Files (x86)/Localwp/resources/extraResources/lightning-services/php-7.4.1+18/bin/win64/ext\php_php_imagick.dll.dll (The specified module could not be found.)) in Unknown on line 0 Warning: PHP Startup: Unable to load dynamic library 'php_pdo_mysql.dll' (tried: C:/Users/user1/AppData/Roaming/Local/lightning-services/php-8.0.0+3/bin/win64/ext\php_pdo_mysql.dll (The specified module could not be found.), C:/Users/user1/AppData/Roaming/Local/lightning-services/php-8.0.0+3/bin/win64/ext\php_php_pdo_mysql.dll.dll (The specified module could not be found.)) in Unknown on line 0 Warning: PHP Startup: Unable to load dynamic library 'php_mysqli.dll' (tried: C:/Users/user1/AppData/Roaming/Local/lightning-services/php-7.3.5+11/bin/win64/ext\php_mysqli.dll (The specified procedure could not be found.), C:/Users/user1/AppData/Roaming/Local/lightning-services/php-7.3.5+11/bin/win64/ext\php_php_mysqli.dll.dll (The specified module could not be found.)) in Unknown on line 0
First, we need to determine where our PHP settings (php.ini) are stored. This command will return the location of the config file:
$ php --ini
Here is the output:
Configuration File (php.ini) Path: C:\WINDOWS Loaded Configuration File: C:\Users\user1\AppData\Roaming\Local\run\N4vHnB5kB\conf\php\php.ini Scan for additional .ini files in: (none) Additional .ini files parsed: (none)
Now, what is left is editing the php.ini file (in our situation, it is located on: C:\Users\user1\AppData\Roaming\Local\run\N4vHnB5kB\conf\php\php.ini ). Look for:
display_startup_errors = On
and change it to:
display_startup_errors = Off
Save the file. That’s it. Warnings will be not present anymore. Now you can execute WP CLI command without any problems. To test our solution, we will export WordPress tables started with the prefix:
wp db export --tables=$(wp db tables 'wp_20*' --format=csv)
Success! Here is the output:
Success: Exported to 'local-2022-07-13-51e1a91.sql'.
That’s it for today’s tutorial. Don’t forget to subscribe to our newsletter and stay up to date with other useful tips and guidelines.
Do you need someone to implement this solution for you? Check out our specialists for hire in the outsourcing section. Are you considering a global project and are uncertain how to proceed? See how we do it.