その他
    ホーム 技術発信 DoRuby PHPのソースインストール

    PHPのソースインストール

    この記事はアピリッツの技術ブログ「DoRuby」から移行した記事です。情報が古い可能性がありますのでご注意ください。

    CentOSにPHP5.2系を入れる為に、utterramblingsリポジトリを使用してyumで楽にインストールしてましたが、ある時から不安定でインストール出来ないという状況が何度か続いた為、最近はソースインストールするようにしています。そのメモです。
    私の要件はyumの場合と同じものを使えるようにする事。
    ちなみに以前はこんな感じで色々入れてました。
    # yum –enablerepo=utterramblings -y install php php-gd php-ldap php-mbstring php-pear php-mcrypt php-xml php-devel php-apc php-soap php-mysql
    # pecl install fileinfo
    ※後は/etc/php.ini、/etc/php.d/apc.ini, fileinfo.iniの設定で完了。

    ●PHPのインストール

    XAMPPに入っているPHP5.2系の最後が1.7.1のPHP5.2.9なので、個人的にはこのバージョンを使用しています。
    # wget http://museum.php.net/php5/php-5.2.9.tar.gz
    # tar zxvf php-5.2.9.tar.gz
    # cd php-5.2.9
    # ./configure –with-apxs2 –with-bz2 –enable-calendar –with-curl –enable-exif –enable-ftp –with-gd –with-gettext –with-gmp –with-ldap –enable-mbstring –with-mcrypt –with-mysql –with-mysqli –with-openssl –with-pdo-mysql –with-pspell –enable-shmop –enable-soap –enable-sockets –enable-sysvmsg –enable-wddx –enable-xml –with-xsl –with-zlib –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d
    後はひたすら、エラーメッセージを見て必要なものをインストール⇔configureを繰り返します。

    configure: error: no acceptable cc found in $PATH
    # yum -y install gcc
    ./configure: line 6699: apxs: command not found
    # yum -y install httpd-devel
    configure: error: xml2-config not found. Please check your libxml2 installation.
    # yum -y install libxml2-devel
    configure: error: Cannot find OpenSSL’s
    # yum -y install openssl-devel
    configure: error: Please reinstall the libcurl distribution –
    easy.h should be in /include/curl/
    # yum -y install curl-devel
    configure: error: libpng.(a|so) not found.
    # yum -y install gd-devel
    configure: error: Unable to locate gmp.h
    # yum -y install gmp-devel
    configure: error: mcrypt.h not found. Please reinstall libmcrypt.
    # yum -y install libmcrypt-devel
    Note that the MySQL client library is not bundled anymore!
    # yum -y install mysql-devel
    configure: error: Cannot find pspell
    # yum -y install pspell-devel
    configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
    # yum -y install libxslt-devel
    Thank you for using PHP.これでconfigureが完了。

    # make
    # make install
    # cp -a php.ini-recommended /etc/php.ini
    # mkdir /etc/php.d

    ●apcのインストール

    # pecl install apc
    エラーメッセージを見て必要なものをインストール、もう一度実行。
    Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF
    environment variable is set correctly and then rerun this script.
    ERROR: `phpize’ failed
    # yum -y install autoconf
    # pecl install apc

    ●PHPの設定変更

    # vi /etc/httpd/conf.d/php.conf

    LoadModule php5_module modules/libphp5.so

    LoadModule php5_module modules/libphp5-zts.so

    AddHandler php5-script .php
    AddType text/html .php

    DirectoryIndex index.php

    php_value date.timezone Asia/Tokyo
    SetEnv TZ Asia/Tokyo

    デフォルトではモジュールのパスが違うので変更しておく。
    # vi /etc/php.ini
    extension_dir = “./”↓変更
    extension_dir = “/usr/lib/php/modules”
    # mkdir /usr/lib/php
    # ln -s /usr/local/lib/php/extensions/no-debug-non-zts-20060613 /usr/lib/php/modules
    後はそれぞれのモジュールが読み込まれるように設定する。
    # vi /etc/php.d/apc.ini
    extension=apc.so
    # vi fileinfo.ini
    extension=fileinfo.so

    ●Apacheの再起動

    # apachectl configtest
    Syntax OK
    # /etc/rc.d/init.d/httpd restart

    記事を共有