VGTech is a blog where the developers and devops of Norways most visited website share code and tricks of the trade… Read more



Are you brilliant? We're hiring. Read more

Don’t Hardcode PHP Executable Path In Shebang

PHP

Some time ago I saw a tweet from Sean Coates about not using a hardcoded path to the PHP executable. With the volatile nature of Twitter, I decide to write a blog post repeating his advice.

When you are using PHP for CLI scripts you should avoid starting them with a common shebang like “#!/usr/bin/php”. Not every GNU/Linux distribution or installation method will place the PHP executable in the directory you expect from your own system.

/usr/bin/env can be used to execute commands in a configured environment where the path to the PHP executable (most likely) will appear in the $PATH variable. If it’s not there, it most certainly ain’t in /usr/bin/php.

A much better shebang for your PHP script would be: #!/usr/bin/env php

Developer at VG. @androa


0 comments

    Leave your comment