8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHP コマンドを実行しても何も出力されない

Posted at

なんやこれ、と解決に無駄に時間がかかってしまった
ある日サーバーでphp cliを実行したら正常に動いてなかった。

root@hoge:~# php -v
root@hoge:~#

エラーもなにも出ない。
でもapache側のモジュールとして組み込んでるPHPは正常稼働している。。
いろいろ調べてたんですが、原因はphp.iniでした。

php.iniで display_errors = Off となっている状態だとエラーを表示しませんが、
CLIでも何も出力されないみたいです。
おそらくはdisplay_errors = Offの設定ののちに誰かが追加した設定がエラーを吐いているのでしょう。
Apacheのモジュール版PHPは再起動するまで設定が反映されなかったと思うのでApache側のPHPが動いているのも納得できます。

ここをdisplay_errors = Onとするとエラーが出るのでそれを読み解けば一気に解決できると思うのですが、そうすると現状のapache側でnoticeとかのエラーが出力されてお叱りを受けるかもしれません。

実はdisplay_errors = stderrとするとCGIやCLIモードの場合のみエラーを出す事ができます。
この設定を反映させて実行。

root@hoge:~# php -v
Fatal error: Directive 'allow_call_time_pass_reference' is no longer available in PHP in Unknown on line 0

PHP5.4で削除された内容を記述してエラーになってたんですね。
この設定をphp.iniからコメントアウトすると正常になりました。

root@hoge:~# php -v
PHP 5.5.5 (cli) (built: Jun 26 2014 14:55:05) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies

display_errors = Onでもちゃんと動くようにプログラム作ろうって話ですね。

8
9
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
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?