月別アーカイブ: 2013年5月

ロリポップのサーバーでPEARを使う方法

PEARのインストール

  1. 「http://pear.php.net/go-pear」をダウンロードし、「go-pear.php」という名前で保存。
  2. ユーザーディレクトリ内に「php/lib」などというディレクトリを作成し、libディレクトリ内に「go-pear.php」を置く。
  3. ブラウザーから「http://www.example.com/php/lib/go-pear.php」にアクセスする。
  4. 表示された画面にしたがってインストールを行う。

すると「php/lib/PEAR」にPEARがインストールされる。PEARの管理は「http://www.example.com/php/lib/PEAR/index.php」から行う。
ただし、上記ファイルは誰にでもアクセルできる状態なので、.htaccessなどを用い、適切なアクセス管理をする。

 

PEARを利用するためのPATHの設定

次にPHPからPEARにアクセスできるようにPATHを設定する

  1. ユーザーディレクトリ内に作成した「php/lib/」内に「pear_path.php」というファイルを作成。

内容は下記の通り

[php]
<?php
ini_set(‘include_path’, ‘(ユーザーディレクトリのフルパス)/web/lib/PEAR’);
?>
[/php]

  1. ロリポップ!ユーザー専用ページから「Webツール」→「PHP」と進み「php.iniの設定」をする

「auto_prepend_file」の値に「(ユーザーディレクトリのフルパス)/web/lib/pear_path.php」を設定

上記でPHPからPEARがインクルードできるようになる。

HTTP_Request2などを使いたい場合は、まず http://www.example.com/php/lib/PEAR/index.php にから「HTTP_Request2」をインストールした後、PHPのプログラムファイルから「require_once ‘HTTP/Request2.php’」とする。

HTTP_Request2を用いたGoogle へのサイトマップ送信

Googleへサイトップを送信する際、PHP PEARのHTTP_Request2を使う方法は下記の通り。

[php]
<?php
require_once ‘HTTP/Request2.php’;

$uri = ‘http://www.google.com/webmasters/tools/ping’;
$sitemap_uri = ‘http://www.example.com/sitemap.xml’;

try{
$request2 = new HTTP_Request2($uri);
$request2—>setMethod(HTTP_Request2::METHOD_POST);
$request2->addPostParameter(‘sitemap’, $sitemap_uri);
$result = $request2->send();
echo $result->getBody();
} catch( HTTP_Request2_Exception $e ){
exit($e->getMessage());
} catch (Exception $e){
exit($e->getMessage());
}
?>
[/php]

上記実行後、下記のように表示されたらリクエストの送信は成功。

Sitemap Notification Received
Your Sitemap has been successfully added to our list of Sitemaps to crawl. If this is the first time you are notifying Google about this Sitemap, please add it via http://www.google.com/webmasters/tools/ so you can track its status. Please note that we do not add all submitted URLs to our index, and we cannot make any predictions or guarantees about when or if they will appear.