LoginSignup
7
8

More than 5 years have passed since last update.

php-build をインストールして pear を使う方法

Last updated at Posted at 2012-03-23

php-build は、複数バージョンのPHPのダウンロード・展開・コンパイル・インストールまでをコマンドひとつで行えるツールです。拡張やPEARライブラリの管理などを行う pyrus がインストール時に同梱されるため、pearコマンドはインストールされません。

ここでは、pyrus ではインストールできない pecl ライブラリを使うために、 pyrus を無効にし、 pear を使えるようにする方法を紹介します。

  • Ubuntu環境での手順です

1. php-build のインストール

ソースコードをチェックアウトする:

cd
git clone git://github.com/CHH/php-build
cd php-build/

install.shにバグがあるので修正する:

vim install.sh 

下記の行を消す:

chmod -R 0777 "$LOG_DIR"

php-build のインストールを実行する:

sudo ./install.sh

インストールできたか確認する:

php-build --definitions

PHPのバージョンが羅列されればOK。

2. 定義ファイルをバージョン管理下に置く

定義ファイルは /usr/local/share/php-build/definitions/ にあり、php-build 実行時に定義ファイルの場所を指定することはできないようなので、定義ファイルのディレクトリを git でバージョン管理する:

cd /usr/local/share/php-build/definitions/
sudo git init
sudo git add -A
sudo git commit --message "first commit"

3. pyrusを無効にし、pearを有効にする

PHP-5.3.0の定義ファイルを編集する:

sudo vim 5.3.10

下記のようにする:

with_pear
install_package "http://www.php.net/distributions/php-5.3.10.tar.bz2"

開発環境であればxdebugの行は残しても構わない。pryusの行はバッティングするので必ず消すこと。また install_package より上に with_pear を記述する必要がある。

編集した定義ファイルをコミットする:

sudo git commit --message "5.3.10: disalbe pryus and enable pear" --all

4. PHP をビルド&インストールする

インストール先のディレクトリを作る:

cd ~
mkdir ~/php-versions

phpenv などを使っている場合は、作る必要なし。

PHPをビルドするのに必要なパッケージをインストールする:

sudo aptitude install build-essential bison re2c libxml2-dev zlib1g-dev \
libcurl4-openssl-dev libjpeg62-dev libpng12-dev libfreetype6-dev libt1-dev \
libmcrypt-dev libreadline-dev libtidy-dev libxslt1-dev

PHP-5.3.10 をインストールする:

php-build 5.3.10 /home/suin/php-versions/5.3.10

※第二引数 prefix は絶対パスにしないとうまくいかないので注意。

インストールされたバージョンを確認する:

~/php-versions/5.3.10/bin/php -v
~/php-versions/5.3.10/bin/pear version

以上

7
8
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
7
8