LoginSignup
8
8

More than 3 years have passed since last update.

PHPのバージョン確認はphpinfoで行うのが確実

Last updated at Posted at 2019-08-05

はじめに

運用しているサイトでエラーが発生!解析のため、PHPのバージョンを確認したい。sshで接続してPHPのバージョン確認をしてみる。

[user@host ~]$ php -v
PHP 5.6.8 (cli) (built: May  6 2015 02:27:31) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
[user@host ~]$ 

よし!PHP5.6だ!!

違う!!(こともある)

php -vで確認できるのはcliで稼働しているPHPのバージョンであり、Apacheで稼働しているPHPのバージョンは違うかもしれない。また、ドメインやサブドメイン単位でPHPのバージョンを切り替えて運用している場合もある。ではどうすれば正確なPHPのバージョンを確認することができるのか…

phpinfoで確認する

phpinfo.php
<?php
phpinfo();

DocumentRoot配下にphpinfo.phpを配置し、HTTPSでアクセスして確認するのが確実。
※確認が終わったらphpinfo.phpの削除をお忘れなく

XSERVERの場合

サーバーパネル > PHP > PHP Ver.切替
から、ドメイン単位でPHPのバージョンを確認、変更ができる

2019/8/5時点で選択できるPHPバージョン

  • PHP7.2.17 (推奨)
  • PHP7.1.28
  • PHP7.0.33 (非推奨)
  • PHP5.6.40 (非推奨)
  • PHP5.5.38 (非推奨)
  • PHP5.4.16 (非推奨)
  • PHP5.3.3 (非推奨)
  • PHP5.1.6 (非推奨)

自作Ubuntsサーバーの場合

下記コマンドで有効になっているモジュールを確認する

a2dismod php <tab>
a2dismod php7.3
# PHP7.3モジュールが有効になっていることが分かる

※CGI版のPHPが稼働する場合は、直接コンフィグファイルを確認する。

参考

composerやLaravelのartisan、CakePHPのbakeなどはcliで実行するため、上述のphp -vでバージョン確認を行うのが適切。

リンク

8
8
2

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
8