LoginSignup
3
4

More than 3 years have passed since last update.

Linux PHPの2種類のインストール方法

Posted at

1.はじめに

Linux CentOS7で,php をインストール機会があったので 自分なりにまとめてみました。

2.2種類のインストール方法

1.ソースからコンパイルしてインストール

2.パッケージ管理ツール(yumなど)でインストール

3.メリット・デメリット

メリット     デメリット
ソースから 最新版を利用可能 時間がかかる
複数バージョンを共存可能 エラー時に知識が必要
オプションを指定可能
パッケージから 簡単にインストール可能 最新版が使えない

ソース → 環境に対する自由度が高い

パッケージ → 履歴を持っていること

4.ソースからコンパイルしてインストール

まとめてくださっていた方がいたので、こちらを参考にしてください。CentOS 7 PHP 7.2.3のソースファイルからのインストール

5.パッケージ管理ツール(yum)を使ったインストール

5.1 インストールするPHPについて情報を得る

ROOT権限で
yum info php
を実行すると 以下のようになります。

読み込んだプラグイン:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
利用可能なパッケージ
名前                : php
アーキテクチャー    : x86_64
バージョン          : 5.4.16
リリース            : 46.el7
容量                : 1.4 M
リポジトリー        : base/7/x86_64
要約                : PHP scripting language for creating dynamic web sites
URL                 : http://www.php.net/
ライセンス          : PHP and Zend and BSD
説明                : PHP is an HTML-embedded scripting language. PHP attempts
                    : to make it easy for developers to write dynamically
                    : generated web pages. PHP also offers built-in database
                    : integration for several commercial and non-commercial
                    : database management systems, so writing a database-enabled
                    : webpage with PHP is fairly simple. The most common use of
                    : PHP coding is probably as a replacement for CGI scripts.
                    :
                    : The php package contains the module (often referred to as
                    : mod_php) which adds support for the PHP language to Apache
                    : HTTP Server.

この情報から PHPのバージョンが、5.4.16であることがわかります。

5.2 インストール

ROOT権限で
yum -y install php
を実行します。
* -y はyumのオプションで、インストール中のすべての[y/N]の問いに[y]で回答するものです。
 

読み込んだプラグイン:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ php.x86_64 0:5.4.16-46.el7 を インストール
--> 依存性の処理をしています: php-common(x86-64) = 5.4.16-46.el7 のパッケージ: php-5.4.16-46.el7.x86_64
--> 依存性の処理をしています: php-cli(x86-64) = 5.4.16-46.el7 のパッケージ: php-5.4.16-46.el7.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ php-cli.x86_64 0:5.4.16-46.el7 を インストール
---> パッケージ php-common.x86_64 0:5.4.16-46.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

================================================================================
 Package             アーキテクチャー
                                     バージョン             リポジトリー   容量
================================================================================
インストール中:
 php                 x86_64          5.4.16-46.el7          base          1.4 M
依存性関連でのインストールをします:
 php-cli             x86_64          5.4.16-46.el7          base          2.7 M
 php-common          x86_64          5.4.16-46.el7          base          565 k

トランザクションの要約
================================================================================
インストール  1 パッケージ (+2 個の依存関係のパッケージ)

総ダウンロード容量: 4.7 M
インストール容量: 17 M
Downloading packages:
(1/3): php-common-5.4.16-46.el7.x86_64.rpm                 | 565 kB   00:00
(2/3): php-5.4.16-46.el7.x86_64.rpm                        | 1.4 MB   00:00
(3/3): php-cli-5.4.16-46.el7.x86_64.rpm                    | 2.7 MB   00:00
--------------------------------------------------------------------------------
合計                                                12 MB/s | 4.7 MB  00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : php-common-5.4.16-46.el7.x86_64                 1/3
  インストール中          : php-cli-5.4.16-46.el7.x86_64                    2/3
  インストール中          : php-5.4.16-46.el7.x86_64                        3/3
  検証中                  : php-common-5.4.16-46.el7.x86_64                 1/3
  検証中                  : php-cli-5.4.16-46.el7.x86_64                    2/3
  検証中                  : php-5.4.16-46.el7.x86_64                        3/3

インストール:
  php.x86_64 0:5.4.16-46.el7

依存性関連をインストールしました:
  php-cli.x86_64 0:5.4.16-46.el7        php-common.x86_64 0:5.4.16-46.el7

完了しました!

5.3インストールの確認

php -v
を実行します。

PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

上記のように、バージョンが表示されれば、インストールは成功です。

参考

LinuxにPHPをインストールする方法は大きく2通りあると思います。
PHPをインストールしよう[Linux構築編]
Composer による PHP 依存関係の処理

3
4
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
3
4