질문게시판에 centos 5.2 apm관련 테스트를 위해 작성함.
소스파일들은 최신버전들입니다.

아래내용은 centos5.2을 노트북에 설치하고 apm 테스트를 위하여 phpinfo()를 본 캡쳐화면입니다.

터미널에서 한글 깨지면...

vi /etc/sysconfig/i18n


LANG="ko_KR.eucKR"
SUPPORTED="en_US.iso885915:en_US:en:ko_KR.eucKR:ko_KR:ko" 



Point : CentOS 5.2 설치후 selinux 관련을 사용하지 않음으로 설정하고 재부팅한 다음 설치를 시작했다.

[root@localhost ~]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted
[root@localhost ~]# reboot

만약 재부팅을 하지 않고 진행하려면 쉘상에서 setenforce 0을 입력하면 된다.


[root@localhost ~]# setenforce 0
[root@localhost ~]# setenforce
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]



혹시라도 selinux를 적용해서 사용하고자 할때에는 웹서버 디렉토리 만든다음 selinux 문맥에 맞게 변경해 주어야 한다.


selinux




=======================

* gcc 컴파일러 설치 확인 *

소스 컴파일시 필요한 gcc 관련 패키지들은 yum을 사용하여 원격 설치할 수 있다.

# yum install yum-fastestmirror -y
# yum install gcc gcc-c++ make automake autoconf -y

추가적인 yum 명령어 사용법은 아래 링크를 참고한다.

http://www.lug.or.kr/home/bbs/board.php?bo_table=centos_book&wr_id=93&page=2#bbs

좀더 자세한 내용은 맨페이지를 참고한다.

# man yum

=======================

* yum을 사용하여 개발 패키지 그룹들을 설치해 둔다. *

rpmforge.net 저장소 사용하기 : 2009-10-05 최신 정보로 수정


CentOS5 에서 yum을 이용해서 패캐지 인스톨 시 인스톨 정보를 얻을 수 없을 경우는 자동으로 인스톨 되지 안된다.이 경우 rpmforge를 repository로써 추가시키면 최신정보에 의해 인스톨을 할 수 있다.

third-party repository와의 호완성이 문제가 되므로 일단 Priority를 인스톨한다.

# yum install yum-properties

/etc/yum.repos.d/ 밑의 .repo 에 밑의 행을 추가시킨다.

priority=N

N은 1~99를 설정해준다. 추천설정은 아래와 같다.

[base], [addons], [updates], [extras] ... priority=1
[centosplus],[contrib] ... priority=2
rpmforge등의 Third-party의 Repository에는  10 이상으로 설정

rpmforge-release Package를 다운로드 한다.
서버에 따라 아래로 부터 다운로드 받는다.

- i386  :
http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
- x86_64 :  
http://apt.sw.be/redhat/el5/en/x86_64/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm 

DAG's GPG 키의 인스톨

# rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

다운로드 한 Package를 확인한다.

# rpm -K rpmforge-release-0.3.6-1.el5.rf.*.rpm

rpmforge-release Package는 RPM 데이터베이스에 GPG 키를 넣는다. 따라서 키를 인스톨 한 후 DAG를 신뢰하는 한은 안전하다.

이제 Package 인스톨

# rpm -i rpmforge-release-0.3.6-1.el5.rf.*.rpm

이것은 yum Repository Config 파일에 적절한 GPG 키를 넣게된다.
다음은 인스톨이 잘 되었다 체크한다.

# yum check-update

다음이 출력될 것이다.

Loading "priorities" plugin
...
76 packages excluded due to repository priority protections

숫자는 다를 수 있지만,
이제부터 CentOS에 필요한 추천 Package를 인스톨 할 수 있다.









개발관련 패키지 그룹 설치하기

# yum groupinstall "Development Libraries" -y
# yum groupinstall "Development Tools" -y
# yum groupinstall "Legacy Software Development" -y

=======================



1. MYSQL 설치

mysql 버전 : mysql-5.0.67.tar.gz [5.x대의 안정버전을 사용한다.]
http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.67.tar.gz/from/http://mysql.byungsoo.net/

mysql 설치경로 : /usr/local/server/mysql

mysql 유저 생성
# useradd -M -s /bin/false mysql

아래 컴파일에서 --with-readline 옵션이 있어야만 ssh 원격접속(putty, utf-8) 콘솔에서 한글 입력이 가능하다.

# ./configure --prefix=/usr/local/server/mysql --with-charset=utf8 --with-extra-charsets=all --with-readline

# make
# make install

컴파일 시작하기 : mysql 환경설정, 파일 복사, 시작스크립트 복사

[root@localhost ~]# yum install re2c
[root@localhost ~]# useradd -M -s /bin/false mysql
[root@localhost ~]# mkdir /usr/local/src/APM
[root@localhost ~]# cd /usr/local/src/APM/
[root@localhost APM]# wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.67.tar.gz/from/http://mysql.byungsoo.net/
[root@localhost APM]# tar xzf mysql-5.0.67.tar.gz
[root@localhost APM]# cd mysql-5.0.67
[root@localhost mysql-5.0.67]# pwd
/usr/local/src/APM/mysql-5.0.67
[root@localhost mysql-5.0.67]# ./configure --prefix=/usr/local/server/mysql --with-charset=utf8 --with-extra-charsets=all --with-readline
[root@localhost mysql-5.0.67]# make
[root@localhost mysql-5.0.67]# make install
[root@localhost mysql-5.0.67]# cp support-files/my-huge.cnf /etc/my.cnf
[root@localhost mysql-5.0.67]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.0.67]# chmod 755 /etc/init.d/mysqld
[root@localhost mysql-5.0.67]# chkconfig --add mysqld
[root@localhost mysql-5.0.67]# chkconfig --list mysqld
mysqld          0:해제  1:해제  2:활성  3:활성  4:활성  5:활성  6:해제
[root@localhost mysql-5.0.67]# chkconfig --level 24 mysqld off
[root@localhost mysql-5.0.67]# chkconfig --list mysqld
mysqld          0:해제  1:해제  2:해제  3:활성  4:해제  5:활성  6:해제
[root@localhost mysql-5.0.67]#

mysql 데이터베이스 초기화 및 디렉토리 퍼미션 설정

[root@localhost mysql-5.0.67]# cd /usr/local/server/mysql/
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# bin/mysql_install_db --user=mysql
[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql var
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL                                             [  OK  ]
[root@localhost mysql]#

mysql을 설치한 다음 mysql를 관리하는 root의 패스워드는 기본적으로 설정되어 있지 않기 때문에 패스워드 없이 누구나 접근이 가능하다. 이를 막기 위해 root@localhost의 패스워드를 설정한다.

[root@localhost mysql]# /usr/local/server/mysql/bin/mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.67-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@localhost mysql]#




2. 아파치 설치

httpd 버전 : httpd-2.2.9.tar.bz2
http://ftp.kaist.ac.kr/pub/Apache/httpd/httpd-2.2.9.tar.bz2

httpd 설치경로 : /usr/local/server/httpd
./configure --prefix=/usr/local/server/httpd --enable-so --enable-mods-shared=all --enable-ssl --with-ssl
make
make install

아파치 시작 스크립트 복사 및 수정

[root@localhost APM]# pwd
/usr/local/src/APM
[root@localhost APM]# lftpget http://ftp.kaist.ac.kr/pub/Apache/httpd/httpd-2.2.9.tar.bz2
[root@localhost APM]# tar xjf httpd-2.2.9.tar.bz2
[root@localhost APM]# cd httpd-2.2.9
[root@localhost httpd-2.2.9]# pwd
/usr/local/src/APM/httpd-2.2.9
[root@localhost httpd-2.2.9]# ./configure --prefix=/usr/local/server/httpd --enable-so --enable-mods-shared=all --enable-ssl --with-ssl
[root@localhost httpd-2.2.9]# make
[root@localhost httpd-2.2.9]# make install
[root@localhost httpd-2.2.9]# cp /usr/local/server/httpd/bin/apachectl /etc/init.d/httpd
[root@localhost httpd-2.2.9]# vi /etc/init.d/httpd

#!/bin/sh
# Comments to support chkconfig on CentOS Linux, http://www.lug.or.kr  
# chkconfig: 35 90 90  
# description: A very fast and reliable WebServer engine. 

[root@localhost httpd-2.2.9]# chmod 755 /etc/init.d/httpd
[root@localhost httpd-2.2.9]# chkconfig --add httpd
[root@localhost httpd-2.2.9]# chkconfig --list httpd
httpd           0:해제  1:해제  2:해제  3:활성  4:해제  5:활성  6:해제
[root@localhost httpd-2.2.9]#




#. 오라클 클라이언트 설치 1.

우선 아래의 주소에서 자신의 서버에 맞는 파일을 다운 받습니다.
http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html 

원하는 버전의.. 두개를
instantclient-basic-linux32-10.2.0.1-20050713.zip
instantclient-sdk-linux32-10.2.0.1-20050713.zip

두개의 파일을 다운받아 각각
/usr/lib/oracle
/usr/lib/oralce/sdk
의 디렉토리로 압축을 풀었습니다.
두 개의 파일이 다 필요합니다. sdk 파일이 없으면 php 컴파일이 되질 않습니다.

php 컴파일시 libclntsh.so 파일이 없다는 에러를 막기위해 해당디렉토리로 이동한 후
심볼릭 링크를 걸어줍니다.

# cd /usr/lib/oracle
# ln -s libclntsh.so.10.1 libclntsh.so

오라클 환경변수를 셋팅해줍니다.
# vi /etc/profile
export NLS_LANG=.KO16KSC5601    <= 이 부분을 오라클의 NLS_LANG 값에 맞게 추가합니다.
:wq
# source /etc/profile

아래 PHP 설치시...

./configure  옵션에
--with-oci8=instantclient,/usr/lib/oracle \

를 추가해 줍니다...
PHP 설치가 끝나고 난뒤 php.ini에서
;extension=php_oci8.dll
앞의 주석을 제거하시고 난뒤 아파치를 재시작 하시면 오라클에 접속되는 것을 확인할 수 있을겁니다.



#. 오라클 클라이언트 설치 2.

오라클 클라이언트는 위 1 이나 지금 2 둘 중에 한개만 해주면 됩니다.
둘 다 할 필요는 없습니다.

http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html 

원하는 버전의.. 두개를

oracle-instantclient-basic-10.1.0.3-1.i386.rpm
oracle-instantclient-devel-10.1.0.3-1.i386.rpm

다운받아서... rpm 으로 설치합니다. 그러면...

rpm -Uvh oracle-instantclient-basic-10.1.0.3-1.i386.rpm
rpm -Uvh oracle-instantclient-devel-10.1.0.3-1.i386.rpm

첫 번째 RPM은 오라클 라이브러리를 /usr/lib/oracle/10.1.0.3/client/lib에 설치하고,
두 번째 RPM은 /usr/include/oracle/10.1.0.3/client에 헤더를 생성합니다.
두 개의 파일이 다 필요합니다. sdk 파일이 없으면 php 컴파일이 되질 않습니다.

php 컴파일시 libclntsh.so 파일이 없다는 에러를 막기위해 해당디렉토리로 이동한 후
심볼릭 링크를 걸어줍니다.

새로운 매개변수는 기존의 --with-oci8 매개변수를 대체합니다.

오라클 환경변수를 셋팅해줍니다.
# vi /etc/profile
export NLS_LANG=.KO16KSC5601    <= 이 부분을 오라클의 NLS_LANG 값에 맞게 추가합니다.
:wq
# source /etc/profile

아래 PHP 설치시...

./configure \
   --with-oci8-instant-client \ 

설치가 무사히 완료되면...
php.ini 파일을 --with-config-file-path에서 지정된 위치에 복사합니다.

LD_LIBRARY_PATH를 /usr/lib/oracle/10.1.0.3/client/lib으로 설정하고 Apache를 재시작합니다.

tnsnames.ora 파일을 이용하여 Oracle Net 서비스 네임을 정의한 경우, TNS_ADMIN을 파일이 위치한 디렉토리로 설정해 줍니다.

Apache를 시작하기 전에 모든 오라클 환경 변수를 설정해 주는 것이 중요합니다. 스크립트의 예가 아래와 같습니다:

#!/bin/sh

APACHEHOME=/home/apache

LD_LIBRARY_PATH=/usr/lib/oracle/10.1.0.3/client/lib:${LD_LIBRARY_PATH}
TNS_ADMIN=/home
export LD_LIBRARY_PATH TNS_ADMIN

echo Starting Apache
$APACHEHOME/apachectl start




난 1번의 경우로 설치했으므로... 이것은 패쓰...





3. PHP 설치

php 버전 : php-5.2.6.tar.bz2
http://www.php.net/get/php-5.2.6.tar.bz2/from/this/mirror

php 설치경로 : /usr/local/server/php

configure시 에러메세지 확인 후 libc-client와 libc-client-devel 패키지를 인스톨해 주었다.
그리고 net-snmp-devel 패키지도 설치해 주었다.

GUI를 설치하지 않은 서버용이라면 --with-xpm-dir 옵션은 사용하지 않는다.

아래의 configure 옵션 모두 복사 후 쉘에 붙여넣기 한다.
(\ 문자는 다음줄에 옵션을 계속 연결해서 쓰겠다는 의미)

./configure \
--prefix=/usr/local/server/php \
--with-apxs2=/usr/local/server/httpd/bin/apxs \
--with-mysql=/usr/local/server/mysql \
--with-mysqli=/usr/local/server/mysql/bin/mysql_config \
--with-pdo-mysql=/usr/local/server/mysql \
--with-oci8=instantclient,/usr/lib/oracle \
--with-config-file-path=/usr/local/server/httpd/conf \
--with-xsl=/usr/bin \
--enable-magic-quotes \
--enable-mod-charset \
--enable-mbstring \
--enable-sigchild \
--enable-safe-mode \
--enable-bcmath \
--enable-calendar \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--enable-ftp \
--with-snmp \
--with-openssl \
--with-zlib \
--with-zlib-dir \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-gd \
--enable-gd-native-ttf \
--with-ttf \
--with-gettext \
--enable-exif \
--with-xpm-dir \
--with-libxml-dir \
--with-pcre-dir \
--with-imap \
--with-imap-ssl \
--with-kerberos \
--with-curl \
--with-ncurses \
--enable-sqlite-utf8 \
--with-regex=php \
--with-bz2 \
--with-mcrypt



 

간혹 각종 라이브러리들이 설치가 안되어 있을 경우 설치시 에러가 발생하는데 이럴때에는 아래의 라이브러리 패키지를 설치해 주고, php를 처음부터 다시 컴파일 한다.

yum install libjpeg-devel -y
yum install libpng-devel -y
yum install libXpm-devel -y
yum install freetype-devel -y
yum install gd-devel -y
yum install libc-client -y
yum install libc-client-devel -y
yum install net-snmp-devel -y
yum install libmcrypt libmcrypt-devel -y



이걸 한방에 설치하려면...

yum install libjpeg-devel libpng-devel libXpm-devel freetype-devel gd-devel libc-client libc-client-devel net-snmp-devel libmcrypt libmcrypt-devel -y




컴파일 문제없이 잘됩니다.
[root@localhost APM]# pwd
/usr/local/src/APM
[root@localhost APM]# yum install libc-client libc-client-devel net-snmp-devel -y
[root@localhost APM]# wget http://www.php.net/get/php-5.2.6.tar.bz2/from/this/mirror
[root@localhost APM]# tar xjf php-5.2.6.tar.bz2
[root@localhost APM]# cd php-5.2.6
[root@localhost php-5.2.6]# ./configure --prefix=/usr/local/server/php --with-apxs2=/usr/local/server/httpd/bin/apxs --with-mysql=/usr/local/server/mysql --with-mysqli=/usr/local/server/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/server/mysql --with-config-file-path=/usr/local/server/httpd/conf --enable-magic-quotes --enable-mod-charset --enable-mbstring --enable-sigchild --enable-safe-mode --enable-bcmath --enable-calendar --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --enable-ftp --with-snmp --with-openssl --with-zlib --with-zlib-dir --with-jpeg-dir --with-png-dir --with-freetype-dir --with-gd --enable-gd-native-ttf --with-ttf --with-gettext --enable-exif --with-xpm-dir --with-libxml-dir --with-pcre-dir --with-imap --with-imap-ssl --with-kerberos --with-curl --with-ncurses --enable-sqlite-utf8 --with-regex=php --with-bz2 --with-mcrypt
creating cache ./config.cache
checking for Cygwin environment... no
checking for mingw32 environment... no
checking for egrep... grep -E
checking for a sed that does not truncate output... /bin/sed
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for gcc... gcc
checking whether the C compiler (gcc  ) works... yes
checking whether the C compiler (gcc  ) is a cross-compiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
checking how to run the C preprocessor... gcc -E

...  중간생략.

checking for Oracle (OCI8) support... yes

creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

[root@localhost php-5.2.6]#





[root@localhost php-5.2.6]# make
[root@localhost php-5.2.6]# make install


*** 아래와 같은 Error 발생시 **************************
/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status
make: *** [libphp5.la] 오류 1

*** 아래처럼 해준다 **********************************


# vi /etc/ld.so.conf
/usr/local/lib  추가 , 저장

# ldconfig

******************************************************

# make distclean 후 다시..

# make && make install



4. php 설치 후 php.ini 복사하기

[root@localhost php-5.2.6]# pwd
/usr/local/src/APM/php-5.2.6
[root@localhost php-5.2.6]# cp php.ini-dist /usr/local/server/httpd/conf/php.ini



5. 아파치 httpd.conf 에 php 확장자를 php 스크립트로 인식하도록 하기

[root@localhost php-5.2.6]# cd /usr/local/server/httpd/conf/
[root@localhost conf]# vi httpd.conf

<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

<IfModule mime_module>
...생략...
   #AddType text/html .shtml
    #AddOutputFilter INCLUDES .shtml

    AddHandler php5-script .phtml .php .inc .ini .html
    AddType application/x-httpd-php-source .phps .incs .inis


</IfModule>



6. phpinfo()함수 호출을 위한 페이지 작성

설치후 아파치의 기본 페이지 디렉토리가 /usr/local/server/httpd/htdocs 이므로 이 디렉토리 아래에 php.php 파일을 작성한다.

[root@localhost conf]# vi /usr/local/server/httpd/htdocs/php.php

<?php phpinfo(); ?>



7. php.php 파일에 접속

[root@localhost conf]# /etc/init.d/httpd start


* 쉘상에서 php와 mysql 명령을 경로를 적어주지 않고 php, mysql만 입력하여 사용하고자 한다면 PATH 변수에 실행 바이너리 파일의 경로를 추가해 주면 된다.

[root@localhost ~]# vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
       . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/server/php/bin:/usr/local/server/mysql/bin

export PATH
unset USERNAME
[root@localhost ~]# source .bash_profile
[root@localhost ~]# which php
/usr/local/server/php/bin/php
[root@localhost ~]# which mysql
/usr/local/server/mysql/bin/mysql
[root@localhost ~]#


http://localhost/php.php

apache, php, mysql에 대한 다른 추가적인 내용들은 CentOS 리눅스 구축관리실무 서적을 참고한다.
--끝--
출처 :
http://www.lug.or.kr/home/bbs/board.php?bo_table=centos_book&wr_id=65




기타 설정

httpd.conf 의 VirTualHost 내에 아래 내용을 넣으면
사이트 로딩과 동시에 AutoLoad.php 를 읽습니다.

[root@localhost conf]# vi /usr/local/server/apache/conf/httpd.conf

php_value auto_prepend_file "/home/fnf/public_html/_Config/AutoLoad.php"