· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
Linuxdoc Sgml/Zend_pgsql-KLDP

PostgreSQL + Apache + Zend ¼³Ä¡Çϱâ

PostgreSQL + Apache + Zend ¼³Ä¡Çϱâ

Á¤¿ø¿µ suni00@kernel.pe.kr

v0.3, 2000³â 2¿ù 16ÀÏ
DB·Î PostgreSQLÀ» »ç¿ëÇϸç Apache À¥¼­¹ö¿¡ PHP Zend¸¦ ¸ðµâ·Î ÄÄÆÄÀÏ ÇÏ´Â ¹æ¹ýÀ» °£·«È÷ ¼³¸íÇÑ´Ù.

1. ¼³Ä¡Çϱâ Àü

  • ¼³Ä¡È¯°æÀº RedHat 6.0 ÀÌ»ó ¹öÀüÀ¸·Î ÇÏ°Ú´Ù.
  • ¼³Ä¡ÇÒ °¢°¢ÀÇ ¹öÀüÀº ´ÙÀ½°ú °°´Ù.
    • PostgreSQL : 6.5.3
    • Apache : 1.3.11
    • PHP : Zend beta 3
  • °¢°¢ ¿øÇÏ´Â ¹öÀüÀ¸·Î ´ÙÀ½ »çÀÌÆ®¿¡¼­ ±¸ÇÑ´Ù.

2. PostgreSQL ¼³Ä¡Çϱâ

2.1 postgres °èÁ¤ ¸¸µé±â

  • postgres¶ó´Â °èÁ¤°ú ±×·ìÀ» ¸¸µç´Ù. ±âº»ÀûÀ¸·Î RedHat ÆÐÅ°Áö´Â useradd¶õ ¸í·ÉÀ¸·Î ±×·ì°ú °èÁ¤À» °°ÀÌ ¸¸µé¾î ÁØ´Ù.
            # useradd postgres
            # passwd postgres
    

2.2 ¹é¾÷ Çϱâ

  • óÀ½ ¼³Ä¡ÇÏ´Â °æ¿ì´Â '2.3 ÄÄÆÄÀÏ¹× ¼³Ä¡'·Î ³Ñ¾î°£´Ù. ¹é¾÷Àº postgres °èÁ¤À¸·Î ÀÛ¾÷ÇÑ´Ù.
            $ pg_dumpall -z > db.out
    

2.3 ÄÄÆÄÀÏ¹× ¼³Ä¡

  1. ÄÄÆÄÀÏ ÇϱâÀü postmaster µ¥¸óÀ» Á×ÀδÙ.
            # ps -aux | grep postmaster
            # kill PID (À§¿¡¼­ ãÀº pid ¹øÈ£)
    
  2. PostgreSQL ¼Ò½º¸¦ /usr/local ¹æ¿¡¼­ Ǭ´Ù.
  3. Ç®¸é postgresql-6.5.3À̶õ µð·ºÅ丮°¡ »ý±â´Âµ¥ À̸§À» pgsql·Î ¹Ù²ãÁØ´Ù. (±âÁ¸ÀÇ pgsql µð·ºÅ丮´Â ¹öÀüÀ» ¸í½ÃÇϸç À̸§À» ¹Ù²ãÁØ´Ù.)
            # 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                        (ÄÄÆÄÀÏ)
    
  4. 'All of PostgreSQL is successfully made. Ready to install' ¶õ ¸Þ¼¼Áö°¡ º¸ÀÌ¸é ¼º°ø.
            # su postgres                     (postgres °èÁ¤À¸·Î ÀÛ¾÷ÇϱâÀ§ÇØ)
            $ make install                    (¼³Ä¡)
    

2.4 ¼³Ä¡ÈÄ ÀÛ¾÷

  1. ¶óÀ̺귯¸® Ãß°¡
            # vi /etc/ld.so.conf             
              /usr/local/pgsql/lib
            # /sbin/ldconfig
    
  2. ȯ°æº¯¼ö Ãß°¡
    °¢ °³ÀÎÀÇ È¯°æº¯¼ö¸¦ ¼³Á¤ÇϱâÀ§ÇØ °³ÀÎÀÇ .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
    
  3. ȯ°æ º¯¼ö Àû¿ë
                                              
    °¢ °èÁ¤¿¡¼­ ½ÇÇàÇؼ­ ȯ°æº¯¼ö¸¦ Àû¿ë½ÃŲ´Ù.
            $ source .bash_profile            
    
  4. µ¥ÀÌÅͺ£À̽º ÃʱâÈ­ Çϱâ
    postgres°èÁ¤À¸·Î ÀÛ¾÷ÇؾßÇÑ´Ù.
            $ initdb -e EUC_KR
    

2.5 postmaster µ¥¸ó ¶Ù¿ì±â

  • postgres °èÁ¤À¸·Î ¶Ù¿ö¾ß ÇÑ´Ù.
        
        $ postmaster -i -S -D /usr/local/pgsql/data

2.6 ¹é¾÷ µ¥ÀÌÅÍ º¹±¸

  • ¹é¾÷µÈ ÆÄÀÏ db.outÀ» º¹±¸Çϱâ À§ÇØ ´ÙÀ½°ú °°ÀÌ postgres °èÁ¤À¸·Î ÀÛ¾÷ÇÑ´Ù.

        $ psql -e template1 < db.out

3. Apache + PHP ¼³Ä¡Çϱâ

  1. ȯ°æ¼³Á¤¹× ÄÄÆÄÀÏ
    ¾ÆÆÄÄ¡¿Í 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                    (¾ÆÆÄÄ¡ ¼³Ä¡)
    
  2. ¼³Ä¡ ÈÄ
    ¼³Ä¡ÈÄ ¾ÆÆÄÄ¡ ȯ°æ¼³Á¤ ÆÄÀÏÀÎ /etc/httpd/conf/httpd.conf ÆÄÀÏÀ» ¿­¾î
    ´ÙÀ½°ú °°ÀÌ µÇ¾îÀÖ´ÂÁö È®ÀÎÇÏ°í ÁÖ¼®À» Ç®¾îÁØ´Ù.
    
            AddType application/x-httpd-php .php
            AddType application/x-httpd-php-source .phps
    

4. ¼³Ä¡ Å×½ºÆ® Çϱâ

Áö±ÝºÎÅÍ ÄíÅ°¸¦ ÀÌ¿ëÇÑ PHP + PostgreSQL¿ë °£´ÜÇÑ Ä«¿îÅ͸¦ ¸¸µé¾îº¸¸ç ¼³Ä¡°¡ Á¦´ë·Î µÇ¾ú´ÂÁö È®ÀÎÇØ º¸ÀÚ. »ç¿ëÀÚ °èÁ¤Àº suni00À¸·Î °¡Á¤ÇÏ°Ú´Ù.

4.1 ÀÏ¹Ý »ç¿ëÀÚ¿¡°Ô DB ±ÇÇÑÁÖ±â

  • postgres °èÁ¤À¸·Î ÀÏ¹Ý »ç¿ëÀÚ¿¡°Ô DB ±ÇÇÑÀ» ÁÖ¾î¾ßÁö DB¸¦ »ý¼ºÇÒ ¼ö ÀÖ´Ù.
            $ su - postgres                   (»ç¿ëÀÚ¸¦ postgres·Î ¹Ù²Û´Ù)
            $ createuser suni00               (±ÇÇÑÀ» ÁÖ°íÇ °èÁ¤À» Àû´Â´Ù) 
    
    DB »ý¼º ±ÇÇÑÀº ²À ÁÖ¾î¾ß ÇÑ´Ù.

4.2 DB »ý¼º¹× Å×ÀÌºí ¸¸µé±â

  • postgres°¡ ÁØ ±ÇÇÑÀ¸·Î ÀϹݻç¿ëÀÚ°¡ ´ÙÀ½°ú °°Àº DB¹× Å×À̺íÀ» »ý¼ºÇÑ´Ù.
            $ 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 ºüÁ®³ª°¨)
    

4.3 PHP ÇÁ·Î±×·¡¹Ö Çϱâ

  • ´ÙÀ½°ú °°Àº ³»¿ëÀÇ count.php ÆÄÀÏÀ» ¸¸µç´Ù.
    <?
            $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;
    ?>
    
    ÀÌÁ¦ À¥¿¡¼­ ÀÌ ÆÄÀÏÀ» Àо¸é reload ÇÒ ¶§¸¶´Ù Çϳª¾¿ Ä«¿îÆ®°¡ Áõ°¡ÇÏ´Â°É ¾Ë ¼ö ÀÖ´Ù.

4.4 ÄíÅ° »ç¿ëÇϱâ

  • ¾Õ¿¡¼­ ¸¸µç Ä«¿îÅÍ´Â reload ÇÒ¶§¸¶´Ù Áõ°¡ÇϹǷΠ±×¸® Á¤È®ÇÏÁö ¾ÊÀº ´ÜÁ¡ÀÌ ÀÖ´Ù. ±×·¡¼­ ´ÙÀ½°ú °°ÀÌ ÄíÅ°¸¦ ÀÌ¿ëÇÏ¿© ¾à°£À̳ª¸¶ ½Å·ÚÇÒ ¼ö ÀÖ°Ô Çغ¸ÀÚ. ÄíÅ°´Â ¸ðµç ű׺¸´Ù À§¿¡ÀÖ¾î¾ß Çϱ⠶§¹®¿¡ < html > ½ÃÀÛ Å±׺¸´Ù À­ÁÙ¿¡ ´ÙÀ½°ú °°ÀÌ ³Ö¾îÁØ´Ù.
            <? if (!$counted) { setcookie("counted",1,time()+3600); } ?>
    
    À§ ³»¿ëÀ» ´ëÃæ ¼³¸íÇϸé 3600ÃÊ(1½Ã°£)µ¿¾È $counted °ªÀ» 1·Î ¸¸µé¾î ÁØ´Ù. ±×·¯¹Ç·Î Çѹø Á¢¼ÓÇÑÈÄ 1½Ã°£ µÚ¿¡ Á¢¼ÓÇؾßÁö¸¸ Ä«¿îÅÍ´Â Áõ°¡ÇÑ´Ù.


ID
Password
Join
True happiness will be found only in true love.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2003-11-27 13:14:12
Processing time 0.0020 sec