PostgreSQL+PHP+Apache¥¤¥ó¥¹¥È¡¼¥ë

Ãí°Õ»ö¹à

¥Ð¡¼¥¸¥ç¥ó8.1.4, 8.0.8, 7.4.13, 7.3.15°ÊÁ°¤Î¥Ð¡¼¥¸¥ç¥ó¤Ë¤Ï¥Þ¥ë¥Á¥Ð¥¤¥È½èÍý¤ËSQL¥¤¥ó¥¸¥§¥¯¥·¥ç¥ó¤ÎÀȼåÀ­¤¬¤¢¤ê¤Þ¤¹¡£
¾ÜºÙ(SRA OSS)
¾ÜºÙ(ITpro)

PostgreSQL¤Î¥¤¥ó¥¹¥È¡¼¥ë

PostgreSQL,PHP,Apache¤ÎRPM¤ÏÁ´¤Æºï½ü¤·¤Æ¤ª¤­¤Þ¤¹
¥Ð¡¼¥¸¥ç¥ó¥¢¥Ã¥×¤¹¤ë¾ì¹ç¤Ï¥Ð¥Ã¥¯¥¢¥Ã¥×¤ò¼è¤Ã¤Æ»ß¤á¤Æ¤ª¤­¤Þ¤·¤ç¤¦

postgres ¥æ¡¼¥¶¡¼¤ÎºîÀ®

# /usr/sbin/useradd -d /usr/local/pgsql postgres
# chmod 755 /usr/local/pgsql

ºî¶È¥Ç¥£¥ì¥¯¥È¥êºîÀ®

# mkdir /usr/local/src/postgresql-7.4.9
# chown postgres /usr/local/src/postgresql-7.4.9

¥½¡¼¥¹¼èÆÀ http://www.postgresql.jp/

# su postgres
$ tar xvzf postgresql-7.4.9.tar.gz
$ cd postgresql-7.4.9
$ ./configure

7.3°Ê¹ß¤Ï¥Þ¥ë¥Á¥Ð¥¤¥È¥µ¥Ý¡¼¥È¤Ï¥Ç¥Õ¥©¥ë¥È¤ÇÍ­¸ú¤Ë¤Ê¤ë
¥í¥°¤ò¼è¤ë¤È¤­¤Ï --enable-syslog ODBCÀܳ¤¹¤ë¾ì¹ç¤Ï --enable-odbc --with-unixodbc
JDBC¥É¥é¥¤¥Ð¤ò¥Ó¥ë¥É¤¹¤ë¾ì¹ç¤Ï --with-java ¤Ç¤âANT1.5°Ê¾å¤¬¤¤¤ë¤é¤·¤¤
--without-readline ¤ò»ØÄꤷ¤í¤È¤«¸À¤ï¤ì¤ë¤È readline-devel ¤È libtermcap-devel ¤òÆþ¤ì¤Æ¤ß¤è¤¦

$ make all
$ make check
$ make install

¥Ð¡¼¥¸¥ç¥ó¤ò¾å¤²¤ë¤È¥¨¥é¡¼¤¬½Ð¤Æmake check¤¬¤Ç¤­¤Ê¤¤¤³¤È¤¬¤¢¤ë
¤³¤ì¤Ï¸Å¤¤libpq.so¤¬»Ä¤Ã¤Æ¤¤¤ë¤«¤é¤é¤·¤¤

# rm -fr /usr/local/pgsql/lib

¤Ê¤É¤È¤·¤Æºï½ü¤·¤Á¤ã¤¤¤Þ¤·¤ç¤¦

contrib´ØÏ¢¤Î¥¤¥ó¥¹¥È¡¼¥ë

Ê̤˥¤¥ó¥¹¥È¡¼¥ëɬÍפϤ¢¤ê¤Þ¤»¤ó
bison¤¬É¬ÍפǤ¹

$ su postgres
$ cd /usr/local/src/postgresql-7.4.9/contrib
$ gmake all
$ gmake install

¥Ñ¥¹¤ÎÀßÄê

postgres¤ÈPostgreSQL¤ò»ÈÍѤ¹¤ë¥æ¡¼¥¶¡¼Á´¤Æ¤Î.bashrc¤Ë°Ê²¼¤òÄɲÃ

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 ~/.bashrc

¥Ç¡¼¥¿¥Ù¡¼¥¹½é´ü²½

$ initdb --encoding=EUC_JP --no-locale

°ì¹ÔÄɲÃ

# vi /etc/ld.so.conf
/usr/local/pgsql/lib
# /sbin/ldconfig

¼«Æ°µ¯Æ°¤ÎÀßÄê

# cp /usr/local/src/postgresql-7.4.9/contrib/start-scripts/linux /etc/rc.d/init.d/postgresql
# chmod 755 /etc/rc.d/init.d/postgresql
# /sbin/chkconfig --add postgresql
# /etc/rc.d/init.d/postgres start

Pg.pm¤Î¥¤¥ó¥¹¥È¡¼¥ë

Pg.pm¤Ï7.3¤«¤éÊÌ´ÉÍý¤Ë¤Ê¤Ã¤¿¤½¤¦¤Ê
Perl¤«¤éPg.pm¤ÇÀܳ¤¹¤ë¾ì¹ç¤Ï°Ê²¼¤ò¼Â¹Ô

http://gborg.postgresql.org/project/pgperl/download/download.php

Pg-2.1.1.tar.gz

# tar xvzf Pg-2.1.1.tar.gz
# cd Pg-2.1.1
# POSTGRES_HOME=/usr/local/pgsql
# export POSTGRES_HOME
# perl Makefile.PL
# make
# make install

syslog´ØÏ¢ÀßÄê

»²¹Í¥µ¥¤¥È

$ vi /usr/local/pgsql/data/postgresql.conf
log_connections = true # Àܳ¥í¥°¤ò»Ä¤¹
log_statement = true # Á´¤Æ¤ÎSQLʸ¤òµ­Ï¿
debug_print_parse = true # ¥Ñ¡¼¥¹¥Ä¥ê¡¼¤ò½ÐÎϤ·¤Þ¤¹
debug_print_rewritten = true # ½ñ¤­´¹¤¨¸å¤Î¥Ñ¡¼¥¹¥Ä¥ê¡¼¤ò½ÐÎϤ·¤Þ¤¹
debug_print_plan = ture # Ìä¹ç¤»¥×¥é¥ó¤ò½ÐÎϤ·¤Þ¤¹
syslog = 2 # ½ÐÎϤòÀ©¸æ¤·¤Þ¤¹(0:½ÐÎϤʤ· 1:syslog¤Èstdout¤Ë½ÐÎÏ 2:syslog¤Î¤ß¤Ë½ÐÎÏ)
syslog_facility = 'LOCAL0' 
# /etc/rc.d/init.d/postgres restart

PostgreSQL¤Î¥í¥°¥Õ¥¡¥¤¥ë¤ÏÊ̤ËÅǤ­½Ð¤¹¤è¤¦¤ËÀßÄê

$su
# vi /etc/syslog.conf
local0.* /var/log/postgres # ¾¤Ëlocal0¤ò»È¤Ã¤Æ¤¤¤Ê¤¤¤«Ãí°Õ
# ps ax | grep syslog
# kill -HUP Ä´¤Ù¤¿syslogd¤ÎPID

¥í¥°¥í¡¼¥Æ¡¼¥·¥ç¥óÀßÄê

# vi /etc/logrotate.d/postgres
"/var/log/postgres"
{
   rotate 4
   weekly
   sharedscripts
   postrotate
     /usr/bin/killall -HUP syslogd
   endscript
}

Apache¤Î¥¤¥ó¥¹¥È¡¼¥ë

http://www.apache.or.jp/

# tar xvzf apache_1.3.34.tar.gz
# cd apache_1.3.34
# OPTIM="-O2" ./configure --enable-module=so --enable-module=rewrite
# make
# make install

Options

FollowSymLinks¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤òÍ­¸ú
Indexes¥Ç¥£¥ì¥¯¥È¥êÆâ´Ý¸«¤¨
IncludesSSIÍ­¸ú
ExecCGICGIÍ­¸ú
MultiViews¥Ö¥é¥¦¥¶¤òȽÄê(?)

AllowOverride

AuthConfigǧ¾ÚÍ­¸ú
FileInfo¥É¥­¥å¥á¥ó¥È¥¿¥¤¥×¤Î¥Ç¥£¥ì¥¯¥Ç¥£¥Ö»ÈÍѵö²Ä
Indexes¥Ç¥£¥ì¥¯¥È¥ê¥¤¥ó¥Ç¥Ã¥¯¥¹À©¸æ
Limit¥Û¥¹¥È¤Ø¤Î¥¢¥¯¥»¥¹À©¸æ

Apache¤Î¥Ð¡¼¥¸¥ç¥ó¤òɽ¼¨¤µ¤»¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¤Ë¤Ï httpd.conf ¤Ë¤ª¤¤¤Æ

ServerSignature Off
ServerTokens ProductOnly

²èÁü¥Õ¥¡¥¤¥ë¤Ï¥í¥°¤Ëµ­Ï¿¤·¤Ê¤¤¤¿¤á¤Ë¤Ï httpd.conf ¤Ë¤ª¤¤¤Æ

<IfModule mod_setenvif.c>

   # no add images log
   SetEnvIf Request_URI "\.(gif)|(jpg)|(png)$" no_log

.....

CustomLog /usr/local/apache/logs/access_log combined env=!no_log

¼«Æ°µ¯Æ°¤ÎÀßÄê

# cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
# chmod 755 /etc/rc.d/init.d/httpd
# vi /etc/rc.d/init.d/httpd

°Ê²¼¤òÄɲÃ

#!/bin/sh
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#              HTML files and CGI.
# processname: httpd
# pidfile: /usr/local/apache/logs/httpd.pid
# config: /usr/local/apache/conf/httpd.conf
# /sbin/chkconfig --add httpd
# /etc/rc.d/init.d/httpd start

¥í¥°¤Î¥í¡¼¥Æ¡¼¥·¥ç¥óÀßÄê

# vi /etc/logrotate.d/apache
/usr/local/apache/logs/*_log
{
  rotate 4
  compress # ZIP°µ½Ì¤¹¤ë¾ì¹ç
  weekly
  sharedscripts
  postrotate
  /usr/local/apache/bin/apachectl restart
  endscript
}
# /usr/sbin/logrotate -f /etc/logrotate.d/apache

¥³¥Þ¥ó¥É¤Ë¤Æ /usr/local/apache/logs Æâ¤Ë access_log.1 error_log.1 ¤¬ºîÀ®¤µ¤ì¤Æ¤¤¤ì¤ÐOK

PHP4¤Î¥¤¥ó¥¹¥È¡¼¥ë

PHP¤á¤â¤â»²¹Í¤Ë¤·¤Æ²¼¤µ¤¤ :D

# tar xvzf php-4.4.1.tar.gz
# cd php-4.4.1
# ./configure --with-pgsql --with-apxs=/usr/local/apache/bin/apxs --enable-zend-multibyte --enable-mbstring --enable-mbregex

--enable-mbstr-enc-trans ¤Ï4.3.0°Ê¹ß¤ÏÇÑ»ß
--enable-trans-sid ¤Ï4.2.0°Ê¹ß¤Ï¾ï¤Ë¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤Þ¤¹
¥³¥Þ¥ó¥É¥é¥¤¥óÈǤÏ4.3.0¤«¤é¾ï¤Ë¹½ÃÛ¤µ¤ì¤ë
CGIÈǤÈCLIÈǤϰ㤦¤â¤Î¤é¤·¤¤¤¾¤Ã

GD¤ò»ÈÍѤ¹¤ë¾ì¹ç¤Ï¤³¤ó¤Ê´¶¤¸

# ./configure \
--with-pgsql --with-apxs=/usr/local/apache/bin/apxs \
--enable-zend-multibyte --enable-mbstring --enable-mbregex \
--with-gd --with-zlib-dir=/usr --with-jpeg-dir=/usr \
--with-png-dir=/usr --with-freetype-dir=/usr --with-ttf \
--enable-gd-native-ttf --enable-gd-jis-conv

libpng, libjpeg, freetype ¤¬¤Ê¤¤¤È¸À¤ï¤ì¤¿¤é devel ¤òÆþ¤ì¤Æ¤ß¤ë

php.ini¤ÎÀßÄê

# cp /usr/local/src/php-4.4.1/php.ini-dist /usr/local/lib/php.ini
;; ½ÐÎϥХåե¡¥ê¥ó¥°¤òÍ­¸ú¤Ë¤¹¤ë
output_buffering = On 

;; mb_output_handler¤Ë¤è¤ë½ÐÎÏÊÑ´¹¤òÍ­¸ú¤Ë¤¹¤ë 
output_handler = mb_output_handler

;; HTTP¥Ø¥Ã¥À charset ¤òÀßÄê
default_charset = Shift_JIS

;;ÆüËܸì¼çÂΤǻÈÍÑ
mbstring.language = Japanese

;; ÆâÉô¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤òEUC-JP¤ËÀßÄê
mbstring.internal_encoding = EUC-JP 

;; HTTPÆþÎÏ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°ÊÑ´¹¤òauto¤ËÀßÄê
mbstring.http_input = auto 

;; SJIS¤ËÊÑ´¹
mbstring.http_output = SJIS

mbstring.encoding_translation = On¡¡É¬Íס©
mbstring.detect_order = auto¡¡É¬Íס©
 
;; ̵¸ú¤Êʸ»ú¤ò½ÐÎϤ·¤Ê¤¤
mbstring.substitute_character = none;

mbstring.func_overload = 0

;; 4.1.0¤«¤é¿ä¾©
register_globals = Off
# make
# make install

httpd.conf¤Î½ñ¤­´¹¤¨

AddType application/x-httpd-php .php

¤òÄɲä·¤ÆApacheºÆµ¯Æ°

CGIÈǤò¥¤¥ó¥¹¥È¡¼¥ë¤¹¤ë¾ì¹ç

4.3.0°Ê¹ß¤ÏÉÔÍ×

# make distclean
# ./configure --with-pgsql --enable-track-vars --enable-force-cgi-redirect --enable-mbstring --enable-mbstr-enc-trans
# make
# make install

¤³¤ì¤Ç/usr/local/bin/php ¤Ë¥Ð¥¤¥Ê¥ê¤¬¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤ë

¥ß¥Ë¥á¥â

PostgreSQL7.3¤«¤é¤Ï¥Û¡¼¥à¥Ç¥£¥ì¥¯¥È¥ê¤Î .pgpass ¤Ë¡¢ ¥Ç¡¼¥¿¥Ù¡¼¥¹¥Û¥¹¥È¤È¥æ¡¼¥¶¥Ñ¥¹¥ï¡¼¥É¤¬µ­½Ò¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤·¤¿¡£ ´Ä¶­ÊÑ¿ô PGPASSWORD ¤Ç¤Ï¤Ê¤¯¡¢.pgpass ¤ò»ÈÍѤ¹¤ë¤è¤¦¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£


¥È¥Ã¥×   ÊÔ½¸ Åà·ë º¹Ê¬ ¥Ð¥Ã¥¯¥¢¥Ã¥× źÉÕ Ê£À½ ̾Á°Êѹ¹ ¥ê¥í¡¼¥É   ¿·µ¬ °ìÍ÷ ¸¡º÷ ºÇ½ª¹¹¿·   ¥Ø¥ë¥×   ºÇ½ª¹¹¿·¤ÎRSS
Last-modified: 2021-09-19 (Æü) 19:09:16