#topicpath
----
#contents
----
* LAMP環境 [#o7384274]

CentOS5.2 (64bit) にて、お手軽にLAMP環境を作ります。

- Linux
- Apache
- MySQL
- Perl/PHP/Python

動作検証のために、
[[MovableType 4.21:http://www.ecbuyers.com/b2c/catalog/default.php?cPath=28_127]]
を入れてみます。

* インストールの指針 [#h0cee977]

それぞれ必要そうなパッケージを探し、要るものをインストールします。

* Apache [#z8951d87]

#pre{{
[root@localhost ~]# yum search httpd
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
 * base: ftp.oss.eznetsols.org
 * updates: ftp.oss.eznetsols.org
 * addons: ftp.oss.eznetsols.org
 * extras: ftp.oss.eznetsols.org
httpd-devel.i386 : Development tools for the Apache HTTP server.
httpd-devel.x86_64 : Development tools for the Apache HTTP server.
httpd-manual.x86_64 : Documentation for the Apache HTTP server.
httpd.x86_64 : Apache HTTP Server
mod_ssl.x86_64 : SSL/TLS module for the Apache HTTP server
system-config-httpd.noarch : Apache configuration tool
mod_dav_svn.x86_64 : Apache server module for Subversion server.
httpd.x86_64 : Apache HTTP Server
}}

インストールします。

#pre{{
[root@localhost ~]# yum install httpd httpd-manual mod_ssl 
...

Transaction Summary
=============================================================================
Install      3 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Total download size: 2.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): httpd-manual-2.2.3 100% |=========================| 832 kB    00:02     
(2/3): mod_ssl-2.2.3-11.e 100% |=========================|  85 kB    00:00     
(3/3): httpd-2.2.3-11.el5 100% |=========================| 1.1 MB    00:02     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: httpd                        ######################### [1/3] 
  Installing: mod_ssl                      ######################### [2/3] 
  Installing: httpd-manual                 ######################### [3/3] 

Installed: httpd-manual.x86_64 0:2.2.3-11.el5_1.centos.3 mod_ssl.x86_64 1:2.2.3-11.el5_1.centos.3
Dependency Installed: httpd.x86_64 0:2.2.3-11.el5_1.centos.3
Complete!
}}

* MySQL [#ed0b3bf3]

同じように探します。

#pre{{
[root@localhost ~]# yum search mysql
...
}}

必要なものをインストールします。
他のモジュールとの連携をすることも考慮して選択しましょう。

#pre{{
[root@localhost ~]# yum install mysql mysql-server perl-DBD-MySQL php-mysql MySQL-python
...
}}

* Perl/PHP/Python [#xb89fcef]

これも同様です。

Perl や Python はインストールされているままで使い、
さらに追加で次のパッケージをインストールしました。

#pre{{
[root@localhost ~]# yum install php php-mbstring 
...
}}

* 動作確認 [#tce5d944]

それぞれ起動してみます。

** MySQL [#w3bd45db]

設定ファイルは /etc/my.cnf にあります。
内容を一応確認してから、起動スクリプトを実行してみます。

#pre{{
[root@localhost ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
}}

#pre{{
[root@localhost ~]# /etc/init.d/mysqld start
MySQL データベースを初期化中:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
                                                           [  OK  ]
MySQL を起動中:                                            [  OK  ]
}}

起動したということで、動作確認してみます。
ここにも書いてありますが、ちゃんと使うにはパスワードを設定してからにしましょう。

#pre{{
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema | 
| mysql              | 
| test               | 
+--------------------+
3 rows in set (0.00 sec)

mysql> \q
Bye
}}

** Apache + PHP [#dadc72ea]

PHP の設定ファイルは /etc/php.ini です。
日本語のため、mbstring 周りを設定します。
下記の行について先頭の ";" を外して有効化しました。

#pre{{
[mbstring]
mbstring.language = Japanese
mbstring.internal_encoding = EUC-JP
mbstring.http_input = auto
mbstring.http_output = SJIS
mbstring.encoding_translation = Off
mbstring.detect_order = auto
mbstring.substitute_character = none;
mbstring.func_overload = 0
mbstring.strict_encoding = Off
}}

Apache httpd から読まれるのは /etc/httpd/conf.d/php.conf ですが、
これは特に変更の必要はありません。

httpd を起動します。

#pre{{
[root@localhost ~]# /etc/init.d/httpd start
httpd を起動中:                                            [  OK  ]
}}

正しく起動したら、ブラウザからアクセスしてみます。

&ref(httpd.png,,50%);

PHP についても確認してみましょう。
確認用に phpinfo.php を1行書きます。

#pre{{
[root@localhost ~]# cat /var/www/html/phpinfo.php
<? phpinfo(); ?>
}}

同様にブラウザからアクセスします。
http://(IPアドレス)/phpinfo.php です。

&ref(php.png,,50%);

設定された環境が表示されるので、一通り確認します。
mbstring の日本語周りや、MySQL のドライバなどを見ましょう。

確認できたらこの phpinfo.php は消しておきます。

* MovableType 4.21 [#v8922740]

まずインストール先として、
httpd で /cgi-bin/ として設定されているディレクトリを探します。

#pre{{
[root@localhost ~]# grep ^ScriptAlias /etc/httpd/conf/httpd.conf 
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
}}

ダウンロードしてきたMTを展開し、cgi-bin/mt として設置します。

#pre{{
[root@localhost ~]# unzip MT-4_21-ja.zip 
...
[root@localhost ~]# mv MT-4.21-ja /var/www/cgi-bin/mt
[root@localhost ~]# chmod 755 /var/www/cgi-bin/mt
}}

/etc/httpd/conf.d/mt.conf を編集して、
CGI として動かすための設定をします。
このディレクトリに置けば httpd の起動時に httpd.conf から読み込まれます。

#pre{{
[root@localhost ~]# cat /etc/httpd/conf.d/mt.conf 
AddHandler cgi-script .cgi
Alias /cgi-bin/mt/ "/var/www/cgi-bin/mt/"

<Directory "/var/www/cgi-bin/mt">
    AllowOverride None
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>
}}

httpd を再起動して、ブラウザから http://(IPアドレス)/cgi-bin/mt/ にアクセスします。

#pre{{
[root@localhost ~]# /etc/init.d/httpd restart
httpd を停止中:                                            [  OK  ]
httpd を起動中:                                            [  OK  ]
}}

&ref(mt-1.png,,50%);

しばらく経つと画面が切り替わります。

&ref(mt-2.png,,50%);

ウィザードを進めていくと、MySQL のデータベースを用意する必要があることがわかります。
MT用のデータベースと、接続用のユーザを作成します。

#pre{{
[root@localhost ~]# mysql 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE DATABASE mt CHARACTER SET ujis;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT all ON mt.* TO mtuser IDENTIFIED BY 'mtuser';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
}}

- データベース : mt
- 接続ユーザ : mtuser
- パスワード : mtuser

として作成しました。接続できることを確認します。

#pre{{
[root@localhost ~]# mysql -h localhost -u mtuser -p -D mt
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
}}

この情報を元に、MT に設定を入力します。

&ref(mt-3.png,,50%);

設定が終わったら mt-config.cgi が生成されるので、
/var/www/cgi-bin/mt/mt-config.cgi として書き込み、
実行権限をつけます。

#pre{{
[root@localhost ~]# vi /var/www/cgi-bin/mt/mt-config.cgi
...
[root@localhost ~]# chmod +x /var/www/cgi-bin/mt/mt-config.cgi
}}

ブログを作成する設定に進んだら、必要なディレクトリを作ります。

#pre{{
[root@localhost ~]# mkdir -p /var/www/html/my_first_blog
[root@localhost ~]# chown apache:apache /var/www/html/my_first_blog
}}

その後データベースなどの設定が進み、ちゃんと終了すれば
MovableType が使えるようになりました。

このように記事を書いていくことができます。

&ref(mt-4.png,,50%);

正しく運用するには画像表示のためのディレクトリへの設定など、
他にも httpd で必要なものもあります。
/etc/httpd/conf.d/mt.conf で設定していきましょう。

----
#comment

トップ   差分 履歴 リロード   一覧 検索 最終更新   ヘルプ   最終更新のRSS