PostgreSQL8+PHP5+Apache2¥¤¥ó¥¹¥È¡¼¥ë

PostgreSQL8.0¤Î²òÀâ
Apache2.2¤Î²òÀâ

PostgreSQL¤ÈMySQL¤ÎÈæ³Ó

Ãí°Õ»ö¹à

¥Ð¡¼¥¸¥ç¥ó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-8.1.3
# chown postgres /usr/local/src/postgresql-8.1.3

¥½¡¼¥¹¼èÆÀ http://www.postgresql.jp/
¾ï¤ËºÇ¿·¥Ð¡¼¥¸¥ç¥ó¤ò³Îǧ¤·¤Þ¤·¤ç¤¦
ÄÌ¿®¤ò°Å¹æ²½¤¹¤ë¾ì¹ç¤Ï ./configure --with-openssl ¤È¤¹¤ë

# su postgres
$ tar xvzf postgresql-8.1.3.tar.gz
$ cd postgresql-8.1.3
$ ./configure
$ gmake
$ gmake check
$ gmake install

SSL¤ÎÀßÄê

$ cd
$ cd data
$ openssl req -new -text -out server.req
Generating a 1024 bit RSA private key
...++++++
.....++++++
writing new private key to 'privkey.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:JP
State or Province Name (full name) [Berkshire]:Shiga
Locality Name (eg, city) [Newbury]:Otsu
Organization Name (eg, company) [My Company Ltd]:Self
Organizational Unit Name (eg, section) []:Engineer
Common Name (eg, your name or your server's hostname) []:example.com
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

¥Ñ¥¹¥Õ¥ì¡¼¥º¤Îºï½ü

$ openssl rsa -in privkey.pem -out server.key
$ rm -f privkey.pem

¼«¸Ê½ð̾

$ openssl req -x509 -in server.req -text -key server.key -out server.crt
$ chmod og-rwx server.key

pg_hba.conf ¤Ëhostssl¤òµ­½Ò
postgresql.conf ¤Îssl¤òon¤Ë¤¹¤ë

¥¯¥é¥¤¥¢¥ó¥È¦¤Ë¤âPostgreSQL¤ò --with-openssl ÉÕ¤­¤Ç¥¤¥ó¥¹¥È¡¼¥ë¤·¤Æ¤ª¤¯
µ¯Æ°¤¹¤ëɬÍפÏ̵¤·

¥Ñ¥¹¤ÎÀßÄê

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-8.1.3/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/postgresql start

¥í¥°´ÉÍý¤ÎÀßÄê

$ vi /usr/local/pgsql/data/postgresql.conf
redirect_stderr = on
log_filename = '%m-%d.log'
log_truncate_on_rotation = on
log_min_error_statement = error
log_line_prefix = '<%t %u %d %p>'

postgresql-8.3.0°Ê¹ß

logging_collector = on
log_filename = '%m-%d.log'
log_truncate_on_rotation = on
log_min_error_statement = error
log_line_prefix = '<%t %u %d %p>'

¼«Æ°VACUUM¤ÎÀßÄê

postgresql-8.1¤«¤é¤Ï¼«Æ°¤ÇVACUUM¤¬¼Â¹Ô¤µ¤ì¤ë¤è¤¦¤ËÀßÄê¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿
postgresql-8.3.0°Ê¹ß¤Ï¥Ç¥Õ¥©¥ë¥È¤ÇÍ­¸ú¤Ë¤Ê¤Ã¤¿

$ vi /usr/local/pgsql/data/postgresql.conf
stats_row_level = on
autovacuum = on

postgresql-8.3.0°Ê¹ß

track_counts = on
autovacuum = on

¥Á¥å¡¼¥Ë¥ó¥°

¥Ç¥Õ¥©¥ë¥È¤Ç¤ÏÉÔ½½Ê¬¤Ê¤Î¤Ç¤³¤Á¤é¤ò»²¹Í¤Ë¹ç¤ï¤»¤Æ¤ä¤Ã¤Æ¤ª¤³¤¦
PostgreSQL¤Î¥Á¥å¡¼¥Ë¥ó¥°

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

http://www.apache.jp/

MPM¤Ïworker¤â¤·¤¯¤Ïperchild¤À¤ÈPHP¤¬°ÂÄêÆ°ºî¤·¤Ê¤¤¤é¤·¤¤
»²¹Í

SSL¤òÍ­¸ú¤Ë¤¹¤ë¾ì¹ç¤Ï --enable-ssl
»²¹Í

# tar xvzf httpd-2.2.4.tar.gz
# cd httpd-2.2.4
# ./configure \
  --with-mpm=prefork \
  --enable-rewrite \
  --enable-so \
  --enable-ssl \
  --enable-dav \
  --with-included-apr
# make
# make install

apache2.2.4¤«¤é¤Ï
¡Öconfigure: error: Cannot use an external APR-util with the bundled APR¡×
¤È¥¨¥é¡¼¤¬½Ð¤ë¤è¤¦¤Ê¤Î¤Ç --with-included-apr ¤òÄɲ乤ë

Apache¤ÎÀßÄê

nobody¸¢¸Â¤Ë¤Ê¤ë¤è¤¦¤ËÊѹ¹
ÆäËÍýͳ¤Ï̵¤·¡£ÀΤ«¤é¤Î¸Ä¿ÍŪ¤Ê̾»Ä

<IfModule !mpm_netware_module>
User nobody
Group nobody
</IfModule>

Apache2.0·Ï¤Î¾ì¹ç

vi /usr/local/apache2/conf/httpd.conf
ServerTokens Prod
ServerSignature Off
TraceEnable Off

Apache2.2·Ï¤Î¾ì¹ç

Apache2.2·Ï¤«¤éÌÜŪÊ̤κ٤«¤¤ÀßÄê¤ÏÊÌ¥Õ¥¡¥¤¥ë¤ËʬΥ¤µ¤ì¤Æ¤¤¤ë¡£
apache2/conf/extra/ Æâ¤Ë httpd-xxxxxxx.conf ¤Î·Á¼°¤Ç¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¡£
¤³¤ì¤é¤òÆɤ߹þ¤à¤¿¤á¤Ë¤Ï httpd.conf Æâ¤Ç³ºÅö²Õ½ê¤Î¥³¥á¥ó¥È¤ò³°¤¹É¬Íפ¬¤¢¤ë
º£²óÀßÄꤹ¤ë¹àÌܤ¬¤¢¤ë¤Î¤Ï httpd-default.conf

vi /usr/local/apache2/conf/httpd.conf

394¹ÔÌܤ¢¤¿¤ê

Include conf/extra/httpd-default.conf

httpd.conf ¤ÇÆɤ߹þ¤Þ¤»¤¿¥Õ¥¡¥¤¥ë¤òÊÔ½¸

vi /usr/local/apache2/conf/extra/httpd-default.conf
ServerTokens Prod
ServerSignature Off
TraceEnable Off

¡ÖTraceEnable¡×¤ÏºÇ½é½ñ¤¤¤Æ¤Ê¤¤¤«¤â
¤½¤Î¾ì¹ç¡ÖServerSignature¡×¤Î²¼¤Ë¤Ç¤âÄɲ䷤Ȥ±¤Ð¤¤¤¤¤À¤í¤¦

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

# cp /usr/local/apache2/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/apache2/logs/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf
# /sbin/chkconfig --add httpd
# /etc/rc.d/init.d/httpd start

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

¥í¥°¤òZIP°µ½Ì¤¹¤ë¾ì¹ç compress

# vi /etc/logrotate.d/apache
/usr/local/apache2/logs/*_log
{
  rotate 4
  compress
  weekly
  sharedscripts
  postrotate
  /usr/local/apache2/bin/apachectl restart
  endscript
}
# /usr/sbin/logrotate -f /etc/logrotate.d/apache

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

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

http://jp.php.net/downloads.php

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

Amazon ECS¤Ê¤É¤òÍøÍѤ¹¤ë¾ì¹ç¤ÏÍ­¸ú¤Ë¤·¤Æ¤ª¤¯

--enable-simplexml

cURL¤ÏÀè¤Ë¥¤¥ó¥¹¥È¡¼¥ë¤·¤Æ¤ª¤¯
RPM¤ÇÆþ¤Ã¤Æ¤¤¤ì¤ÐOK

--with-curl

fopen('https://example.com/index.html');
¤Ê¤É¤È¤·¤¿¤¤¾ì¹ç¤Ï»ØÄ꤬ɬÍ×

--with-openssl

MySQL¤ÏÀè¤Ë¥¤¥ó¥¹¥È¡¼¥ë¤·¤Æ¤ª¤¯
¥½¡¼¥¹¤«¤é¤Î¥¤¥ó¥¹¥È¡¼¥ë¤ÏMySQL5.0¥¤¥ó¥¹¥È¡¼¥ë¤ò»²¾È

--with-mysql
# tar xvzf php-5.1.4.tar.gz
# cd php-5.1.4
# ./configure \
    --with-apxs2=/usr/local/apache2/bin/apxs \
    --enable-zend-multibyte \
    --enable-mbstring \
    --enable-mbregex \
    --with-zlib \
    --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 \
    --enable-sockets \
    --enable-simplexml \
    --with-curl \
    --with-pgsql \
    --with-mysql=/usr/local/mysql \
    --with-sqlite=shared \
    --enable-pdo=shared \
    --with-pdo-pgsql=shared \
    --with-pdo-mysql=shared,/usr/local/mysql
    --with-pdo-sqlite=shared \
# make
# make install

¤½¤Î¾configure¥ª¥×¥·¥ç¥ó¤Ë¤Ä¤¤¤Æ

php.ini¤ÎÀßÄê

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

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

;; ¥Ø¥Ã¥À¤Ëɽ¼¨¤µ¤ì¤ë X-Powered-By: PHP/x.x.x ¤òÈóɽ¼¨¤Ë¤¹¤ë
expose_php = Off

magic_quotes_gpc = Off

;; 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

;; ¼«Æ°¥¨¥ó¥³¡¼¥É
;; ¥Û¥ó¥È¤ÏOff¤Ë¤·¤Æ¼«ÎϤǥ¨¥ó¥³¡¼¥É¤¹¤ëÊý¤¬Ê¸»ú²½¤±¤Î¿´Çۤ⤤¤é¤Ê¤¤
mbstring.encoding_translation = On

mbstring.detect_order = auto
 
;; ̵¸ú¤Êʸ»ú¤ò½ÐÎϤ·¤Ê¤¤
mbstring.substitute_character = none;

mbstring.func_overload = 0

; Zend_Session¤ò»ÈÍѤ¹¤ë¤Ê¤é¤Ð¥³¥á¥ó¥È¤ò¤Ï¤º¤·¤Æ¤ª¤¯¤ÈµÈ
session.save_path = "/tmp"

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

AddType application/x-httpd-php .php

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


¥È¥Ã¥×   ¿·µ¬ °ìÍ÷ ¸¡º÷ ºÇ½ª¹¹¿·   ¥Ø¥ë¥×   ºÇ½ª¹¹¿·¤ÎRSS