[Nature's Linux Tech Portal]  
 
Google
WWW を検索 tech.n-linux.com を検索 Wiki検索

WebDB-APM(LAMP)パッケージのセットアップTips †



テクニカルライター mami
2004/12/08
Nature's Linux Release 1.2 対応 2004/12/14
PHP 4.3.11パッケージ対応 2005/04/05
テクニカルノートコード:tcn00002

↑

はじめに †

 ここでは Apache, PHP, MySQL のインストールと設定方法について説明します。この作業は Nature's Linux で XOOPS をインストールする前、あるいはPHPでプログラミングをはじめる前に行う必要があります。

↑

WebDB-APM モジュールのインストール †

 ここでは、まず Nature's Linux のミドルウェア系パッケージである Nature's Linux on WebDB-APMをインストールします。このパッケージは Nature's Linux 上で WebとDBのサーバを動作させるためのパッケージであり、Apache, PHP, MySQL の最新の安定版が含まれています。

 このApacheはphp4_moduleを含み、PHPのスクリプトを実行するのに最適化されているものです。またPHPはMySQLとの接続に最適化されているものです。

 なお、WebDB-APM と共存できないパッケージは Nature's Linux on Web-A (Apacheの最新版が含まれているパッケージ)及び Nature's Linux on WebDB-APP(Apache, PHP, PostgreSQLの最新版が含まれているパッケージ)です。

 パッケージ間の衝突を知るには、 apt-get update && apt-cache depends nl-webdb-apm を実行します。 実行すると、WebDB-APM では、依存するパッケージとして

Depends: apache13-modssl
Depends: php4-mysql
Depends: mysql40 

WebDB-APM では、衝突するパッケージとして       

Conflicts: nl-web-a
Conflicts: nl-web-app   

と表示されます。衝突するパッケージが既にインストールされている場合には、先にそれらのパッケージを apt-get remove <パッケージ名> コマンドで削除してから WebDB-APM をインストールしてください(パッケージ管理については簡単リファレンスを参照してください)。なお、パッケージによってはインストール時に、インストールするパッケージと衝突するパッケージを自動的にアンインストールしてくれるものもあります。

 パッケージのインストールは以下のように行います。

  1. VFSに root でログインまたは、suコマンドでrootに変更します。
    login as: dev
    dev@10.99.7.102's password:
    Last login: Wed Oct 20 15:54:00 2004
    Nature's Linux BASE-OS Edition. Release 1.2
    [VFS-dev@tcng002 dev]$ su -
    Password:
    [VFS-root@tcng002 root]# 
  2. apt-get update を実行して、Nature's Linux の deb パッケージダウンロードサイトにアクセスし、使用可能な deb パッケージの情報をローカルディスク上に取得します。
    [VFS-root@tcng002 root]# apt-get update
    Get:1 ftp://packages.n-linux.com deb/ Packages [35.5kB]
    Get:2 ftp://packages.n-linux.com deb/ Release
    Ign ftp://packages.n-linux.com deb/ Release
    Get:3 ftp://packages.n-linux.com src/ Sources [18.8kB]
    Get:4 ftp://packages.n-linux.com src/ Release
    Ign ftp://packages.n-linux.com src/ Release
    Fetched 54.2kB in 1s (34.1kB/s)
    Reading Package Lists... Done
    [VFS-root@tcng002 root]#
  3. apt-get install nl-webdb-apm で Nature's Linux on WebDB-APM をインストールします。以下のようにメッセージが表示されますので、最後にYと入力するとインストールが始まります。
    [VFS-root@tcng002 root]# apt-get install nl-webdb-apm
    Reading Package Lists... Done
    Building Dependency Tree... Done
    The following extra packages will be installed:
      apache13-modssl libdbd-mysql libdbi-perl libmysql40 mysql40 php4-mysql
    The following NEW packages will be installed:
      apache13-modssl libdbd-mysql libdbi-perl libmysql40 mysql40 nl-webdb-apm
      php4-mysql
    0 upgraded, 7 newly installed, 0 to remove and 20 not upgraded.
    Need to get 11.7MB of archives.
    After unpacking 35.8MB of additional disk space will be used.
    Do you want to continue? [Y/n] y
    Get:1 ftp://packages.n-linux.com deb/ apache13-modssl 1.3.31+2.8.20-nl1 [1876kB]
    Get:2 ftp://packages.n-linux.com deb/ libmysql40 4.0.21-nl2 [177kB]
    Get:3 ftp://packages.n-linux.com deb/ libdbd-mysql 2.9004-nl1 [121kB]
    Get:4 ftp://packages.n-linux.com deb/ libdbi-perl 1.45-nl1 [588kB]
    Get:5 ftp://packages.n-linux.com deb/ mysql40 4.0.21-nl2 [5490kB]
    Get:6 ftp://packages.n-linux.com deb/ php4-mysql 4.3.9-nl1 [3437kB]
    Get:7 ftp://packages.n-linux.com deb/ nl-webdb-apm 1.0.0-nl1 [2738B]
    Fetched 11.7MB in 8s (1359kB/s)
    Selecting previously deselected package apache13-modssl.
    (Reading database ... 16389 files and directories currently installed.)
    Unpacking apache13-modssl (from .../apache13-modssl_1.3.31+2.8.20-nl1_i386.deb) ...
    Selecting previously deselected package libmysql40.
    Unpacking libmysql40 (from .../libmysql40_4.0.21-nl2_i386.deb) ...
    Selecting previously deselected package libdbd-mysql.
    Unpacking libdbd-mysql (from .../libdbd-mysql_2.9004-nl1_i386.deb) ...
    Selecting previously deselected package libdbi-perl.
    Unpacking libdbi-perl (from .../libdbi-perl_1.45-nl1_i386.deb) ...
    Selecting previously deselected package mysql40.
    Unpacking mysql40 (from .../mysql40_4.0.21-nl2_i386.deb) ...
    Selecting previously deselected package php4-mysql.
    Unpacking php4-mysql (from .../php4-mysql_4.3.9-nl1_i386.deb) ...
    Selecting previously deselected package nl-webdb-apm.
    Unpacking nl-webdb-apm (from .../nl-webdb-apm_1.0.0-nl1_i386.deb) ...
    Setting up apache13-modssl (1.3.31+2.8.20-nl1) ...
    
    Setting up libmysql40 (4.0.21-nl2) ...
    
    Setting up libdbd-mysql (2.9004-nl1) ...
    
    Setting up libdbi-perl (1.45-nl1) ...
    
    Setting up mysql40 (4.0.21-nl2) ...
    Preparing db table
    Preparing host table
    Preparing user table
    Preparing func table
    Preparing tables_priv table
    Preparing columns_priv table
    Installing all prepared tables
    041028  9:54:00 /opt/package/mysql40/libexec/mysqld: Shutdown Complete
    
    
    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:
    /opt/package/mysql40/bin/mysqladmin -u root password 'new-password'
    /opt/package/mysql40/bin/mysqladmin -u root -h tcng002 password 'new-password'
    See the manual for more instructions.
    
    You can start the MySQL daemon with:
    cd /opt/package/mysql40 ; /opt/package/mysql40/bin/mysqld_safe &
    
    You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
    cd sql-bench ; perl run-all-tests
    
    Please report any problems with the /opt/package/mysql40/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 https://order.mysql.com
    
    
    Setting up php4-mysql (4.3.9-nl1) ...
    Changed httpd.conf, Please, restart apache.
    
    Setting up nl-webdb-apm (1.0.0-nl1) ...
    
    [VFS-root@tcng002 root]#
  4. dpkg -l を実行して、表示されるパッケージリストに nl-webdb-apm が含まれていることを確認します。
    [VFS-root@tcng002 root]# dpkg -l | grep nl-
    ii  nl-vfsbase     1.0.3-nl1      Nature's Linux base files package for VFS.
    ii  nl-webdb-apm   1.0.0-nl1      This is the middleware appliance package of
    [VFS-root@tcng002 root]#
  5. 依存関係を確認してみます。
    [VFS-root@tcng002 root]# apt-cache depends nl-webdb-apm
    nl-webdb-apm
      Depends: apache13-modssl
      Depends: php4-mysql
      Depends: mysql40
      Conflicts: nl-web-a
      Conflicts: nl-webdb-app
    [VFS-root@tcng002 root]#
↑

Apacheの設定 &dagger;

 /opt/etc/apache13-modssl/httpd.confをviコマンドを使って編集します (注意:1.3.33+2.8.22-nl1以前のパッケージは /home/daemon/apache13-modssl/httpd.confとなります)。

[VFS-root@tcng002 root]# vi /opt/etc/apache13-modssl/httpd.conf

まず、以下の記述があることを確認します。それぞれ別の行にあります。

LoadModule      php4_module              libexec/libphp4.so
AddType         application/x-httpd-php  .php
DocumentRoot    "/var/data/apache13-modssl"

そして以下の箇所に

<IfModule mod_dir.c>
  DirectoryIndex  index.html
</IfModule>

index.php を追加します。

<IfModule mod_dir.c>
  DirectoryIndex  index.html index.php
</IfModule>

 httpd.conf を変更後、service apache statusを実行して、Apacheの状態を確認します。 httpd is stoppedと表示されたらservice apache start、 httpd (pid ... ) is running...と表示されたらservice apache reloadを実行します。

[VFS-root@tcng002 root]# service apache status
httpd is stopped
[VFS-root@tcng002 root]# service apache start
Starting apache:                                           [  OK  ]
[VFS-root@tcng002 root]#
↑

PHPの設定 &dagger;

 /opt/etc/php4/php.iniをviコマンドを使って編集します (注意:4.3.9-nl1以前のパッケージは/opt/package/php4-mysql/lib/php.iniとな ります。また、4.3.10以前では/opt/etc/php4-mysql/php.iniとなります)。

[VFS-root@tcng002 root]# vi /opt/etc/php4/php.ini

以下の箇所を編集します。それぞれ違う行にあります。

  • doc_root
    doc_root = 
    となっているところをhttpd.confのDocumentRootと同じディレクトリを設定します。
    doc_root = "/var/data/apache13-modssl"
↑

MySQLの設定 &dagger;

↑

root パスワードの設定 &dagger;

 MySQL がインストールされた直後では、MySQL の管理者ユーザである root のパスワードが設定されていません。そこでまず、root ユーザのパスワードを設定します。なお、root ユーザは MySQL全体の管理者です。

  1. service mysqld start を実行してMySQLを起動します。
    [VFS-root@tcng002 root]# service mysqld start
    Starting MySQL:                                            [  OK  ]
    [VFS-root@tcng002 root]#
  2. Nature's Linuxではmysqlユーザーが既に予約されて登録されていますが、MySQLを含むパッケージをインストールし、パスワードを設定して初めて適切に利用できるユーザーとなります。rootユーザーでmysqlユーザーのパスワードを設定します。
    [VFS-root@tcng000 root]# passwd mysql
    New UNIX password:
    Retype new UNIX password:
    passwd: password updated successfully
    [VFS-root@tcng000 root]#
  3. mysqlユーザにログインします。mysqlユーザはMySQLのコマンドが使えるようになっています。rootユーザーからmysqlユーザーになっても構いません。
    [VFS-root@tcng002 root]# su - mysql
  4. mysql -u root mysql と入力します。このコマンドは MySQL にパスワードなしの MySQLのroot ユーザとしてログインすることを意味します。ログインが成功すると、MySQL Monitor へのウェルカムメッセージが表示されます。
    [VFS-mysql@tcng002 mysql]$ mysql -u root mysql
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1 to server version: 4.0.21
    
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    
    mysql>
  5. MySQL プロンプトから set password for root=password('<パスワード>'); と入力して、root のパスワードを設定します。Query OK と表示されたら成功です。
    mysql> set password for root=password('nl-tech');
    Query OK, 0 rows affected (0.03 sec)
    
    mysql>
  6. MySQL プロンプトから flush privileges; と入力して、認証関連の変更を反映させます。Query OK と表示されたら成功です。
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>
  7. MySQL プロンプトから \q と入力して MySQL を一旦終了します。
    mysql> \q
    Bye
    [VFS-mysql@tcng002 mysql]$ 
  8. mysql ユーザーで mysql -p -u root mysql と入力します。パスワード入力を求められますので、先ほど設定したパスワードを入力します。上記のようなMySQL Monitor へのウェルカムメッセージが表示されたらログイン成功です。
    [VFS-mysql@tcng002 mysql]$ mysql -p -u root mysql
    Enter password:
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2 to server version: 4.0.21
    
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    
    mysql>
  9. MySQL プロンプトから \q と入力して MySQL を終了します。
    mysql> \q
    Bye
    [VFS-mysql@tcng002 mysql]$
↑

データベースの作成 &dagger;

 次にデータベースを作成します。XOOPS をインストールする場合にはこれが XOOPS 用インストールデータベースとなります。PHPを使う場合には、このデータベースに読み書きを行うことになります。

  1. mysql ユーザーで mysqladmin -p -u root create <データベース名> と入力します。パスワード入力を求められますので、先ほど設定した root のパスワードを入力します。ここでは例としてデータベース名をxoopsとしています。
    [VFS-mysqlt@tcng002 mysql]$ mysqladmin -p -u root create xoops
    Enter password:
    [VFS-mysql@tcng002 mysql]$
  2. データベース作成に成功した場合には、何もメッセージは出力されません。
  3. MySQL にログインし、MySQL プロンプトから show databases; と入力して、データベースが作成されていることを確認し、\qと入力してMySQLを終了します。
    [VFS-mysql@tcng002 mysql]$ mysql -p -u root mysql
    Enter password:
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 4 to server version: 4.0.21
    
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    
    mysql> show databases;
    +----------+
    | Database |
    +----------+
    | mysql    |
    | test     |
    | xoops    |
    +----------+
    3 rows in set (0.00 sec)
    
    mysql> \q
    Bye
    [VFS-mysql@tcng002 mysql]$
↑

ユーザーアカウントの作成 &dagger;

 今作成したデータベースはこのままでは root ユーザしかアクセスできません。セキュリティ上、全権限を持っている root ユーザをデータベースに日常的にアクセスするのに利用するのは危険ですので、データベースにアクセスできるユーザアカウントを別に作成します。

  1. mysql ユーザーで mysql -p -u root <データベース名> と入力します。パスワード入力を求められますので、先ほど設定したroot のパスワードを入力します。ログインに成功すると、MySQL Monitor へのウェルカムメッセージが表示されます。ここでは例としてデータベース名をxoopsとしています。
    [VFS-mysql@tcng002 mysql]$ mysql -p -u root xoops
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 5 to server version: 4.0.21
    
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    
    mysql>
  2. MySQL プロンプトから grant all on <データベース名>.* to <ユーザ名>@localhost identified by '<パスワード>'; と入力してユーザアカウント <ユーザ名>(例えば xoopsadm)を作成します。他のマシンからもデータベースをアクセスするのならば、<ユーザ名>@localhost の部分を適宜変更してからユーザアカウントを追加します。Query OK と表示されたら成功です。
    mysql> grant all on xoops.* to dev@localhost identified by 'nl-tech';
    Query OK, 0 rows affected (0.05 sec)
    
    mysql>
  3. MySQL プロンプトから flush privileges; と入力して、認証関連の変更を反映させます。Query OK と表示されたら成功です。
    mysql> flush privileges;
    Query OK, 0 rows affected (0.01 sec)
    
    mysql>
  4. mysql プロンプトから \q と入力して MySQL を一旦終了します。
    mysql> \q
    Bye
    [VFS-mysql@tcng002 mysql]$
  5. mysql ユーザーで mysql -p -u <ユーザ名> <データベース名> と入力します。パスワード入力を求められますので、先ほど設定したパスワードを入力します。上記のようなMySQL Monitor へのウェルカムメッセージが表示されたらログイン成功です。
    [VFS-mysql@tcng002 mysql]$ mysql -p -u dev xoops
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 7 to server version: 4.0.21
    
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    
    mysql>
  6. MySQL プロンプトから \q と入力して MySQL を終了します。
    mysql> \q
    Bye
    [VFS-mysql@tcng002 mysql]$ 

 XOOPS をインストールする際には、ここで設定したデータベース名とユーザアカウント名・パスワードを指定します。PHPを用いてデータベースに接続するときも同様です。

↑

動作確認 &dagger;

  1. Apache の動作確認はブラウザから http://<サーバ名> で apache のウェルカム画面が表示されればOKです。
    図1


  2. PHP の動作確認は、apache の Document Root 下に以下の記述があるファイル phpinfo.php を用意します。
    <?php phpinfo(); ?>
    http://<サーバ名>/phpinfo.php で PHP のバージョン情報や設定情報が表示されればOKです。
    図2


  3. MySQL の動作確認は、apache の Document Root 下に以下の記述があるファイル mysqltest.php を用意します。
    <html>
    <head><title>MySQL Connection Test</title></head>
    <body>
    <?php
         $connection=mysql_connect("localhost", "<ユーザ名>", <パスワード>")
         or die ("Connection Failed");
         echo("Connected to MySQL");
    ?>
    </body></html>
    http://<サーバ名>/mysqltest.php で"Connected to MySQL" と表示されればOKです。
    図3


↑

テクニカルライター紹介 &dagger;

mami.jpg テクニカルライター mami

東京在住。 ソフトウェアエンジニア。学生の頃は DEC System-20/Tops-20, DEC VAX-11/730/DCL, DEC VAX-11/780/Unix BSD, IBM 3090-200VF/VPS, Encore Multilmax/UMAX 4.3, Sun4-280/SunOS4.1 と MS-DOS なぞ 今は亡きマシンと戯れて過ごす。仕事ではUnixとWindowsを使い、 「既にある物をなるべく使う」「効率的に開発する」をポリシーに 直近では XOOPS、PHPやWikiを使ったサイト構築に従事。好きな動物は ペンギンとホッキョクグマ。先日、旭山動物園にて猛スピードで 泳ぎまくるTUX君とホッキョクグマを見てご満悦。現在フリー。




↑

この文章について &dagger;

本文書に関する著作権の保有について

Nature's Linux関連の記事は、著作権者であるジグソー株式会社がすべての権利を保有しています。

Copyright (C) 2003-2009 JIG-SAW, Inc. All rights reserved.

本書に記載されている会社名、製品名は、各社の登録商標または商標です。

記載の内容は予告無く変更される可能性があります。

また、この文書は、 クリエイティブ・コモンズ・ライセンス の下でライセンスされています。



 
 
 
 
 |  会社概要  |  企業ポリシー  |  お問い合わせ  |
Copyright (C) 2003-2009 JIG-SAW, Inc. All rights reserved.