Last-modified: 2011-12-26 (月) 01:24:42
Apache/mod_php導入(CentOS)

概要

ソースからインストールしたApacheにmod_phpをインストールします。
Apacheのインストールに関しては、以下のページを参照ください。
ソースから導入

手順

  1. 前準備です。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
    
    -
    !
    -
    !
     
    -
    |
    !
    -
    !
     
    -
    |
    !
    -
    !
     
    -
    |
    !
    -
    !
     
    -
    |
    !
    -
    !
     
    -
    |
    !
    -
    !
     
    -
    |
    !
    -
    !
     
    -
    |
    !
    -
    !
     
    -
    |
    |
    !
    
    # libxml2-develのインストールを確認します
    yum list | grep libxml2-devel
    # 未インストールならばインストールします
    yum install libxml2-devel
     
    # MySQLサポートを組み込みたい場合
    # libxml2-develのインストールを確認します
    yum list | grep mysql-devel
    # 未インストールならばインストールします
    yum install mysql-devel
     
    # GDサポートを組み込みたい場合
    # gd-develのインストールを確認します
    yum list | grep gd-devel
    # 未インストールならばインストールします
    yum install gd-devel
     
    # GDサポート(jpeg)を組み込みたい場合
    # libjpeg-develのインストールを確認します
    yum list | grep libjpeg-devel
    # 未インストールならばインストールします
    yum install libjpeg-devel
     
    # GDサポート(png)を組み込みたい場合
    # libpng-develのインストールを確認します
    yum list | grep libpng-devel
    # 未インストールならばインストールします
    yum install libpng-devel
     
    # GDサポート(freetype)を組み込みたい場合
    # freetype-develのインストールを確認します
    yum list | grep freetype-devel
    # 未インストールならばインストールします
    yum install freetype-devel
     
    # cURLサポートを組み込みたい場合
    # curl-develのインストールを確認します
    yum list | grep curl-devel
    # 未インストールならばインストールします
    yum install curl-devel
     
    # mcryptサポートを組み込みたい場合
    # libmcrypt-develのインストールを確認します
    yum list | grep libmcrypt-devel
    # 未インストールならばインストールします
    yum install libmcrypt-devel
     
    # 後述のconfigureオプションを指定してmakeしたたところ
    # 私の環境ではlibltdlが無くてエラーになりました
    # 以下のパッケージをインストールしたところ、エラーが解消されました
    yum install libtool-ltdl-devel
  2. ソースをダウンロードします。
    Everything is expanded.Everything is shortened.
      1
      2
      3
    
    -
    |
    !
    
    # URLは検証時に使用したものです
    # 最新版のURLに変更してください
    wget http://www.php.net/get/php-5.3.1.tar.gz/from/jp.php.net/mirror
  3. 展開します。
    Everything is expanded.Everything is shortened.
      1
    
     
    
    tar zxvf php-5.3.1.tar.gz
  4. 展開先へ移動します。
    Everything is expanded.Everything is shortened.
      1
    
     
    
    cd php-5.3.1
  5. makefileを作成します。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
    
    -
    !
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    
    # configureを実行して、makefileを作成します
    './configure' \
    '--with-apxs2filter=<Apacheルート>/bin/apxs' \
    '--enable-mbstring' \
    '--enable-mbregex' \
    '--enable-zend-multibyte' \
    '--with-zlib' \
    '--with-mysql' \
    '--enable-sqlite-utf8' \
    '--with-gd' \
    '--with-jpeg-dir=/usr/lib' \
    '--with-png-dir=/usr/lib' \
    '--with-zlib-dir=/usr/lib' \
    '--with-freetype-dir=/usr/lib' \
    '--enable-gd-native-ttf' \
    '--disable-gd-jis-conv' \
    '--with-curl=/usr/include/curl' \
    '--with-mysqli=/usr/bin/mysql_config' \
    '--with-mcrypt' \
  6. ビルド、インストールを行ないます。
    Everything is expanded.Everything is shortened.
      1
      2
      3
    
     
     
     
    
    make
    make test
    make install
  7. <Apacheルート>/conf/httpd.confを編集します。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
    
    -
    |
    !
     
    -
    |
    |
    |
    |
    !
    -
    |
    
    # モジュールをロードするように設定されているか確認します
    # mod_phpインストール時点で追記されていました
    LoadModule php5_module        modules/libphp5.so
     
    # mod_php
    # IfModuleディレクティブで囲んだ方がよいでしょうが
    # 囲むと存在しないと判断されてしまいました
    # 今回は常にmod_phpを有効にしておくため、囲まないことにしました
    #<IfModule mod_php5.c>
        AddType application/x-httpd-php .php
    #</IfModule>
    # 
    
  8. SELinuxを有効にしている場合は、libphp5.soのコンテキストが原因でApacheが起動しなくなる可能性があります
    libphp5.soが原因でApacheが起動しないに解決法の1つを書きましたので、参照ください。
  9. 公開ディレクトリにinfo.phpを作成します。
    <?php phpinfo() ?>
  10. アクセスしてphpが動作していることを確認します。
  11. php.iniをコピーします。
    Everything is expanded.Everything is shortened.
      1
      2
    
    -
    !
    
    # php.ini-developmentは開発用らしいので、php.ini-productionをコピーします
    cp <PHPソースパス>/php.ini-production <phpinfoのConfiguration File Path(php.ini)>
  12. PHPのバージョンが5.3系ならば、タイムゾーンの設定を行ないます。
    It is not safe to rely on the system's timezone settings.
  13. Apacheを再起動します。
    Everything is expanded.Everything is shortened.
      1
    
     
    
    /etc/init.d/httpd restart

検証時の環境

参考