PHPのインストール

[参考記事] Apacheのインストール
[参考記事] PHPをyumでインストールする
[参考記事] GD関数でJPEGライブラリが使用できないとき

PHPをインストールするには、公式サイトよりPHPソースファイルをダウンロードします。

PHP公式サイト
ダウンロード

コマンド(ターミナル)より直接ダウンロードする場合はURLを調べて、wgetコマンドを実行します。

ダウンロード

wget http://jp2.php.net/get/php-5.2.11.tar.gz/from/jp.php.net/mirror

ダウンロードしたファイルが正しいものかどうか検証するには次のコマンドを実行します。

md5sum php-5.2.11.tar.gz

これがダウンロードリンクにあるmd5チェックサムと一致するかを確認します。

解凍

ダウンロードしたファイルは圧縮されいてるため、そのままではインストールできません。

一般的には、/usr/local/srcに解凍します。
解凍後は解凍されたディレクトリに移動します。

tar zxvf php-5.2.11.tar.gz -C /usr/local/src
cd /usr/local/src/php-5.2.11/

インストール

[参考記事] MySQLのインストール

[参考記事] PostgreSQLのインストール

[参考記事] zlibのインストール

使用したい設定にあわせてconfigureオプションを指定します。

./configure --with-apxs2=/usr/local/apache2/bin/apxs --enable-mbregex --enable-mbstring --enable-zend-multibyte --with-mysql --with-mysqli=/usr/bin/mysql_config --enable-ftp --with-zlib --with-openssl --with-pdo-mysql --with-gd

makeでビルドします。

make

ビルド結果

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.


Build complete.
Don't forget to run 'make test'.

make testをするのを忘れないでください。とあるので『 make test 』しますが、たまに失敗するようです。
エラーレポートをPHP.netに送るように促される場合は、気にしないで次に進んでもいいかもしれません。

make test

make installでインストールを実行します。

make install

インストール結果

[PEAR] Archive_Tar    - installed: 1.3.3
[PEAR] Console_Getopt - installed: 1.2.3
[PEAR] Structures_Graph- installed: 1.0.2
[PEAR] XML_Util       - installed: 1.2.1
[PEAR] PEAR           - installed: 1.8.0
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
Installing PDO headers:          /usr/local/include/php/ext/pdo/

インストール時のトラブル

MySQLのヘッダーファイルがない・かクライアントライブラリがない

checking for MySQL UNIX socket location... /var/lib/mysql/mysql.sock
configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore!

この場合、MySQLのインストールを確認しましょう。
MySQLのサーバ版、クライアント版だけでなく、Headers and librariesのMySQL-develが必要です。

インストール後の設定

PHPのモジュールが組み込まれるように、PHPのインストール時にApacheのhttpd.confに追記がされます。
しかし『 .php 』をPHPファイルとして関連付ける設定まではされていないため、 httpd.confに下記を追記します。

AddType application/x-httpd-php .php

Apacheの再起動

PHPのインストール後にApacheを再起動すると、PHPがweb経由で使用できます。

/usr/local/apache2/bin/apachectl restart

ここで下記のようなエラーが出る場合には、SElinuxが有効になっているせいです。

httpd: Syntax error on line 53 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

/usr/local/apache2/modules/libphp5.so
をApacheの実行権限では呼び出すことができないというエラーです。

まずはSELinuxが有効かどうかを確認します。

/usr/sbin/getenforce

Enforcing と出たらSELinuxは有効、
Permissive と出たらSELinuxは無効です。

有効になっている場合、下記のコマンドで権限を変更します。

chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache2/modules/libphp5.so

関連記事

スポンサーリンク

インストールの方法

ホームページ製作・web系アプリ系の製作案件募集中です。

上に戻る