2008. 12. 20. 20:14

웹서버 구축관리 / Apache , PHP , MySQL 설치 설정


■ 아파치 서버 설정

설치전 준비 사항
패키지 준비
0. httpd
0. php
0. mysql
0. gcc 관련 패키지
0. libjpeg , libpng , freetype , gd

■ 소스 다운로드
// 아파치
www.apache.org   --> http server --> from a mirror --> unix source
# cd /usr/src
# wget
http://mirror.apache-kr.org/httpd/httpd-2.2.11.tar.gz
// php
www.php.net  --> downloads --> php 5.x.x -
# wget
http://kr2.php.net/get/php-5.2.8.tar.gz/from/this/mirror
// mysql
www.mysql.org or mysql.com  --> downloads  --> Compressed GNU TAR archive (tar.gz)
--> pick a mirror -- >
# wget
http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.30.tar.gz/from/http://mysql.byungsoo.net/
# ls -l
-rw-r--r--  1 root   root    6806786 12월 13 23:35 httpd-2.2.11.tar.gz
-rw-r--r--  1 root   root   29050568 11월 20 08:19 mysql-5.1.30.tar.gz
-rw-r--r--  1 root   root   12427411 12월  8 04:43 php-5.2.8.tar.gz

 
라이브러리, 컴파일러 확인
# yum -y install gcc cpp gcc-c++ compat-gcc-32-g77 flex
# rpm -qa gcc* cpp* compat-gcc* flex*
gcc-c++-4.1.2-42.el5
gcc-objc++-4.1.2-42.el5
gcc-objc-4.1.2-42.el5
compat-gcc-34-3.4.6-4
gcc-java-4.1.2-42.el5
flex-2.5.4a-41.fc6
cpp-4.1.2-42.el5
compat-gcc-34-g77-3.4.6-4
gcc-gfortran-4.1.2-42.el5
gcc-4.1.2-42.el5
gcc-gnat-4.1.2-42.el5

# yum -y install libjpeg-devel libpng-devl freetype-devel gd-devel
# rpm -qa libjpeg* libpng* freetype* gd-*
libpng-1.2.10-7.1.el5_0.1
libjpeg-6b-37
gd-devel-2.0.33-9.4.el5_1.1
libjpeg-devel-6b-37
freetype-devel-2.2.1-20.el5_2
freetype-2.2.1-20.el5_2
libpng-devel-1.2.10-7.1.el5_0.1

■ MySQL 설치
# tar xvfz mysql-5.1.30.tar.gz
# useradd -M -s /bin/false mysql
# ./configure \
--prefix=/usr/local/mysql \
--with-charset=utf8 \
--with-extra-charsets=all
....
MySQL has a Web site at http://www.mysql.com/ which carries details on the
latest release, upcoming features, and other information to make your
work or play with MySQL more productive. There you can also find
information about mailing lists for MySQL discussion.
Remember to check the platform specific part of the reference manual for
hints about installing MySQL on your platform. Also have a look at the
files in the Docs directory.
Thank you for choosing MySQL!
# make && make install
....
# echo $?
0
#


// 환경 설정파일 복사 , 소스 폴더내에 있다.
# cp support-files/my-large.cnf /etc/my.cnf

 

my-huge.cnf 1~2G
my-large.cnf 512M
my-medium.cnf 128M~ 256M
my-small.cnf 64M
이하
초기 샘플 파일에 대해서..
vmware상에서 구현중 메모리 512로 잡고 하지만 vmware상 문제인지 small외에 사용하면
아래 install db가 되지 않는다.
또한 mysqld 시작시 위 파일들 때문에 시작이 안된다.. 혹시 안되는 분들이 있다면
rm -f /etc/my.cnf 하고 작업을 진행 하길. 문제 해결을 위해 검색 중이나
마땅히 해결책이 보이질 않고 있음..(vmware상의 문제로 보여짐)



// 기본 DB생성
# cd /usr/local/mysql
# cd bin
# ls
# ./mysql_install_db --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/bin/mysqladmin -u root password 'new-password'
/usr/local/bin/mysqladmin -u root -h fedora password 'new-password'
Alternatively you can run:
/usr/local/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr/local ; /usr/local/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/bin/mysqlbug script!
The latest information about MySQL is available at http://www.mysql.com/
Support MySQL by buying support/licenses from http://shop.mysql.com/
# echo $?
0
// 디렉토리 권한 설정
#  chown -R mysql:mysql .

// 환경변수 등록
# vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
# source ~/.bash_profile   < 로긴 과정 없이 적용 >

//자동실행 설정
# cp share/mysql/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --list mysqld

// mysqld 시작
# /etc/init.d/mysqld start
Starting MySQL.                                            [  OK  ]
# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.30 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> exit
Bye

// 암호 설정
# mysqladmin -u root password ****
# # mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.30 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> exit



■ APACHE 설치
# cd /usr/src
# ls
httpd-2.2.11.tar.gz
# tar xvfz httpd-2.2.11.tar.gz
# cd httpd-2.2.11
# ls
# ./configure --prefix=/usr/local/apache --enable-mods-shared=all --enable-so --enable-rewrite
// prefix ( 위치 ), enable-mods-shared=all (모든 모듈을 DSO로)
// enable-so    (DSO 모드 활성)
// enable-rewrite ( URL 재작성 모듈 활성)
# echo $?
# make && make install
# echo $?

■ 자동실행 스크립트 정의

# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
# chkconfig --add httpd
안됨
# vi /etc/init.d/httpd
#!/bin/sh
# chkconfig: 2345 90 90
# description: init file for Apache server daemon
# processname: /usr/local/apache/bin/apachectl
# config: /usr/local/apache/conf/httpd.conf
# pidfile: /usr/lcoal/apache/logs/httpd.pid
....
# chkconfig --add httpd
# chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

■ httpd.conf  환경 설정
# vi /usr/local/apache/conf/httpd.conf
#ServerName    << 주석 해체
# /etc/init.d/httpd restart

웹브라우저에서 접속 테스트



■ PHP  설치
# cd /usr/src
# ls
         php-5.2.8.tar.gz
# tar xvzf php-5.2.8.tar.gz 
# cd php-5.2.8
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/apache/conf --disable-debug --enable-safe-mode --enable-track-vars --enable-sockets --enable-mod-charset --with-charset=utf8 --with-xml --with-language=korean --enable-mailparse --enable-calendar --enable-sysvsem=yes --enable-sysvshm=yes --enable-ftp --enable-magic-quotes --enable-gd-native-ttf --enable-url-includes --enable-trans-id --enable-inline-optimization --enable-bcmath --with-jpeg --with-png --with-zlib --with-jpeg-dir=/usr --with-png-dir=/usr/lib --with-freetype-dir=/usr --with-libxml-dir=/usr --enable-exif --with-gd --with-ttf --with-gettext --enable-sigchild --enable-mbstring
prefix ( 위치)
with-apxs2 (아파치의 apxs를 이용해 아파치에 모듈적재)
with-mysql (mysql과 연동)
with-config-file-path ( php 의 환경설정 파일인 php.ini가 생성될 위치)
이하 라이브러리 포함 위치

....
+--------------------------------------------------------------------+
| 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.
Notice: Following unknown configure options were used:
--enable-track-vars
--with-charset=utf8
--with-xml
--with-language=korean
--enable-mailparse
--enable-calender
--enable-url-includes
--enable-trans-id
--with-jpeg
--with-png            << 없는 옵션일 경우 출력됨
Check './configure --help' for available options
# echo $?
0
# make && make install
# cp php.ini-dist /usr/local/apache/conf/php.ini
# vi /usr/local/apache/conf/httpd.conf
<IfModule dir_module>
    DirectoryIndex index.html index.html index.php
</IfModule>
<IfModule mime_module>
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
</IfModule>
# vi /usr/local/apache/htdocs/phpinfo.php
<? phpinfo(); ?>
# /etc/init.d/httpd restart
웹브라우저에서 확인




■ apache 환경 설정   ( # vi /usr/local/bin/apache/conf/httpd.conf )
ServerRoot "/usr/local/apache"
# 아파치 웹서버가 설치된 디렉토리

Listen 80
# 아파치가 사용할 포트번호

LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_anon_module modules/mod_authn_anon.so
# 아파치에 등록된 모듈목록

<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>
User daemon
Group daemon
</IfModule>
</IfModule>
# 아파치 데몬은 root권한 그 자식 프로세스는 위에서 지정된 이름으로 실행된다.

ServerAdmin you@example.com
# 에러 발생시 보내질 서버관리자의 주소

DocumentRoot "/usr/local/apache/htdocs"
# 아파치서버의 웹문서가 있는 경로 설정

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>
# 해당 디렉토리 이하의 웹문서를 어떻게 제어할 것인가를 설정


-AllowOverride 는 디렉토리 인증 관련 AccessFileName과 관련

-Order   는 차단 허용에 대한 기본값 설정

<IfModule dir_module>
    DirectoryIndex index.html index.html index.php
</IfModule>
# 클라이언트가 파일이름없이 접근시 나열된 파일을 순서대로 검색하여 보여준다.

<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>
# 특정한 파일형식을 정규표현식으로 지정해서 해당 파일에 대한 접근 제어을 설정할때 사용

ErrorLog "logs/error_log"
# 에러로그파일 위치

LogLevel warn
# 에러로그레벨 지정

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "logs/access_log" common
</IfModule>
# 웹서버 로그 포멧 지정

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
</IfModule>
# Redirect지시어는 앞에 지정한 주소로 접속하면 뒤에 지정한 URL로 이동한다.
# Alias 지시어는 경로를 짧게 줄이거나 DocumentRoot 외에 다른곳에 있는 디렉토리 접근
# ScriptAlias 는 서버 스크립트를 포함한다.

<IfModule cgid_module>
    #Scriptsock logs/cgisock
</IfModule>
# CGI 데몬과 통신을 위해 사용할 소켓의 이름 지정

<Directory "/usr/local/apache/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>
# cgi 스크립트가 있는 디렉토리의 설정내용

DefaultType text/plain
# 웹서버가 데이터를 전송하는 문서 형식 지정, mime.types파일에 정의되지않는 형식을 표시

<IfModule mime_module>
    TypesConfig conf/mime.types
# 웹서버의 mime type을 지정한 파일을 지정
# Addtype 특정 확장자 지정
# AddEncoding 특정 확장자를 가진 파일을 특정 형식으로 인코딩
# AddHandler 특정 확장자를 가진 파일의 핸들러를 지정한다.
    #AddType application/x-gzip .tgz
    #AddEncoding x-compress .Z
    #AddEncoding x-gzip .gz .tgz
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    #AddHandler cgi-script .cgi
    # For type maps (negotiated resources):
    #AddHandler type-map var
    #AddType text/html .shtml
    #AddOutputFilter INCLUDES .shtml
</IfModule>

#MIMEMagicFile conf/magic
# RFC 형식이 지정되어있지 않을때 파일의 내용을 통해 자동적으로 결정하게 되는데 해당 지시어를 # 통해서 conf/magic 파일을 힌트 삼아서 문서 형식을 결정

#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
# 에러 발생시 응답 페이지

#EnableMMAP off
#EnableSendfile off
# 메모리 대응 or 메모리 매핑

#Include conf/extra/httpd-mpm.conf
# 다중 처리 모듈

#Include conf/extra/httpd-multilang-errordoc.conf
# 에러메시지 다중언어 지원

#Include conf/extra/httpd-autoindex.conf
# 클라에게 보여줄 디렉토리 목록 설정
#Include conf/extra/httpd-languages.conf
# 다중 언어를 지원키 위한 설정 파일
# User home directories
#Include conf/extra/httpd-userdir.conf
# 사용자 홈 디렉토리 설정 파일
# Real-time info on requests and configuration
#Include conf/extra/httpd-info.conf
# 아파치 웹서버의 상태와 환경설정 제공 파일
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
# 가상호스트 설정파일
# Local access to the Apache HTTP Server Manual
#Include conf/extra/httpd-manual.conf
# 아파치 메뉴얼
# Distributed authoring and versioning (WebDAV)
#Include conf/extra/httpd-dav.conf
# 웹사이트 개발도구 WebDAV 지원 모듈
# Various default settings
#Include conf/extra/httpd-default.conf
# 아파치 기본 설정 파일
# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf
# 보안 소켓 레이어
#
# Note: The following must must be present to support
#       starting without SSL on platforms with no /dev/random equivalent
#       but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
# 보안 소켓 레이어 모듈이 Load되어질때, 인터넷을 통해 비공개문서를 전송키위해 사용