티스토리 뷰

Apache Php MySQL 설치 하기 V 1.0


APM
Apache Web Server, Php, MySQL의 약자로서, 웹서버를 설치하기 위한 기본 컴포넌트 프로그램이다. 흔히 웹서버를 셋업할때 APM을 설치한다고 표현한다.

APM
와 관련된 프로그램을 설치하는 방법을 알아보자.

1. 프로그램의 다운로드
- Apache Web Server : http://www.apache.org
- PHP : http://www.php.net
- MySQL : http://www.mysql.com
*
다음은 관련된 프로그램이다.

- gd : http://www.boutell.com/gd

: gd library는 웹상에서 챠트나 그래픽, 썸네일 같은 그래픽 표현을 하기 위해 C, PHP, Perl같은 언어를 지원하는 그래픽 라이브러리이다. PNG, JPG, GIF 파일을 만들고 상호 지원한다.

- freetype : http://freetype.sourceforge.net

: freetype는 웹상의 글꼴을 처리하기 위한 폰트 엔진 프로그램이다.

* Zend Optimizer PHP 5 버전이상에 내장되어 있어 별도 설치할 필요가 없다.


2.
다운로드 받은 애플리케이션들을 서버에 저장한다.

일반적으로 /usr/local/source 라는 디렉토리를 만들고 여기에 넣는다.


3.
기존 리눅스에 설치된 APM 모듈 제거하기

기존 리눅스에 이미 APM이나 관련 애플리케이션이 설치되어 있는 것을 제거해야 한다.

우선 데몬으로 작동이라면 데몬을 내려야 하는 과정을 거쳐야 한다.

# ps –ef | grep httpd

# ps –ef | grep mysqld

해서 만일 데몬이 떠 있다면, 각각

# killall httpd

# killall mysqld

데몬을 내렸다면 이젠 RPM 패키지를 제거해야 한다.

# rpm –qa | grep httpd

# rpm -qa | grep httpd

system-config-httpd-1.3.3-1.1

httpd-2.2.0-5.1.2

두개의 패키지가 설치되어 있는데 이를 모두 제거한다. 제거하는 명령어는

# rpm -e --nodeps httpd-2.2.0-5.1.2

# rpm -e --nodeps system-config-httpd-1.3.3-1.1

* nodeps 옵션은 의존성 문제를 없애기 위한 것이다. 제거하려는 프로그램을 다른 패키지가 의존성가지고 있으면 삭제가 되지 않기에 붙여주는 옵션이다.

같은 방법으로 mysql, php, gd, freetype도 찾아보고 삭제한다.

# rpm -qa | grep mysqld

# rpm -qa | grep php

# rpm -qa | grep gd

# rpm -qa | grep freetype

주의할 것은 반드시 해당 패키지만 지워야 한다. 예를들어 gd관련 패키지를 찾는데 gdbm도 같이 검색되어 나오는데 이런 패키지는 지우면 안된다.


4. MySQL
설치하기

제일 먼저 MySQL을 설치해야 한다.

우선 mysql 그룹과 mysql 사용자가 등록되어 있어야 설치가 가능하므로

/etc/passwd 파일과 /etc/group 파일에서 mysql이 있는지 찾아본다.

없다면 만들어 주어야 한다.

# groupadd mysql

# useradd -g mysql mysql

압축된 파일을 풀어야 한다.

우선 압축 파일이 있는 디렉토리로 이동한다.

# cd /usr/local/source

압축을 해제한다. (압축해제와 tar를 푼다.)

# tar xvfz mysql* (자세한 파일명 입력)

긴 이름의 디렉토리를 mysql로 바꾼다.

# mv mysql* (자세한 파일명 입력) mysql

# cd mysql (/usr/local/source/mysql)

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

--prefix=/usr/local/mysql  설치 디렉토리 지정

--with-charset=euckr 한글 지원

--localstatedir=/usr/local/mysql/data  데이타 저장 디렉토리 지정

# make

# make install

설치는 끝났다.

사용을 위한 기초 DB를 만들어 주어야 한다.

# scripts/mysql_install_db

DB 생성 후에는 데이터가 생성되는 폴더의 권한을 mysql로 바꾸어 주어야 한다.

# chown -R mysql:mysql /usr/local/mysql/data

다음으로 환경 설정 파일을 /etc/my.cnf 로 복사한다.

# cp support-files/my-medium.cnf /etc/my.cnf

mysql 의 데몬스크립트인 mysql.server 파일에 mysql_safe가 실행되는 라인에 language 옵션을 추가해 준다.

# vi /usr/local/mysql/share/mysql/mysql.server

$bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file >/dev/null 2>&1 &

$bindir/mysqld_safe --datadir=$datadir --language=korean --pid-file=$server_pid_file >/dev/null 2>&1 &

mysql 경로 추가

# vi /root/.bash_profile

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

마지막으로 부팅시 자동 실행이 되도록 만들어 준다.

링크를 걸어 주어야 한다. Run Level 3 5 모두에 링크를 걸어야 한다.

# cp -p /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld

# ln -s /etc/rc.d/init.d/mysqld /etc/rc.d/rc3.d/S90mysqld

# ln -s /etc/rc.d/init.d/mysqld /etc/rc.d/rc5.d/S90mysqld

이제 mysql을 구동시켜 보자

# /etc/rc.d/init.d/mysqld start

/etc/rc.d/init.d/mysqld start

떠 있는지 확인해 보려면

# ps -ef|grep mysqld

root     29017     1  0 12:54 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --language=korean --pid-file=/usr/local/mysql/data/서버명.pid

mysql    29047 29017  0 12:54 pts/1    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/서버명.pid --skip-locking --port=3306 --socket=/tmp/mysql.sock --language=korean

root     29067 11175  0 12:55 pts/1    00:00:00 grep mysqld

초기 구동후 패스워드를 설정해 준다.

# ./mysqladmin -u root password 원하는패스워드

mysql로 들어가기

# ./mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5 to server version: 5.0.21-log

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

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema   |

| mysql                |

| test                 |

+--------------------+

3 rows in set (0.00 sec)


5. freetype
설치

# cd /usr/local/source

# tar xvfz freetype-2.2.1*

# cd freetype-2.2.1

# ./configure

# make

# make install


6. gd
설치

# cd /usr/local/source

# tar xvf gd-2.0.33.tar.tar

# cd gd-2.0.33

# ./configure --prefix=/usr/local/gd --with-freetype=/usr/local/include/freetype2

# make

# make install


7. Apache
설치-1

# cd /usr/local/source

# tar xvfz apache_1.3.36.tar.gz

# mv apache_1.3.36 apache (디렉토리 이름을 바꾸어 준다.)

# cd apache

# ./configure --prefix=/usr/local/apache


8. php
설치

# cd /usr/local/source

# tar xvfz php-5.1.4.tar.gz

# cd php-5.1.4

# ./configure --with-config-file-path=/etc --with-exec-prefix=/usr/bin --with-mysql=/usr/local/mysql --with-apache=../apache --with-gd=/usr/local/gd --with-freetype-dir=/usr/local/include/freetype2 --with-jpeg-dir=/usr/lib/ --with-png-dir=/usr/lib/ --with-zlib-dir=/usr/lib/ --with-language=korean --with-charset=euc-kr --enable-track-vars --enable-safe-mode --enable-gd-native-ttf

(일일히 입력하기 어려우면 copy & paste하자)

# make

# make install

php 환경 설정 파일 복사

# cp ./php.ini-dist /etc/php.ini


9. Apache
설치-2

# cd /usr/local/source/apache

# ./configure --prefix=/usr/local/apache --activate-module=src/modules/php5/libphp5.a --activate-module=src/modules/standard/mod_rewrite.c --enable-module=so --enable-shared=max --sysconfdir=/usr/local/apache/conf --htdocsdir=/usr/local/apache/htdocs --logfiledir=/var/log/httpd

# make

# make install


다음과 같은 화면을 만난다면 설치가 완료된 것이다.

+--------------------------------------------------------+

| You now have successfully built and installed the                  |

| Apache 1.3 HTTP server. To verify that Apache actually             |

| works correctly you now should first check the                     |

| (initially created or preserved) configuration files                   |

|                                                                 |

|   /usr/local/apache/conf/httpd.conf

|                                                                 |

| and then you should be able to immediately fire up                 |

| Apache the first time by running:                                   |

|                                                                |

|   /usr/local/apache/bin/apachectl start

|                                                                 |

| Thanks for using Apache.       The Apache Group                 |

|                               http://www.apache.org/          |

+--------------------------------------------------------+

이제 httpd 설정을 바꾸어 주어야 한다.

# cd /usr/local/apache/conf

# vi httpd.conf

ServerName www.example.com

-> SeverName 서버명

디렉토리 보안을 위해 Indexes를 없애준다.

Options Indexes FollowSymLinks MultiViews

-> Options FollowSymLinks MultiViews

<IfModule mod_userdir.c>

  UserDir public_html

</IfModule>

->

<IfModule mod_userdir.c>

  UserDir html

</IfModule>

<IfModule mod_dir.c>

  DirectoryIndex index.html

</IfModule>

->

<IfModule mod_dir.c>

  DirectoryIndex index.html index.php

</IfModule>

AddType을 추가한다.

AddType application/x-tar .tgz

->

AddType application/x-tar .tgz

AddType application/x-httpd-php .php .php3 .inc .ph .htm .html

AddType application/x-httpd-php-source .phps

이제 모든 설정이 끝나고 부팅이 될 때 자동으로 실행되도록 링크를 걸어준다.

# cp -p /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd

# ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S99httpd

# ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc5.d/S99httpd

# /etc/rc.d/init.d/httpd start (실행)

PHP가 정상 작동하는지를 알아보기 위해 test.php를 만들어 /usr/local/apache/htdocs에 넣고 브라우저로 확인해 보자.

# vi test.php

<html>       

  <?php

  phpinfo();

  ?>

  </html>

정상적으로 버전 표시가 상세히 나온다면 완벽하게 설치가 된 것이다.

이로서 모든 설정은 끝났다.


PS. 한글이 깨지면 http://cusee.net/23 참고

반응형
댓글