人気ブログランキング | 話題のタグを見る
Windows環境に OPEN PNE 2.14.1をインストールしてみた
新しい案件でオープンソース SNS で定番らしい OPEN PNE を使うかもしれないので、実行環境作ってみました。

まず、OpenPENダウンロードページからダウンロードします。

今回使ったのは安定版となっていた、 OpenPNE Ver.2.14.1 です。

解凍した中の setup/OpenPNE_Setup.html にセットアップがガイドが入ってるんで、これに従って入れます。

とりあえず要所のみメモって行きます。


「1. ファイルの設置」
ファイル構造はそのままで行きます。

「2. 設定ファイルの変更」
OPENPNE_DIR/config.php.sample を OPENPNE_DIR/config.php にコピーしてconfig.phpを修正します。

変更したのはDBアクセス周りと、DB暗号化キー、メールサーバードメインです。

「3. データベースの設定」
DBは今回 MySQL5.0 を使います。MySQL5 も setup\sql\mysql41\install の中を使ったんで構わないようです。
新規データベースとして openpne というデータベースを新たに作りました。

後は初期化スクリプトを走らせます。


D:\openpne\setup\sql\mysql41\install>mysql -h localhost -u root -pパスワード --default-character-set=utf8 openpne < install-2.14-create_tables.sql
D:\openpne\setup\sql\mysql41\install>mysql -h localhost -u root -pパスワード --default-character-set=utf8 openpne < install-2.14-insert_data.sql



「4. サーバ設定」
次は Apache の設定をしろということなんですが、既にメインのホストアクセスは CakePHP 用の開発にとっているんで、バーチャルホストを使うことにしました。
LAN内用のDNSサーバ構築してたんで助かりました。


ServerName pc2.xxx.local
DocumentRoot "D:/openpne/public_html/"
ServerAdmin aa@aa.ne.jp
ErrorLog logs/error_log
TransferLog logs/access_log



「4-2. メールサーバの設定」はよくわからんのですっ飛ばし、Windows版なんで「4-3. cronの設定」も飛ばします。


「5. セットアップモジュールの実行」
http://サーバ名/?m=setup
で初期ユーザと管理者ユーザを作成します。


「6. 管理画面へのアクセス」
初期値では
http://サーバ名/?m=admin
が管理画面の初期値だけど、セキュリティ考えたら、別ドメインにするかモジュール名を変更したほうがいいですね。
楽なのはモジュール名の変更で、
config.php 内にある ADMIN_MODULE_NAME の値を変更するだけでいいようです。
この値が m= の後に続く文字列になるようですね。


■外部メールサーバを OPEN PNE から扱う
これでOpenPNEが使えるようになるんですが、まずユーザを作らないといけません。
で、管理ページから行くと招待メールを送らないと行けないようで。。。

OpenPNEはどうやら外部のメールサーバを使うオプションは無いようなのでググってみたら、[はまる]OpenPNEをXAMPPで使うという記事を見つけました。
ここに書いてるように webapp\lib\util\mail_send.php で
return mail($address, $subject, $body, $headers, $params);
を下記のように書き換えます。
include_once('Mail.php');
$recipients = $address ;
$headers = "" ;
$headers['From'] = $from ;
$headers['To'] = $address ;
$headers['Subject'] = $subject;
 
$mail_options = array(
'host' => 'smtp.mailsv.co.jp', // SMTPサーバー名
'port' => 587, // ポート番号
'auth' => true, // SMTP認証 true false
'username' => "test@mailsv.co.jp", // ユーザー名
'password' => "testtest", // パスワード
'localhost' => 'localhost', //送信元サーバーのFQDN名 HELOに使う
);
 
$mail_object =& Mail::factory("SMTP",$mail_options);
$result =$mail_object->send($recipients, $headers, $body);
return $result;



これでメール送信実行したら、こんなエラーが。。。

Warning: Mail_smtp::include_once(Net/SMTP.php) [mail-smtp.include-once]: failed to open stream:
No such file or directory in D:\openpne\lib\include\Mail\smtp.php on line 206

Warning: Mail_smtp::include_once() [function.include]: Failed opening 'Net/SMTP.php' for inclusion
(include_path='D:\yopenpne/lib/include;D:\\openpne/webapp/lib;.;C:\Program Files\PHP\pear') in
D:\openpne\lib\include\Mail\smtp.php on line 206

Fatal error: Class 'Net_SMTP' not found in D:\openpne\lib\include\Mail\smtp.php on line 210

Net_SMTPクラスが入ってないってことらしいですね。

Net_SMTPクラス は PHP のクラスライブラリ PEAR の一部なので、まず PEAR をインストールします。


■PEAR のインストール
PEAR のインストールは PHP インストールフォルダの go-pear.bat をたたくと開始できます。
(バッチたたくと「LIBPQ.dllが見つからなかったため、このアプリケーションは開始できませんでした。アプリケーションをインストールし直すとこの問題は解決される場合があります。」という PostgreSQL 周りのエラーが出ますが、今回 MySQL を使うので無視します。エラー無くすには、php.iniの「extension=php_pgsql.dll」をコメントアウトするといいようです。)


Are you installing a system-wide PEAR or a local copy?
(system|local) [system] : system

system と入力します。



Below is a suggested file layout for your new PEAR installation. To
change individual locations, type the number in front of the
directory. Type 'all' to change all of them or simply press Enter to
accept these locations.

1. Installation base ($prefix) : C:\Program Files\PHP
2. Temporary directory for processing : C:\Program Files\PHP\tmp
3. Temporary directory for downloads : C:\Program Files\PHP\tmp
4. Binaries directory : C:\Program Files\PHP
5. PHP code directory ($php_dir) : C:\Program Files\PHP\pear
6. Documentation directory : C:\Program Files\PHP\docs
7. Data directory : C:\Program Files\PHP\data
8. User-modifiable configuration files directory : C:\Program Files\PHP\cfg
9. Public Web Files directory : C:\Program Files\PHP\www
10. Tests directory : C:\Program Files\PHP\tests
11. Name of configuration file : C:\Windows\pear.ini
12. Path to CLI php.exe : C:\Program Files\PHP\.

1-12, 'all' or Enter to continue:

そのままEnter入力します。
番号やallと押下すると、インストールパスを変更できるようです。



Beginning install...
Configuration written to C:\Windows\pear.ini...
Initialized registry...
Preparing to install...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.2.tar...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.2.3.tar...

installing phar://go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.7.1.tar...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.2.tar.
..
pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0)
install ok: channel://pear.php.net/Archive_Tar-1.3.2
install ok: channel://pear.php.net/Console_Getopt-1.2.3
install ok: channel://pear.php.net/Structures_Graph-1.0.2
install ok: channel://pear.php.net/PEAR-1.7.1
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)

PEAR: To install optional features use "pear install pear/PEAR#featurename"

******************************************************************************
WARNING! The include_path defined in the currently used php.ini does not
contain the PEAR PHP directory you just specified:
<C:\Program Files\PHP\pear>
If the specified directory is also not in the include_path used by
your scripts, you will have problems getting any PEAR packages working.

Would you like to alter php.ini <C:\Program Files\PHP\php.ini>? [Y/n] :

Y を押下します。これにより、php.ini に PERA のパスを自動的にに追記してくれる用です。
下記のパスが追加されてました。

;***** Added by go-pear
include_path=".;C:\Program Files\PHP\pear"
;*****




php.ini <C:\Program Files\PHP\php.ini> include_path updated.

Current include path : .;C:\php5\pear
Configured directory : C:\Program Files\PHP\pear
Currently used php.ini (guess) : C:\Program Files\PHP\php.ini
Press Enter to continue:

とりあえずそのままEnterします。


** WARNING! Old version found at C:\Program Files\PHP, please remove it or be su
re to use the new c:\program files\php\pear.bat command

The 'pear' command is now at your service at c:\program files\php\pear.bat


* WINDOWS ENVIRONMENT VARIABLES *
For convenience, a REG file is available under C:\Program Files\PHP\PEAR_ENV.reg
.
This file creates ENV variables for the current user.

Double-click this file to add it to the current user registry.

続行するには何かキーを押してください . . .

これでキー押すとコマンドプロンプトが閉じます。

後は、PHPインストールフォルダの
PEAR_ENV.reg
を実行すると、環境変数にPEAR周りのパスが登録されます。



■Net_SMTPクラスライブラリのインストール
後は、Net_SMTPクラスライブラリをインストールします。
まず、http://pear.php.net/package/Net_SMTP/downloadアーカイブをダウンロード。
そして、コマンドプロンプトで解凍したフォルダのパスへ移動し、

<pear install Net_SMTP-1.3.3


でインストールし Apache を再起動します。
※(追記)上のリンクからダウンロードしなくても、 pear install Net_SMTP-1.3.3 するだけで、pear自体がリポジトリから取ってきてくれるっぽいです。

これで、メールが送信できるようになるはずだったんですが、一つハマってしまいました。
それは、webapp\lib\util\mail_send.php を書き換えた時に、SMTP認証で入れたメールアドレスを、OPEN PNE の管理画面の SNS 設定の管理メールアドレスにしないと行けないということです。
SNS 設定の管理メールアドレスがメールでの from になるんでしょうが、smtp認証時に異なっていると、メールサーバによってはスパムとみなして送信できないっぽいです。
これにかなりの時間かかったので、気をつけましょう。


参考:
OKWave:SMTP.phpについて
PEARのインストール
PHP5.2とPEARのインストール手順
by jehoshaphat | 2009-08-21 18:48 | PHP開発


<< Webサイトの一部を別ドメイン... (MySQL)ログイン時のパス... >>