top
Vine3.2でPostgresql、PHP、Apache構成
余裕のある人はアフィリエイトページ商品紹介をご覧になるのもいいかも。掘り出し物はあるかな。バナー集はこちら
参考にしたサイト
http://collie.low-temp.sci.yamaguchi-u.ac.jp/~ashida/comp/psql.html
http://www.miloweb.net/postgresql.html
http://toto3.com/toto/linux/fedoracore2_postgresql.html
vine3.2のインストール 日立FLORA 128MBにインストール
boot: text でインストール

カスタム を選択 
下記追加した。
X Windowシステム
日本語入力システム
GNOMEデスクトップ
インターネットクライアント
Emacsエディタ
FTPサーバー・・・・いずれ必要になるので。それに今回のテーマではないので。
基本開発ソフト
その他のソフト
Shells
システム管理ツール

ログインはグラフィック、色(16bit) 1024X768。
・・・・インターネットからファイルを取得するにはいいです。
インストール後
vi /etc/apt/sources.listで extras 追加
vi /etc/proftpd.confでanonymousFTPに#をつける
   DefaultRoot   ~/
   UseReverseDNS off
   IdentLookups   off
vi /etc/hosts.deny  ALL:ALL
vi /etc/hosts.allow  proftpd:ALL, ALL:192.168.1.0/255.255.255.0 , ALL:localhost

Synapticを利用してUpdate,Upgrade、dist-upgradeした

postgresql
postgresql-server
postgresql-libs
インストール
php、php-apache、php-postgresql インストール

最後にapt-get update
    apt-get upgarade
     apt-get dist-upgarde
を行った。
これは Synapticと aptコマンドでは少し異なるような感じがしたので。
http://www.miloweb.net/postgresql.htmlを手本にして進めた。
PostgreSQL を起動してみます。
この起動により、データベースの初期化、必要なファイルの生成や各種設定を自動的に行ってくれる様です。

root]# /etc/rc.d/init.d/postgresql start
データベースを初期化中: [ OK ]
Starting postgresql service: [ OK ]
PostgreSQL の最高権限を持つpostgres 」ユーザにパスワードを設定します
[root@kdk45 gotsu]# passwd postgres
Changing password for user postgres.
New password:
BAD PASSWORD: it is too short ・・・・短すぎると怒られました。
Retype new password:
Sorry, passwords do not match
New password:XXXXXXX・・・・・・・・・少し長い文字列にしました
Retype new password:
passwd: all authentication tokens updated successfully.

ネットワーク経由でデータベースにアクセスするので、
TCP/IP 通信の許可を設定します。

/var/lib/pgsql/data/postgresql.conf を編集します。
編集個所は 2630 行目です。

#tcpip_socket = false
tcpip_socket = true

続いて同じ階層にある pg_hba.conf を編集します。
フルパスは /var/lib/pgsql/data/pg_hba.conf になります。
編集個所は 245 行目です。

#host all 127.0.0.1 255.255.255.255 trust を host all 127.0.0.1 255.255.255.255 trust に変更します。(コメントを取るだけです)
となっているがvine3.2では53行に

# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
host all all 127.0.0.1 255.255.255.255 trust とあったのでそのままとした。

上記 2 つのファイルが編集できたら、PostgreSQL を再起動します。

# /etc/rc.d/init.d/postgresql restart

[root@kdk45 gotsu]# /etc/rc.d/init.d/postgresql restart
Stopping postgresql service: [ OK ]
Starting postgresql service: [ OK ]

そして、Linuxの一般ユーザ( 例として hoge さん )に PostgreSQL の実行権限を与えます。
su postgres

とやったら
[root@kdk45 root]# su postgres
bash-2.05b$

となってしまった。・・・・Bash-2.05bが不足ということらしいと思ってSynapticで見たらインストールされている、困った。googleで「bash-2.05b 使い方」 で検索したら
bash-2.05b$ の次にコマンドを打ち込むということだった。(恥)


http://toto3.com//toto/linux/fedoracore2_postgresql.html に
#su - postgres・・・postgresユーザになる
-bash-2.05b$ psql template ・・・psqlコマンドでpostgresqlに接続 と書いてあった。

[root@kdk45 root]# su - postgres
-bash-2.05b$ psql template1
PostgreSQL の会話型ターミナル、psql 7.4.10 へようこそ

\copyright とタイプすると、配布条件を表示します。
\h とタイプすると、SQL コマンドのヘルプを表示します。
\? とタイプすると、内部スラッシュコマンドのヘルプを表示します。
\g と打つかセミコロンで閉じると、クエリーを実行します。
\q で終了します。
template1=# \q
-bash-2.05b$ exit ・・・・・一応\qで終了してbash-2.05bからrootに戻るために exit と入力
logout
[root@kdk45 root]#

一般ユーザpostgresuser01 をpostgresqlに登録するため 
#mkdir /home/postgresuser01
#adduser -d /home/postgresuser01 postgresuser01
chown postgresuser01 /home/postgresuser01
としておいて

[root@kdk45 root]# su - postgres
-bash-2.05b$ createuser -AdPE postgresuser01
Enter password for new user:
Enter it again:
CREATE USER

データベースサーバー認証設定ファイル編集
-bash-2.05b$ vi /var/lib/pgsql/data/pg_hba.conf

# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD

local all all trust
# IPv4-style local connections:
host all all 127.0.0.1 255.255.255.255 trust
host all all 192.168.1.0 255.255.255.0 trust ・・・・LAN内部からのアクセスは無条件に許可
(host all all 0.0.0.0 0.0.0.0 password crypt ・・・・・上記以外からのアクセスはパスワード認証で許可)
:wq

-bash-2.05b$ exit
logout
[root@kdk45 root]# /etc/rc.d/init.d/postgresql restart
Stopping postgresql service: [ OK ]
Starting postgresql service: [ OK ]

[root@kdk45 root]#

http://toto3.com//toto/linux/fedoracore2_postgresql.html によるここまで


postgresuser02を作ってみる

まずlinuxの一般ユーザを/homeに作る
#mkdir /home/postgresuser02
#useradd -d /home/postgresuser02 postgresuser02
chown postgresuser02 /home/postgresuser02

#su - postgres


$ createuser hoge
Shall the new user be allowed to create databases? (y/n) y <-- 新しいデータベースの作成権限を与える
Shall the new user be allowed to create more new user? (y/n) n <-- ユーザの追加権限は与えない
CREATE USER <-- 正常にユーザーを作成した証。この表示が無いとユーザの作成は失敗しています。

[root@kdk45 root]# mkdir /home/postgresuser02
[root@kdk45 root]# useradd -d /home/postgresuser02 postgresuser02
[root@kdk45 root]# chown postgresuser02 /home/postgresuser02
[root@kdk45 root]# su - postgres
-bash-2.05b$ createuser postgresuser02
Shall the new user be allowed to create databases? (y/n) y
Shall the new user be allowed to create more new users? (y/n) n
CREATE USER
-bash-2.05b$

再びhttp://www.miloweb.net/postgresql.htmlを手本にして進めた。
# su - hoge
$ createdb sampledb
CREATE DATABASE <-- 正常にデータベースを作成した証
を参考に
[root@kdk45 root]# su - postgresuser01
[postgresuser01@kdk45 postgresuser01]$ createdb sampl
edb
CREATE DATABASE

作成したデータベースを削除してみる
[postgresuser01@kdk45 postgresuser01]$ dropdb sampled
b
DROP DATABASE
ここまでは順調だったが

次にテーブルを作成します。
テーブルの作成方法は、psql コマンドを用いても作成できますが、
面倒だったのであらかじめテーブルを作成する SQL を記述したファイルを読み込ませ、テーブルを作成する方法を取る事にしました。

新規で SampleTable.sql というファイルを作成する。
中身は以下の通り。

drop table SampleTable;
CREATE TABLE SampleTable (
    No integer,
    Name varchar(20)
);

テーブルを作成する。

$ psql -f SampleTable.sql sampledb
CREATE <-- 正常にテーブルを作成した証

これで、エラーが出なかったら、成功です。
確認してみましょう。

---------上のとおりやってみました
[postgresuser01@kdk45 postgresuser01]$ vi SampleTable.sql

drop table
SampleTable;
CREATE
TABLE
SampleTable(
No integer,
Name varchar(20)
);

:wq

[postgresuser01@kdk45 postgresuser01]$ psql -f SampleTable.
sql sampledb
psql:SampleTable.sql:2: ERROR: table "sampletable" does not exist
CREATE TABLE
[postgresuser01@kdk45 postgresuser01]$ psql -n sampledb
PostgreSQL の会話型ターミナル、psql 7.4.10 へようこそ

\copyright とタイプすると、配布条件を表示します。
\h とタイプすると、SQL コマンドのヘルプを表示します。
\? とタイプすると、内部スラッシュコマンドのヘルプを表示します。
\g と打つかセミコロンで閉じると、クエリーを実行します。
\q で終了します。

sampledb=> \d SampleTable
テーブル "public.sampletable"
カラム | 型 | 修飾語
--------+-----------------------+--------
no | integer |
name | character varying(20) |

sampledb=> INSERT INTO sampleTable(no,name) VALUES(1,'GODZILLA');
INSERT 17146 1
sampledb=> SELECT * FROM SampleTable;
no | name
----+----------
1 | GODZILLA・・・・・・・データが登録されています。
(1 行)

sampledb=> \q
[postgresuser01@kdk45 postgresuser01]$
Web 上からアクセス可能にする
vine3.2ではapacheになっている
[root@kdk45 root]# su - postgres
-bash-2.05b$ createuser apache
Shall the new user be allowed to create databases? (y/n) n
Shall the new user be allowed to create more new users? (y/n) n
CREATE USER
-bash-2.05b$
[root@kdk45 root]# su - postgresuser01
[postgresuser01@kdk45 postgresuser01]$ psql -n SampleDB
psql: FATAL: database "SampleDB" does not exist・・・・大文字でエラー
小文字にして再度実施

[postgresuser01@kdk45 postgresuser01]$ psql -n sampledb
PostgreSQL の会話型ターミナル、psql 7.4.10 へようこそ

\copyright とタイプすると、配布条件を表示します。
\h とタイプすると、SQL コマンドのヘルプを表示します。
\? とタイプすると、内部スラッシュコマンドのヘルプを表示しま す。
\g と打つかセミコロンで閉じると、クエリーを実行します。
\q で終了します。

sampledb=> grant all on sampletable to apache;
GRANT
sampledb=> \q
10 [root@kdk45 root]# chkconfig postgresql on ・・・ここは一連の作業が済んでから実施
最初にやっておくべきかな〜
一応これで最小限のpostgresql環境は出来たらしいのです。
あとは買ってあった本に沿って進めたいと思います。