プログラマ 福重 伸太朗 〜基本へ帰ろう〜 このページをアンテナに追加 RSSフィード

2008-10-21

coLinux に Apache,PHP,Postgresの開発環境構築メモ

what

Apache,PHP,Postgresの開発環境を coLinux に構築することになったのでメモ。



インストールするバージョン

2.0.63

4.4.8

  • Postgres

8.1.11



文字コード

EUC-JP



OS

% uname -a
Linux debian 2.6.22.18-co-0.7.3 #1 PREEMPT Sat May 24 22:27:30 UTC 2008 i686 GNU/Linux


postgres の install

http://www.stackasterisk.jp/tech/dataBase/postgresql01_01.jsp

$ sudo useradd postgres
$ cd /usr/local/src
$ sudo wget ftp://ftp.sra.co.jp/pub/cmd/postgres/8.1.11/postgresql-8.1.11.tar.gz
$ sudo tar zxf postgresql-8.1.11.tar.gz
$ cd postgresql-8.1.11
$ sudo ./configure --enable-multibyte=EUC_JP --with-perl
$ sudo make all
$ sudo make install
$ sudo chown postgres.postgres -R /usr/local/pgsql
$ sudo su - postgres
$ pwd
/var/lib/postgresql
$ touch .bash_profile
$ vi ~/.bash_profile
$ cat .bash_profile
export PATH="$PATH":/usr/local/pgsql/bin
export POSTGRES_HOME=/usr/local/pgsql
export PGLIB=$POSTGRES_HOME/lib
export PGDATA=$POSTGRES_HOME/data
export MANPATH="$MANPATH":$POSTGRES_HOME/man
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$PGLIB"
$ source ~/.bash_profile
$ initdb --encoding=EUC_JP --no-locale
$ pg_ctl -o "-S -i" start
postmaster starting
$ vi /usr/local/pgsql/data/pg_hba.conf
### pg_hba.conf は変更しませんでした ###
$ exit
$ whoami
fuku
$ sudo vi /etc/rc.local
$ cat /etc/rc.local    
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
su - postgres -c "pg_ctl -o \"-S -i\" start"
exit 0
$ sudo cp /usr/local/src/postgresql-8.1.11/contrib/start-scripts/linux /etc/init.d/postgresql
$ sudo chmod 755 /etc/init.d/postgresql
$ sudo /etc/init.d/postgresql restart
Restarting PostgreSQL: postmaster stopped
ok

psql で問い合わせしてみると、以下のようなエラーメッセージがでる。

debian:/home/fuku# su postgres  
postgres@debian:/home/fuku$ psql -l
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
       LANGUAGE = (unset),
       LC_ALL = (unset),
       LANG = "ja_JP.UTF-8"
   are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
psql: could not connect to server: No such file or directory
       Is the server running locally and accepting
       connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
postgres@debian:/home/fuku$

どうも、ロケールに不具合があるようす。

http://osb.sra.co.jp/PostgreSQL/Manual/PostgreSQL-7.1-ja/charset.html

postgres@debian:/home/fuku$ perl -v
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
       LANGUAGE = (unset),
       LC_ALL = (unset),
       LANG = "ja_JP.UTF-8"
   are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
 
This is perl, v5.8.8 built for i486-linux-gnu-thread-multi
 
Copyright 1987-2006, Larry Wall
 
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
 
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
 
postgres@debian:/home/fuku$


http://omake.accense.com/wiki/DebianPerlLocaleError?format=txt

$ sudo dpkg-reconfigure locales
Generating locales (this might take a while)...
 ja_JP.EUC-JP... done
 ja_JP.UTF-8... done
Generation complete.

「`ja_JP.UTF-8`」と「`ja_JP.EUC-JP`」の両方をチェック。


ロケールのエラーがでなくなった。

[fuku@debian ~]$ perl -v
 
This is perl, v5.8.8 built for i486-linux-gnu-thread-multi
 
Copyright 1987-2006, Larry Wall
 
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
 
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.


  • 再び、psql で問い合わせてみる。
[fuku@debian ~]$ su
Password:
debian:/home/fuku# su postgres
postgres@debian:/home/fuku$ psql -l
psql: could not connect to server: そのようなファイルやディレクトリはありません
       Is the server running locally and accepting
       connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

ロケールのエラーは消えたが、「そのようなファイルやディレクトリはありません」といったエラーがでた。




  • 解決策

http://tomo.ac/goodstream/database/postgresql/linux/tips/netconn.htm

「-h オプションで、データベースを置いているホストを指定する」


postgres@debian:/home/fuku$ psql -l -h localhost
       List of databases
  Name    |  Owner   | Encoding
-----------+----------+----------
postgres  | postgres | EUC_JP
template0 | postgres | EUC_JP
template1 | postgres | EUC_JP
(3 rows)

できた。




毎度打つのは面倒なので、 -h localhost を省略する。

以下の行を /var/lib/postgresql/.bash_profile に追加する。

export PGHOST=localhost

  • 実験
$ sudo su - postgres
postgres@debian:~$ psql -l
        List of databases
   Name    |  Owner   | Encoding 
-----------+----------+----------
 template0 | postgres | EUC_JP
 template1 | postgres | EUC_JP
(2 rows)

OK


apache の install

http://www.atmarkit.co.jp/flinux/rensai/apache03/apache03b.html

http://kepietro.dip.jp/index.php?Apache%A5%A4%A5%F3%A5%B9%A5%C8%A1%BC%A5%EB

2.0.55 を入れたかったが、落ちてないので、 2.0.63 を入れる

$ cd /usr/local/src
$ sudo wget http://www.apache.jp/dist/httpd-2.0.63.tar.gz
$ sudo tar zxvf httpd-2.0.63.tar.gz
$ cd httpd-2.0.63
$ sudo ./configure --enable-so --enable-rewrite --enable-ssl
$ sudo make
$ sudo make install
$ sudo install -o root -g root -m 755 /usr/local/apache2/bin/apachectl /etc/init.d/apache


  • /usr/local/apache2/conf/httpd.conf の修正 (修正箇所を表示)
#ServerName www.example.com:80
↓
ServerName 10.20.138.175:80
DocumentRoot "/usr/local/apache2/htdocs"
↓
DocumentRoot "/var/samba/public"

$ sudo /etc/init.d/apache start

起動問題なし。




PHP の install

$ cd /usr/local/src
$ sudo wget http://jp2.php.net/get/php-4.4.8.tar.gz/from/jp.php.net/mirror
$ sudo tar zxvf php-4.4.8.tar.gz
$ cd php-4.4.8
$ sudo ./configure '--enable-mbstring' '--enable-mbstr-enc-trans' '--enable-mbregex' '--with-config-file-path=/etc' '--with-zlib' '--with-mysql' '--with-pgsql' '--with-apxs2=/usr/local/apache2/bin/apxs'
$ sudo make
$ sudo make install
$ php -v
PHP 4.4.8 (cli) (built: Oct 23 2008 08:22:46)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
$ sudo cp /usr/local/src/php-4.4.8/php.ini-dist /etc/php.ini

完了。



  • /usr/local/lib/php.ini の編集
- y2k_compliance = On
+ y2k_compliance = Off

- output_buffering = On
+ output_buffering = Off

- max_execution_time = 30
+ max_execution_time = 300

+warn_plus_overloading = Off

- upload_max_filesize = 2M
+ upload_max_filesize = 5M

- ;extension=php_imap.dll
+ extension=php_imap.dll

+ [Sockets]
+ ; Use the system read() function instead of the php_read() wrapper.
+ sockets.use_system_read = On

- ;mbstring.http_output = SJIS
+ mbstring.http_output = SJIS

- output_buffering = Off
+ output_buffering = On
 
- ;output_handler =
+ output_handler = mb_output_handler
 
- ;default_charset = "iso-8859-1"
+ default_charsert = "EUC-JP"
 
- ;session.save_path = /tmp
+ session.save_path = /tmp/php
 
- ;mbstring.language = Japanese
+ mbstring.language = Japanese
 
- ;mbstring.internal_encoding = EUC-JP
+ mbstring.internal_encoding = EUC-JP
 
- ;mbstring.http_input = auto
+ mbstring.http_input = auto
 
- ;mbstring.encoding_translation = Off
+ mbstring.encoding_translation = On
 
- ;mbstring.detect_order = auto
+ mbstring.detect_order = auto
 
- ;mbstring.substitute_character = none;
+ mbstring.substitute_character = none;

  • /usr/local/apache2/conf/httpd.conf の修正
- #LoadModule php4_module        modules/libphp4.so
+ LoadModule php4_module        modules/libphp4.so

+ AddType application/x-httpd-php .php

- DirectoryIndex index.html index.html.var
+ DirectoryIndex index.php index.html index.htm index.html.var


これで完了