Running Command line php or Shell Script as External tool


Been using phpStorm now for a month solid 8 horus a day everyday for my work and am very impressed. After using ReSharper for years as a .NET dev.

I am now setting it up to help me do daily tasks easier etc. The one thing i cannot get to work is this:

Say I have a shell script or a php file which can be run via command line (or command line too within phpStorm)

php /path/to/php/file.php (this works if i type it into the command line console in phpStorm).

When I try and set it up as an external tool , i keep getting the error code 2 , which is file not found , even when i look at the error the path is correct the file exists there. I have no idea why this is not working

I have googled etc and found no real answer to this problem




Hi there,

How did you setup your External Tool entry? A screenshot would be good (extrenal tools entry; the error; ect).


Please see the images below.. As i said if I run for this example the simple command.

php /Users/waseem/Development/p.php

I get the output of the php file which is just the text "test"



As I suspected you are doing it wrong.

The Edit External Tool screen (the one on your screenshot) has separate fields for program and parameters -- use both of them -- they are there for a reason -- do not put whole command in "program" field.

To sum up:
Program: $PhpExecutable$
Parameters: /Users/waseem/Development/p.php


Cool for that simple scenario things are fine...

My more complicated issue was as follows:

php /path/to/php/file.php FILETOPROCESS

So i tired the following:

Program: $PhpExecutable$
Parameters: /path/to/php/file.php FILETOPROCESS

Result = Not working

my solution was:

Create bash script in /usr/bin called "dophp"

php /path/to/php/file.php $1


Program: dophp
Parameters: $FileParentDir$/$FileNameWithoutExtension$.php

For what I needed this all worked. There were some failed attempts using the .profile file in Mountain Lion (mac) .. and setting my dophp in there as an alias of the php command. From normal terminal this worked fine. But from within phpStorm it did not recognize the dopage command untill it was in a script in /usr/bin .

Hope this helps someone else out there maybe.



PhpStorm may simply not see some environment configurations/parameters (cannot find the better word right now, sorry) if they applied to *terminal only* (e.g. .bash_profile or whatever those files are -- sorry, I'm not a Mac user). That's why (one of the reasons) some functionality (e.g Run/Debug Configurations; File Watchers) have "Environment variables" field.

Have a look at comments in this thread (for example), starting from this one: it should explain most (if not all) of it.

In any case, I would expect this to work, as long as path to php is a full path -- I personally see nothing wrong with it:
Program: $PhpExecutable$
Parameters: /path/to/php/file.php FILETOPROCESS

You may file a bug report to the Issue Tracker if the above does not work (using full paths).

Same with this:
Program: dophp    (<-- better use FULL path to that file)

Parameters: $FileParentDir$/$FileNameWithoutExtension$.php


Thank You for the help I got it working which is the main thing I am productive :)

I will try what you said .


Please sign in to leave a comment.