問題
さくらのレンタルサーバ スタンダードに「PEAR パッケージマネージャの取得とインストール(ホスティング環境でのPEAR)」の方法でPEARをインストールしようとしたところ、
1 |
Fatal error: Class 'PEAR' not found in /path/to/go-pear.php on line 697 |
のエラーで停止してしまった。
環境
さくらのレンタルサーバ スタンダード
1 2 3 4 |
$ php --version PHP 5.4.29 (cli) (built: Jun 11 2014 18:20:32) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies |
解決方法
ダウンロードした http://pear.php.net/go-pear のスクリプトを以下の通り変更する。
(今回のソースだと115行目から120行目)
1 2 3 4 5 6 |
$bootstrap_files = array( 'PEAR5.php' => 'https://raw.github.com/pear/pear-core/master/PEAR5.php', 'PEAR.php' => 'https://raw.github.com/pear/pear-core/master/PEAR.php', 'Archive/Tar.php' => 'https://raw.github.com/pear/Archive_Tar/master/Archive/Tar.php', 'Console/Getopt.php' => 'https://raw.github.com/pear/Console_Getopt/trunk/Console/Getopt.php', ); |
1 2 3 4 5 6 |
$bootstrap_files = array( 'PEAR5.php' => 'https://raw.githubusercontent.com/pear/pear-core/master/PEAR5.php', 'PEAR.php' => 'https://raw.githubusercontent.com/pear/pear-core/master/PEAR.php', 'Archive/Tar.php' => 'https://raw.githubusercontent.com/pear/Archive_Tar/master/Archive/Tar.php', 'Console/Getopt.php' => 'https://raw.githubusercontent.com/pear/Console_Getopt/trunk/Console/Getopt.php', ); |
原因
上記、「変更前」の「$bootstrap_files」にあるURLは、全て「変更後」のURLに301リダイレクトされている。
go-pear のソース1055行目あたりにある download_url() で、fsockopen() を使用しているが、fsockopen() は301リダイレクトを追従してくれないため、各ファイルをダウンロードできず、PEARクラスが無いよエラーでコケる。
ので、301リダイレクト先のURLを指定してあげる。(「raw.github.com」を「raw.githubusercontent.com」に変更する。)