Linuxdoc Sgml/Zend_pgsql-KLDP
<!doctype linuxdoc system>
<article>
<title>PostgreSQL + Apache + Zend ¼³Ä¡Çϱâ
<author>Á¤¿ø¿µ <htmlurl url="mailto:suni00@kernel.pe.kr"
name="suni00@kernel.pe.kr">
<date>v0.3, 2000³â 2¿ù 16ÀÏ
<abstract>
DB·Î PostgreSQLÀ» »ç¿ëÇϸç Apache À¥¼¹ö¿¡ PHP Zend¸¦ ¸ðµâ·Î
ÄÄÆÄÀÏ ÇÏ´Â ¹æ¹ýÀ» °£·«È÷ ¼³¸íÇÑ´Ù.
</abstract>
<toc>
<sect> ¼³Ä¡Çϱâ Àü<p>
<itemize>
<item>¼³Ä¡È¯°æÀº RedHat 6.0 ÀÌ»ó ¹öÀüÀ¸·Î ÇϰڴÙ.
<item>¼³Ä¡ÇÒ °¢°¢ÀÇ ¹öÀüÀº ´ÙÀ½°ú °°´Ù.
<itemize>
<item> PostgreSQL : 6.5.3
<item> Apache : 1.3.11
<item> PHP : Zend beta 3
</itemize>
<item>°¢°¢ ¿øÇÏ´Â ¹öÀüÀ¸·Î ´ÙÀ½ »çÀÌÆ®¿¡¼ ±¸ÇÑ´Ù.
<itemize>
<item><url url="http://www.postgresql.org">
<item><url url="http://www.apache.org">
<item><url url="http://www.php.net">
</itemize>
</itemize>
<sect> PostgreSQL ¼³Ä¡Çϱâ<p>
<sect1> postgres °èÁ¤ ¸¸µé±â <p>
<itemize>
<item>postgres¶ó´Â °èÁ¤°ú ±×·ìÀ» ¸¸µç´Ù. ±âº»ÀûÀ¸·Î RedHat ÆÐŰÁö´Â
useradd¶õ ¸í·ÉÀ¸·Î ±×·ì°ú °èÁ¤À» °°ÀÌ ¸¸µé¾î ÁØ´Ù.
<verb>
# useradd postgres
# passwd postgres
</verb>
</itemize>
<sect1> ¹é¾÷ Çϱâ <p>
<itemize>
<item>óÀ½ ¼³Ä¡ÇÏ´Â °æ¿ì´Â <bf>'2.3 ÄÄÆÄÀÏ¹× ¼³Ä¡'</bf>·Î ³Ñ¾î°£´Ù.
¹é¾÷Àº postgres °èÁ¤À¸·Î ÀÛ¾÷ÇÑ´Ù.
<verb>
$ pg_dumpall -z > db.out
</verb>
</itemize>
<sect1> ÄÄÆÄÀÏ¹× ¼³Ä¡ <p>
<enum>
<item>ÄÄÆÄÀÏ ÇϱâÀü postmaster µ¥¸óÀ» Á×ÀδÙ.
<verb>
# ps -aux | grep postmaster
# kill PID (À§¿¡¼ ãÀº pid ¹øÈ£)
</verb>
<item>PostgreSQL ¼Ò½º¸¦ /usr/local ¹æ¿¡¼ Ǭ´Ù.
<item>Ç®¸é postgresql-6.5.3À̶õ µð·ºÅ丮°¡ »ý±â´Âµ¥ À̸§À» pgsql·Î ¹Ù²ãÁØ´Ù.
(±âÁ¸ÀÇ pgsql µð·ºÅ丮´Â ¹öÀüÀ» ¸í½ÃÇϸç À̸§À» ¹Ù²ãÁØ´Ù.)
<verb>
# mv postgresql-6.5.3 pgsql (À̸§À» pgsql·Î ¹Ù²Û´Ù)
# chown -R postgres.postgres pgsql (user¿Í groupÀ» ¹Ù²Û´Ù)
# cd /usr/local/pgsql/src
# vi Makefile.custom (Pentitum pro±Þ À̻󿡼 ÃÖÀûȸ¦
CFLAG+= -m486 À§ÇØ »ý¼ºÇÑ´Ù)
# ./configure --with-mb=EUC_KR (ÇÑ±Û »ç¿ëÀ» À§ÇØ)
# cd /usr/local/pgsql/doc
# make install (¸Ç ÆäÀÌÁö, HTML ¹®¼ÆÄÀÏ ¼³Ä¡)
# cd /usr/local/pgsql/src
# make all (ÄÄÆÄÀÏ)
</verb>
<item>'All of PostgreSQL is successfully made. Ready to install' ¶õ ¸Þ¼¼Áö°¡
º¸ÀÌ¸é ¼º°ø.
<verb>
# su postgres (postgres °èÁ¤À¸·Î ÀÛ¾÷ÇϱâÀ§ÇØ)
$ make install (¼³Ä¡)
</verb>
</enum>
<sect1> ¼³Ä¡ÈÄ ÀÛ¾÷ <p>
<enum>
<item>¶óÀ̺귯¸® Ãß°¡
<verb>
# vi /etc/ld.so.conf
/usr/local/pgsql/lib
# /sbin/ldconfig
</verb>
<item>ȯ°æº¯¼ö Ãß°¡
<verb>
°¢ °³ÀÎÀÇ È¯°æº¯¼ö¸¦ ¼³Á¤ÇϱâÀ§ÇØ °³ÀÎÀÇ .bash_profile¿¡ ´ÙÀ½À» Ãß°¡ÇÑ´Ù.
(DB¸¦ »ç¿ëÇÒ °èÁ¤ÀÇ È¯°æº¯¼ö¸¦ ¼³Á¤ - postgres °èÁ¤¿¡µµ Àû¿ë½ÃŲ´Ù.)
PATH=$PATH:/usr/local/pgsql/bin
MANPATH=$MANPATH:/usr/local/pgsql/man
PGLIB=/usr/local/pgsql/lib
PGDATA=/usr/local/pgsql/data
export PATH MANPATH PGLIB PGDATA
</verb>
<item>ȯ°æ º¯¼ö Àû¿ë
<verb>
°¢ °èÁ¤¿¡¼ ½ÇÇàÇØ¼ ȯ°æº¯¼ö¸¦ Àû¿ë½ÃŲ´Ù.
$ source .bash_profile
</verb>
<item>µ¥ÀÌÅͺ£À̽º ÃʱâÈ Çϱâ
<verb>
postgres°èÁ¤À¸·Î ÀÛ¾÷ÇØ¾ßÇÑ´Ù.
$ initdb -e EUC_KR
</verb>
</enum>
<sect1> postmaster µ¥¸ó ¶Ù¿ì±â <p>
<itemize>
<item>postgres °èÁ¤À¸·Î ¶Ù¿ö¾ß ÇÑ´Ù.
</itemize>
<verb>
$ postmaster -i -S -D /usr/local/pgsql/data
</verb>
<sect1> ¹é¾÷ µ¥ÀÌÅÍ º¹±¸ <p>
<itemize>
<item>¹é¾÷µÈ ÆÄÀÏ db.outÀ» º¹±¸Çϱâ À§ÇØ ´ÙÀ½°ú °°ÀÌ postgres °èÁ¤À¸·Î ÀÛ¾÷ÇÑ´Ù.
</itemize>
<verb>
$ psql -e template1 < db.out
</verb>
<sect> Apache + PHP ¼³Ä¡Çϱâ <p>
<enum>
<item>ȯ°æ¼³Á¤¹× ÄÄÆÄÀÏ
<verb>
¾ÆÆÄÄ¡¿Í PHP¸ðµÎ /usr/local µð·ºÅ丮¿¡ Ç®¾úÀ¸¸ç ¾ÆÆÄÄ¡ÀÇ ¼Ò½º µð·ºÅ丮´Â
/usr/local/apache_1.3.11À̸ç PHPÀÇ ¼Ò½º µð·ºÅ丮´Â /usr/local/php-4.0b3ÀÌ´Ù.
¸ðµç°Ç root °èÁ¤À¸·Î ÀÛ¾÷ÇÑ´Ù.
# cd /usr/local/apache_1.3.11 (¾ÆÆÄÄ¡ ¼Ò½º µð·ºÅ丮·Î À̵¿)
# ./configure --prefix=/etc/httpd (ÄÄÆÄÀÏÈÄ »ý¼º ÆÄÀÏÀÇ °æ·Î´Â
/etc/httpd ÀÌ´Ù)
# cd /usr/local/php-4.0b3 (php ¼Ò½º µð·ºÅ丮·Î À̵¿)
# ./configure --with-apache=/usr/local/apache_1.3.11
--with-pgsql=/usr/local/pgsql
--enable-track-vars
(¾ÆÆÄÄ¡¿Í postgresÀÇ °æ·ÎÀε¥ ÇÑÁÙ¿¡ ÀÌ¾î ½á¾ßÇÑ´Ù)
# make
# make install (php ¼³Ä¡)
# cp php.ini-dist /usr/local/lib/php.ini (php ¿É¼Çµé)
# cd /usr/local/apache_1.3.11 (¾ÆÆÄÄ¡ µð·ºÅ丮·Î À̵¿)
# ./configure --prefix=/etc/httpd
--activate-module=src/modules/php4/libphp4.a
(php¸¦ ¸ðµâ·Î Æ÷ÇÔ½ÃÅ´, ¿ª½Ã ÇÑÁÙ·Î ÀÌ¾î ½á¾ßÇÑ´Ù)
# make
# make install (¾ÆÆÄÄ¡ ¼³Ä¡)
</verb>
<item>¼³Ä¡ ÈÄ
<verb>
¼³Ä¡ÈÄ ¾ÆÆÄÄ¡ ȯ°æ¼³Á¤ ÆÄÀÏÀÎ /etc/httpd/conf/httpd.conf ÆÄÀÏÀ» ¿¾î
´ÙÀ½°ú °°ÀÌ µÇ¾îÀÖ´ÂÁö È®ÀÎÇϰí ÁÖ¼®À» Ç®¾îÁØ´Ù.
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</verb>
</enum>
<sect> ¼³Ä¡ Å×½ºÆ® Çϱâ <p>
Áö±ÝºÎÅÍ Äí۸¦ ÀÌ¿ëÇÑ PHP + PostgreSQL¿ë °£´ÜÇÑ Ä«¿îÅ͸¦ ¸¸µé¾îº¸¸ç
¼³Ä¡°¡ Á¦´ë·Î µÇ¾ú´ÂÁö È®ÀÎÇØ º¸ÀÚ.
»ç¿ëÀÚ °èÁ¤Àº suni00À¸·Î °¡Á¤ÇϰڴÙ.
<sect1> ÀÏ¹Ý »ç¿ëÀÚ¿¡°Ô DB ±ÇÇÑÁÖ±â <p>
<itemize>
<item>postgres °èÁ¤À¸·Î ÀÏ¹Ý »ç¿ëÀÚ¿¡°Ô DB ±ÇÇÑÀ» ÁÖ¾î¾ßÁö DB¸¦ »ý¼ºÇÒ ¼ö
ÀÖ´Ù.
<verb>
$ su - postgres (»ç¿ëÀÚ¸¦ postgres·Î ¹Ù²Û´Ù)
$ createuser suni00 (±ÇÇÑÀ» ÁÖ°íÇ °èÁ¤À» Àû´Â´Ù)
</verb>
DB »ý¼º ±ÇÇÑÀº ²À ÁÖ¾î¾ß ÇÑ´Ù.
</itemize>
<sect1> DB »ý¼º¹× Å×ÀÌºí ¸¸µé±â <p>
<itemize>
<item>postgres°¡ ÁØ ±ÇÇÑÀ¸·Î ÀϹݻç¿ëÀÚ°¡ ´ÙÀ½°ú °°Àº DB¹× Å×À̺íÀ» »ý¼ºÇÑ´Ù.
<verb>
$ su - suni00 (ÀϹݰèÁ¤ »ç¿ëÀÚ·Î ¹Ù²Û´Ù)
$ createdb test (test¶õ DB¸¦ ¸¸µç´Ù)
$ psql test (test DB¿¡ ¿¬°á)
test=> create table counter ( count int ); (table »ý¼º)
test=> insert into counter values ( 0 ); (0À» ÀÔ·Â)
test=> \q (DB ºüÁ®³ª°¨)
</verb>
</itemize>
<sect1> PHP ÇÁ·Î±×·¡¹Ö Çϱâ <p>
<itemize>
<item>´ÙÀ½°ú °°Àº ³»¿ëÀÇ count.php ÆÄÀÏÀ» ¸¸µç´Ù.
<verb>
<?
$connect=pg_connect("dbname=test user=suni00");
$result=pg_exec($connect,"select * from counter");
$count_num = pg_result($result,0,"count");
if (!$counted) {
$count_num++;
pg_exec($connect,"update counter set count=$count_num");
}
echo $count_num;
?>
</verb>
ÀÌÁ¦ À¥¿¡¼ ÀÌ ÆÄÀÏÀ» Àо¸é reload ÇÒ ¶§¸¶´Ù Çϳª¾¿ Ä«¿îÆ®°¡
Áõ°¡ÇÏ´Â°É ¾Ë ¼ö ÀÖ´Ù.
</itemize>
<sect1> ÄíŰ »ç¿ëÇϱâ <p>
<itemize>
<item>¾Õ¿¡¼ ¸¸µç Ä«¿îÅÍ´Â reload ÇÒ¶§¸¶´Ù Áõ°¡ÇϹǷΠ±×¸® Á¤È®ÇÏÁö ¾ÊÀº
´ÜÁ¡ÀÌ ÀÖ´Ù. ±×·¡¼ ´ÙÀ½°ú °°ÀÌ Äí۸¦ ÀÌ¿ëÇÏ¿© ¾à°£À̳ª¸¶ ½Å·ÚÇÒ ¼ö
ÀÖ°Ô ÇØº¸ÀÚ.
ÄíŰ´Â ¸ðµç ű׺¸´Ù À§¿¡ÀÖ¾î¾ß Çϱ⠶§¹®¿¡ < html > ½ÃÀÛ Å±׺¸´Ù
ÀÁÙ¿¡ ´ÙÀ½°ú °°ÀÌ ³Ö¾îÁØ´Ù.
<verb>
<? if (!$counted) { setcookie("counted",1,time()+3600); } ?>
</verb>
À§ ³»¿ëÀ» ´ëÃæ ¼³¸íÇϸé 3600ÃÊ(1½Ã°£)µ¿¾È $counted °ªÀ» 1·Î ¸¸µé¾î
ÁØ´Ù. ±×·¯¹Ç·Î Çѹø Á¢¼ÓÇÑÈÄ 1½Ã°£ µÚ¿¡ Á¢¼ÓÇØ¾ßÁö¸¸ Ä«¿îÅÍ´Â
Áõ°¡ÇÑ´Ù.
</itemize>
</article>
|
Good news from afar can bring you a welcome visitor. |











