Fedora 에 APM(Apache, PHP, MySQL) 설치하기

APM을 설치하기 전에 기존에 설치되어 있던 내용을 모두 삭제 한다.
yum remove (name..)  or
rpm -e (name..)

지금 설치하려는 최신버전은 다음과 같습니다. 따로 준비하실 필요는 없고 설치과정에서 모든 자료는 받아서 설치합니다.
mysql 5.0.51 (www.mysql.com) , Compressed GNU TAR archive (tar.gz) 여기의 파일 download
apache 2.2.2  (httpd.apache.org)
php 5.1.4  (www.php.net)

php 라이브러리 : zlib 1.2.3(www.zlib.net), libpng 1.2.10(www.libpng.org/pub/png/libpng.html)
                         free type 2.2.1(www.freetype.org),  libjpeg v6b(freshmeat.net/projects/libjpeg)
                         gd 2.0.33(www.boutell.com/gd)
Zend Optimizer 3.0.1

1. zlib, libpng, free type, libjpeg, gd 설치php 언어에는 여러 함수를 지원합니다. php설치시 라이브러리를 설치해 주어야 작동하는 함수들이 많습니다. 모든 라이브러리를 설치하는 것은 무리가 있다고 생각하며, 커다란 사진을 조그마한 사진을 만들거나 도표를 그리기 위해 gd라이브러리는 기본적으로 설치해 주어야 한다고 생각해서, 연관있는 위 프로그램들을 설치하도록 하겠습니다. 물론 제가 썼던 설치강좌대로 설치하셨다면, 위 라이브러리들은 모두 설치되어 있을 것입니다. 하지만, gd라이브러리와 연동이 안된 상태이며, php 연동시 문제를 일으키기 때문에 컴파일 설치하도록 하겠습니다. rpm 설치된 것들은 그대로 놔 두셔도 상관없으니 놔두고 설치하겠습니다.

(1) zlib 설치
  zlib은 압축과 관련된 라이브러리 입니다.
  cd /usr/local
  wget http://ftp.superuser.co.kr/pub/etc/zlib-1.2.3.tar.bz2
  tar xvfj zlib-1.2.3.tar.bz2
  cd zlib-1.2.3
  ./configure && make && make install
  cd ..
  rm -rf zlib-1.2.3*

wget 명령어를 이용해서 ftp 사이트에서 압축된 소스파일을 가져오고 난 뒤에 압축을 해제합니다.
풀어진 디렉토리로 이동하여 configure와 컴파일과 설치를 한꺼번에 명령을 내여 설치합니다.
여기서 && 표시는 configure 가 성공하면 make를 실행하고 make 가 성공하면, make install를 실행하는 의미입니다.
마지막에 압축파일과 풀어진 소스파일은 필요없기 때문에 삭제합니다.
앞으로 설치할 모든 프로그램도 위와 같이 간단하게 설치할 것입니다.

(2) libpng 설치
png 포맷을 다루기 위한 라이브러리입니다.
  wget http://ftp.superuser.co.kr/pub/etc/libpng-1.2.10.tar.bz2
  tar xvfj libpng-1.2.10.tar.bz2
  cd libpng-1.2.10
  cp scripts/makefile.linux makefile
  make test && make install
  cd ..
  rm -rf libpng-1.2.10*

특별한 것은 makefile을 configure로 만들지 않고 , 복사한 것 외에는 다른 것이 없습니다.

(3) freetype 2 설치
글짜를 그릴 때 쓰는 라이브러리 입니다.
  wget http://ftp.superuser.co.kr/pub/etc/freetype-2.2.1.tar.bz2
  tar xvfj freetype-2.2.1.tar.bz2
  cd freetype-2.2.1
  ./configure && make && make install
  cd ..
  rm -rf freetype-2.2.1*

(4) libjpeg 설치
jpg 포맷을 다루는 라이브러리 입니다.
  wget http://ftp.superuser.co.kr/pub/etc/jpegsrc.v6b.tar.gz
  tar xvfz jpegsrc.v6b.tar.gz
  cd jpeg-6b
  ./configure --enable-shared --enable-static
  make && make test
  mkdir /usr/local/man/man1
  make install
  cd ..
  rm -rf jpeg*
위 설치법에서 특별한 것은 중간에 /usr/local/man/man1이라는 디렉토리를 생성합니다. 이유는 make install 하면 /usr/local/man/man1 디렉토리가 없다고 멘 페이지가 설치가 되지 않는다는 에러가 납니다.

(5) gd 설치
그래픽 라이브러리 입니다.
  wget http://ftp.superuser.co.kr/pub/etc/gd-2.0.33.tar.gz
  tar xvfz gd-2.0.33.tar.gz
  cd gd-2.0.33
  ./configure && make && make install
  cd ..
  rm -rf gd-2.0.33*

2. MySQL 설치지금부터는 DB 서버를 설치하겠습니다.  mysql은 많은 프로그램과 연동이 가능하며, linux에서 유용하게 사용할 수 있는 DBMS입니다. 4.1.X 버전에서 많은 변화가 있었고, 특히 5.0.X 버전에서는 사용자정의 함수, 트리거등 DBMS가 갖추어야 할 거의 대부분의 기능을 갖추고 있습니다. 그럼 현재 가장 최근 버전을 설치해 보도록 하겠습니다.
(mysql은 다른 프로그램에 비해 설치시간이 오래 걸립니다.. 컴파일 하는 시간이 엄청 오래 걸리죠)

(1) 설치
설치는 성능을 약 10% 정도 끌어올려준다는 static 모드로 설치하겠습니다.

       cd /usr/local/src
       tar xvfz mysql-4.1.12.tar.gz
       cd /usr/local/src/mysql-4.1.12

       ./configure \
       --prefix=/usr/local/mysql \
       --localstatedir=/usr/local/mysql/data \
       --with-charset=euckr

[root@localhost local]#./configure --prefix=/usr/local/mysql --enable-assembler --localstatedir=/usr/local/mysql/data --with-charset=euckr --with-mysqld-user=mysql --enable-thread-safe-client --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static


       make; make install
       cd /usr/local/mysql
       ./bin/mysql_install_db
       useradd -d /usr/local/mysql -s /bin/false mysql
       
chown mysql:mysql -R /usruseradd -d /usr/local/mysql -s /bin/false /local/mysql
       /usr/local/mysql/bin/mysqld_safe --user=mysql --old-passwords &

        \는 줄바꿈시 사용합니다.
        --prefix=/usr/local/mysql 는 기본 설치 디렉토리를 지정합니다.
        --localstatedir=/usr/local/mysql/data 는 데이터 기본 저장 장소를 지정합니다.
        --with-charset=euckr 는 기본 언어셋을 정의합니다.
        MySQL 4.1.X 에서는 --with-charset=euckr 으로 해야 합니다.
        MySQL 4.0까지는
--with-charset=euc_kr 로 설치해야 합니다.


3. Apache 2 설치
web 서버인 apache 는 1.X 버전과 2.0.X버전, 2.2.X 버전이 있습니다. 설정 파일 이 다르고, 운영또한 다른 방법으로 돌아가기 때문에 설치 시에도 구분하여 설치해 주는 것이 좋습니다. 아파치 2.2 버전은 성능향상 및 많은 점이 달라졌습니다. 자세한 사항은 소프트웨어 리뷰부분을 참조하시기 바랍니다. apache 1버전을 아직도 많이 사용 하는  이유는 1.X에만 돌아가는 확장모듈(예.  mod_throttle) 때문입니다.  본 강좌에서는 최신 버전을 다루기 때문에 2.2.X 버전을 설치합니다.

(1) 설치
  wget http://ftp.superuser.co.kr/pub/apache/httpd-2.0.49.tar.gz
  tar xvfj httpd-2.2.2.tar.bz2
  cd httpd-2.2.2

** MaxClient 값 튜닝( 최대 256이지만 이상으로 올려줍니다== > 4096)
server/mpm/prefork/prefork.c 파일에서
#define DEFAULT_SERVER_LIMIT 256 부분을 찾아서
#define DEFAULT_SERVER_LIMIT 4096 으로 수정해 줍니다.

server/mpm/worker/worker.c 파 일에서
#define DEFAULT_SERVER_LIMIT 16  부분을 찾아서  ( 16 * 16 = 256)
#define DEFAULT_THREAD_LIMIT 256  이렇게 수정해 줍니다. (256 * 16 = 4096)

./configure --enable-so --prefix=/usr/local/apache
make && make install
cd ..
rm -rf httpd-2.2.2.tar.bz2

아파치 또한 추가 설치 모듈이 있을 수 있으니 소스를 남겨둔다.

  (2) 동적 (DSO)모듈 올리기
    위 아파치 옵션은 기본 옵션입니다. 하지만, 요즘은 rewrite 모듈을 대부분 많이 사용합니다.
  이 모듈을 동적으로 올려 보도록 하겠습니다.
  /usr/local/apache/bin/apxs -cai /usr/local/httpd-2.2.2/modules/mappers/mod_rewrite.c
  위와같이 한줄의 명령만 내리면. httpd.conf 파일에
  LoadModule rewrite_module     modules/mod_rewrite.so
  위와 같이 한줄이 생기며, 동적으로 모듈을 로그 가능한 것입니다.


4. PHP 4 설치
현재 안정화된 최신버전이 5점대 버전입니다. php를 컴파일해서 apache 에 모듈로 올릴 것 입니다.

(1) 설치
wget http://ftp.superuser.co.kr/pub/php/php-5.1.4.tar.bz2
tar xvfj php-5.1.4.tar.bz2
cd php-5.1.4

CFLAGS="-O3 -march=i686 -funroll-loops -fomit-frame-pointer" \
./configure \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-zlib --with-gd --with-ttf --with-png \
--with-expat-dir=/usr --with-gmp --with-xml \
--with-mysql=/usr/local/mysql \
--with-language=korean \
--with-charset=euc_kr \
--disable-debug --disable-posix --disable-rpath \
--enable-safe-mode --enable-magic-quotes \
--disable-dmalloc --enable-bcmath \
--enable-dio --enable-gd-native-ttf \
--enable-sysvsem --enable-sysvshm \
--enable-wddx --enable-versioning \
--enable-pic --enable-inline-optimization \
--enable-memory-limit --enable-mbstring \
--enable-mbregex --enable-mbstr-enc-trans \
--with-config-file- --enable-ftp --disable-debug --enable-track-vars=yes \
--with-jpeg-dir --with-freetype-dir \
--enable-gd-native-ttf --enable-dl
  make && make install
  cp php.ini-dist /usr/local/lib/php.ini
- php.ini 파일을 복사 해 줍니다.
  cd ..
  rm -rf php-5.1.4.tar.bz2


5. Zend Optimizer
php의 성능을 최대화 해 준다는 Zend Optimizer를 설치합니다. Zend 홈페이지에 가보면 성능을 40% 향상시킨다고 합니다. ^^; 검증은 못했지만 말이죠~~ Zend는 컴파일 할 필요없이 받아서 설치하면 됩니다.^^; Zend는 Zend.org에서 가입만 하면 자유롭게 다운로드 받을 수 있습니다.

(1) 설치
  wget \
  http://ftp.superuser.co.kr/pub/ZendOptimizer/ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz

  tar xvfz ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz
  cd ZendOptimizer-3.0.1-linux-glibc21-i386
  ./install.sh - 위 명령을 실행시키면 다음과 같은 화면들이 주루룩~~ 나옵니다. 무조건 OK~ 또는 YES~^&^
하면 끝납니다.&&;
zd
  cd ..
  rm -rf ZendOptimizer-3.0.1-linux-glibc21-i386*


6. 웹 서버 운영
(1) 아파치 설정파일(/usr/local/apache/conf/httpd.conf) 다루기
아파치 설정파일을 다룹니다. 변경후에는 꼭 아파치를 재시작하시기 바랍니다.
(( 아파치 2.2.X는 설정파일이 기능별로 분리가 되어 있습니다. 아래와 같습니다.
httpd-autoindex.conf  httpd-info.conf    httpd-mpm.conf  httpd-userdir.conf httpd-dav.conf        httpd-languages.conf  httpd-multilang-errordoc.conf  httpd-vhosts.conf  httpd-default.conf    httpd-manual.conf     httpd-ssl.conf ))

-  .php 파일 및 html 파일에서 php 코드 실행되게 설정하려면
AddType application/x-httpd-php .php .phtml .php3 .html .htm
AddType application/x-httpd-php-source .phps위 내용을 추가해 줍니다. 추가 하게 되면 위 파일들에 있는 php 코드는 실행하게 됩니다.

- index.php를 기본으로 실행하게 설정 아파치는 기본적으로 DirectoryIndex index.html index.html.var 이렇게 설정 되어 있어 index.html 파일을 기본으로 읽습니다. 조금 바꾸어 주어 index.php 파일 및 기타 파일들도 기본으로 읽게 설정합니다.
DirectoryIndex index.html index.htm index.php index.php3 index.cgi

- 그림 파일 및 프래쉬 파일 로그 남기지 않게 설정
방문자 수가 많아지면 웹로그가 엄청 쌓이게 되고, 그 로그는 크기가  2G를 넘게 되면 웹페이지에 이상현상이 생깁니다. 그렇다고 로그를 안 남길 수는 없는 것이고, 이미지 파일들은 로그남기는 것에서 제외합니다.
CustomLog logs/access_log common 이렇게 되어 있는 것을 ..
SetEnvIfNoCase Request_URI (gif|png|jpg|css|js|bmp|jpeg|swf)$ IMAGE=1
CustomLog /usr/local/apache/logs/access_log common env=!IMAGE이렇게 바꾸면^^; 쉽게 가능합니다.

(2) php 설정파일 (/usr/local/lib/php.ini) 다루기
php와 관련된 설정을 다룹니다. 변경후에 꼭 아파치 재 시작을 해 주시기 바랍니다.

- post, get , 쿠키 , 세션등의 변수를 일반변수로
예전에 php는 기본적으로 위 변수를 일반변수로 사용할 수 있었습니다. 하지만 보안에 취약 하기 때문에 php 설치시 기본적으로 일반변소로 사용못하게 설정합니다. 이렇게 되면 문제가 예전에 사용하던 짜여졌던 프로그램은 정상적으로 실행되지 않습니다. 보안보다는 호환성이 더 중요하죠^^;
register_globals=On  이렇게 설정합니다.

- 업로드 용량 제한 풀기 기본적으로 업로드는 2M로 제한되어 있습니다. 만약 2M 이상으로 하면 여러 가지 설정들을 바꾸어 줘야 합니다. 업로드 되는 시간을 길 게 해 주어야 하고, 한번에 잡아먹을 메모리를 크게 해 주어야 합니다.
default_socket_timeout = 600
post_max_size = 20M
memory_limit = 20M
upload_max_filesize = 20M

(3) mysql 및 apache 시작
- mysql 시작 : /usr/local/mysql/bin/mysqld_safe &
- apache 시작 : /usr/local/apache/bin/apachectl start

(4) mysql 및 apache 재 시작
- mysql 재시작 : /usr/local/mysql/bin/mysqladmin -u root -p reload
==> 이 방법은 완벽한 재 시작이 아닙니다. 어떤 문제가 생겼을시는 완전히 중지시키고 다시 시작하세요.
- apache 재시작 : /usr/local/apache/bin/apachectl restart

(5) mysql 및 apache 중지
- mysql 중지 : /usr/local/mysql/bin/mysqladmin -u root -p shutdown
==>  이 방법으로 죽지 않을 때는 killall mysqld 라고 하면 죽습니다.
- apache 중지 : /usr/local/apache/bin/apachectl stop
==> 대부분 이 방법으로 죽으나 죽지 않는다면, killall httpd 하시면 죽습니다.

(6) 부팅시 자동 시작 등록하기
echo ' /usr/local/mysql/bin/mysqld_safe&
/usr/local/apache/bin/apachectl start' >> /etc/rc.d/rc.local

위와같은 한줄로 /etc/rc.d/rc.local 파일의 마지막 부분에 삽입합니다.


7. 확인
이렇게 열심히 설치 하였다면.. 확인을 해야 합니다. 서버단에서 확인은 이렇게 합니다.
(1) 프로세스 확인
  ps -ef | grep httpdroot     24963     1  0 00:46 ?        00:00:00 /usr/local/apache/bin/httpd -k restart
daemon    7319 24963  0 01:16 ?        00:00:00 /usr/local/apache/bin/httpd -k restart
daemon    7320 24963  0 01:16 ?        00:00:00 /usr/local/apache/bin/httpd -k restart
daemon    7321 24963  0 01:16 ?        00:00:00 /usr/local/apache/bin/httpd -k restart
daemon    7322 24963  0 01:16 ?        00:00:00 /usr/local/apache/bin/httpd -k restart
daemon    7323 24963  0 01:16 ?        00:00:00 /usr/local/apache/bin/httpd -k restart

  ps -ef | grep mysql
root      5444 29124  0 00:13 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe
mysql     5465  5444  0 00:13 pts/0    00:00:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --pid-file=/usr/local/mysql/data/study.superuser.co.kr.pid --skip-locking --port=3306 --socket=/tmp/mysql.sock
mysql     5466  5465  0 00:13 pts/0    00:00:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --pid-file=/usr/local/mysql/data/study.superuser.co.kr.pid --skip-locking --port=3306 --socket=/tmp/mysql.sock
mysql     5467  5466  0 00:13 pts/0    00:00:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --pid-file=/usr/local/mysql/data/study.superuser.co.kr.pid --skip-locking --port=3306 --socket=/tmp/mysql.sock
mysql     5468  5466  0 00:13 pts/0    00:00:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --pid-file=/usr/local/mysql/data/study.superuser.co.kr.pid --skip-locking --port=3306 --socket=/tmp/mysql.sock

(2) 포트 확인
netstat -an | grep LISTEN | grep 80
tcp        0      0 :::80                       :::*                        LISTEN
netstat -an | grep LISTEN | grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN


(3) 웹으로 확인
먼저 테스트 페이지 작성 합니다. 간단하게 phpinfo() 함수를 실행시켜 보도록 하겠습니다.
echo "<? phpinfo(); ?>" > /usr/local/apache/htdocs/index.php
php
위 결과를 잘 살펴보면, 설치된 라이브러리와 환경변수들을 확인할 수 있습니다.


8. 마치며..
최신 버전을 대상으로 강좌를 썼지만, 또 많은 것들이 변할 것이라 생각합니다. 자그마한 버전 변화는 설치법이 거의 동일하기 때문에 강좌 업데이트는 큰 변화가 있을 때 할 것입니다.
리눅스에서 APM은 리눅스를 키우는데 커다란 공을 세웠다고 생각합니다.  또한 쉽고 저렴하게 웹서버 및 DB 서버를 구축할 수 있어 행복한 시대를 살아간다고 생각합니다. 많은 분들에게 도움이 되길 바라며 본 강좌를 마무리 합니다.
혹시 본강좌에 대한 질문 및 오타를 발견하게 되면, 메일 한통 보내주기 바랍니다.. 메일주소는 doly 골뱅이superuser.co.kr 입니다.. 메일 주소를 무단 수집해서 스팸메일을 보내는 이를 막기 위해서 위와 같이 표기했으며, 골뱅이 부분은 @ 치환하면 됩니다.
이상... 2006년 6월 1일 ~ 날씨 좋은날에~ 수퍼유저 doly ...

ps . 저작권은 수퍼유저코리아에 있습니다.^^; 배포 또한 수퍼유저코리아에서만 가능합니다.
항상 문서의 내용은 최신버전의 내용을 반영하여 바뀔 수 있습니다.

Posted by 시티락