Ubuntu16.04LTS下PhpStorm2018.1配置php7.0解释器报错求助
Hey there, let’s work through this PhpStorm interpreter validation error step by step, based on your setup details:
Step 1: Verify You’re Selecting the Exact PHP 7.0 Binary
Even though which php points to /usr/bin/php, symlinks can sometimes cause confusion in PhpStorm. Let’s explicitly target PHP 7.0:
- Open PhpStorm and navigate to
File > Settings > Languages & Frameworks > PHP - Click the
...button next to "CLI Interpreter" - Select
Localfrom the dropdown, then browse directly to/usr/bin/php7.0(not just/usr/bin/php) - Save the configuration and try validating again
Step 2: Align PhpStorm with Your CLI’s php.ini
PhpStorm might be loading a different php.ini file than your terminal’s PHP instance. Let’s sync them:
- Run this in your terminal to find your active CLI php.ini:
Note the path listed underphp --iniLoaded Configuration File(e.g.,/etc/php/7.0/cli/php.ini) - Back in PhpStorm’s CLI Interpreter settings, go to the
Configuration Optionstab - Add a new entry:
-cwith the value of your loaded php.ini path (e.g.,/etc/php/7.0/cli/php.ini) - Apply changes and re-validate
Step 3: Eliminate Unwanted PHP CLI Output
The "Failed to parse" error almost always happens when PHP outputs extra text (warnings, notices, or custom startup messages) before the clean JSON PhpStorm expects. Here’s how to fix it:
- Test if PHP outputs extra content by running:
If the output starts with warnings/errors instead of pure JSON, that’s your culprit.php -r "echo json_encode(['test' => 'valid']);" - Fix this by either:
- Editing
/etc/php/7.0/cli/php.inito setdisplay_errors = Off - Adding a configuration option in PhpStorm’s CLI settings:
-d display_errors=0
- Editing
Step 4: Check for Auto-loaded PHP Scripts
If you have an auto_prepend_file configured in php.ini, it might inject extra output. Run this to check:
php -i | grep auto_prepend_file
If a path is listed, either comment out that line in your cli/php.ini or adjust the script to not output anything when running via CLI.
内容的提问来源于stack exchange,提问作者Prasad Sawant

