The linter-phpmd plugin for Atom is popular with PHP and WordPress developers, but it relies on having phpmd installed and available on your PATH. Without it, you might see an error:
[Linter] Error running PHPMD Error: Failed to spawn command `phpmd`. Make sure `phpmd` is installed and on your PATH
If you’ve seen this error in your Atom Developer Tools, the fix is quite simple. You just need to:
- Install phpmd – we’ll use Composer for this.
- Add it to your path – this makes it available anywhere on your command line.
Is Composer already installed globally?
If so, consider running composer self-update to be sure you’re on the latest version.
If not, jump over to getcomposer.org to install it globally on your local system. Then come back and continue with the steps in this post.
You can check if it’s installed by attempting to get the version. It should return something like
Composer version 1.4.2 2017-05-17 08:17:52.
Installing phpmd globally is required to ensure it is available for Atom to use. Start by running the following command:
composer global require phpmd/phpmd
You can now run phpmd using the full path to the installed binary:
# Check the installed version. ~/.composer/vendor/bin/phpmd --version
That’s helpful, but let’s make sure the command is available everywhere without the full path.
Add phpmd to your PATH
You could add just phpmd to your path, but I find it’s much easier to add all of your globally-installed Composer binaries to your path, so that they are always available to you. (Hey, they’re supposed to be global, right?!)
To do that, use your favorite terminal editor to edit your
# Using vim $ vim ~/.bash_profile # Using nano $ nano ~/.bash_profile
You’ll need to add the following lines somewhere in the file:
# Add globally-installed Composer binaries to PATH. export PATH=~/.composer/vendor/bin:$PATH
Then, be sure to reload your environment variables in your terminal by running:
# Reload the file from source. source ~/.bash_profile
Verify it works!
Try to run the raw phpmd command to get the currently installed version:
Those pesky Atom phpmd linter errors should now have melted away 🙂