LoginSignup
2
6

More than 5 years have passed since last update.

PHPを直接実行する(#!/usr/bin/php -q)

Last updated at Posted at 2017-11-04

shebang

phpファイルを実行するときはphpコマンドの後にファイルパスを書きますが、
シェルファイルのように1行目に#!/usr/bin/php -qを記入すれば直接実行できます。

#!/usr/bin/php -q
<?
...

phpの場所が/usr/bin/とは限らないので、その場合は/usr/bin/envを使うといいらしいです。
【PHP】shebang

ハマりどころ

  • ファイルに実行権限を与えること。
chmod +x ...
  • 改行コードをLFにすること。

Windowsで書いているとCR+LFになっていたりするので要注意。
PHP Shebang not working

2
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
6