APM이라는 말이 널리 이용될정도로 Apache + PHP + MySQL을 이용한 웹서비스들이 많이 생겼습니다.
Apache라는 웹서버는 초기 강력한 기능등으로 웹서버의 카테고리 킬러로 통할정도로 높은 점유율을 보유하고 있었습니다.
그런데 이 Apache가 범용적인 기능을 많이 보유하고 있고 또 메모리나 자원 점유율이 높은 편입니다.
아파치 1.x는 process단위이고 2.x는 thread를 이용하여 조금더 나아졌지만 자원 소모량등이 많은 것은 여전합니다.
이에 반해 lighttpd 는 non-blocking I/O로 단일 프로세스에서 실행되어 보다 가볍고 빠르다는 장점이 있습니다.
그리고 PHP를 다룰때 fastcgi기반으로 사용하기에 아파치의 mod_php와 비슷하거나 훨씬 빨라졌습니다.
lighttp는 apache의 모듈을 거의 다 쓸수 있다고 하네요. (실제 제게 필요한 모듈들은 다 있습니다)
lighttp에 php (enable fastcgi)를 연동하고 최근 각광받는 xcache를 이용하여 기존의 아파치+PHP보다 가볍고 빠른 웹서버 구축에 대해서 간단히 글을 쓰겠습니다.
php 설치
여기서는 php 5.2.0 을 기준으로 설치하도록 하겠습니다.
./configure의 옵션은 적당히 알아서 해주시면 됩니다. ( \ 역슬래시는 줄나눔의 의미이니 주의하세요)
view plaincopy to clipboardprint?
wget
http://kr2.php.net/get/php-5.2.0.tar.gz/from/this/mirror
tar xvfz php-5.2.0.tar.gz
cd php-5.2.0
./configure \
--prefix=/usr/local/php \
--with-exec-dir=/usr/bin \
--with-mysql \
--with-sqlite \
--with-config-file-path=/etc \
--disable-debug \
--enable-sockets \
--with-png-dir=/usr/lib \
--with-freetype-dir=/usr/include/freetype2 \
--enable-mod-charset \
--enable-calendar \
--enable-sysvsem=yes \
--enable-sysvshm=yes \
--enable-ftp \
--enable-magic-quotes \
--enable-gd-native-ttf \
--enable-inline-optimization \
--enable-bcmath \
--with-zlib \
--with-jpeg-dir=/usr/src \
--with-gd \
--with-ttf \
--with-gettext \
--enable-sigchild \
--with-libxml-dir=/usr/local/src/libxml2-2.6.11 \
--with-zlib-dir=/usr/local/src/zlib-1.2.1 \
--with-iconv \
--enable-fastcgi \
--enable-force-cgi-redirect
make
make install
wget
http://kr2.php.net/get/php-5.2.0.tar.gz/from/this/mirror
tar xvfz php-5.2.0.tar.gz
cd php-5.2.0
./configure \
--prefix=/usr/local/php \
--with-exec-dir=/usr/bin \
--with-mysql \
--with-sqlite \
--with-config-file-path=/etc \
--disable-debug \
--enable-sockets \
--with-png-dir=/usr/lib \
--with-freetype-dir=/usr/include/freetype2 \
--enable-mod-charset \
--enable-calendar \
--enable-sysvsem=yes \
--enable-sysvshm=yes \
--enable-ftp \
--enable-magic-quotes \
--enable-gd-native-ttf \
--enable-inline-optimization \
--enable-bcmath \
--with-zlib \
--with-jpeg-dir=/usr/src \
--with-gd \
--with-ttf \
--with-gettext \
--enable-sigchild \
--with-libxml-dir=/usr/local/src/libxml2-2.6.11 \
--with-zlib-dir=/usr/local/src/zlib-1.2.1 \
--with-iconv \
--enable-fastcgi \
--enable-force-cgi-redirect
make
make install
이렇게 하면 php의 설치가 완료됩니다.
--enable-fastcgi, --enable-force-cgi-redirect는 필수입니다.
php.ini 파일은 /etc 디렉토리에 있는 것으로 설정하였습니다.
Zend Optimizer, eAccelerator등의 설치에 대해서는 소개하지 않습니다. :)
xcache 설치
xcache는 제로보드XE와 같은 class/object기반의 프로그램들을 보다 빠르고 가볍게 해주는 캐쉬 프로그램입니다.
APC나 eaccelerator 속도도 더 빠르다고 알려져 있구요.
php5.2.0에 돌아가는 xcache 1.2.1 을 기준으로 설치법을 알려드립니다.
wget
http://xcache.lighttpd.net/pub/Releases/1.2.1/xcache-1.2.1.tar.gz
tar xvfz xcache-1.2.1.tar.gz
cd xcache-1.2.1
phpize
./configure --enable-xcache --enable-xcache-coverager
make
make install
cat xcache.ini >> /etc/php.ini
위에서 phpize나 configure시에 php 실행파일들의 경로 문제가 생길 수 있습니다.
1번처럼 php를 /usr/local/php/bin 에 실행파일이 생기게 했다면 아래와 같이 미리 PATH를 지정해주세요.
export PATH="$PATH:/usr/local/php/bin"
그 다음 /etc/php.ini 파일을 여세요.
만약 zend optimizer등을 설치하였다면 xcache 설정중 zend_extension이 zend optimizer보다 위에 있어야 합니다.
저는 아래와 같이 설정하였습니다.
view plaincopy to clipboardprint?
[xcache-common]
zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so
[xcache.admin]
xcache.admin.auth = On
xcache.admin.user = "관리자 아이디"
xcache.admin.pass = "md5 hash 비밀번호"
[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 64M
xcache.count = 4
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0
xcache.var_size = 64M
xcache.var_count = 4
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = On
;xcache.mmap_path = "/tmp/xcache"
xcache.mmap_path = "/dev/zero"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = On
[xcache.coverager]
xcache.coverager = On
xcache.coveragedump_directory = ""
[xcache-common]
zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so
[xcache.admin]
xcache.admin.auth = On
xcache.admin.user = "관리자 아이디"
xcache.admin.pass = "md5 hash 비밀번호"
[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 64M
xcache.count = 4
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0
xcache.var_size = 64M
xcache.var_count = 4
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = On
;xcache.mmap_path = "/tmp/xcache"
xcache.mmap_path = "/dev/zero"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = On
[xcache.coverager]
xcache.coverager = On
xcache.coveragedump_directory = ""
위의 설정중 xcache.admin.user와 xcache.admin.pass는 xcache 관리자 페이지를 사용할 경우 입력해주면 됩니다.
참고로 관리자 페이지는 xcache 소스중 admin 이라는 디렉토리에 있고 이 admin 디렉토리를 웹에서 접근할 수 있는 곳에 복사해주시면 됩니다.
xcache.size나 xcache.var_size는 적절히 해주시면 됩니다.
xcache.count와 xcache.var_count는 cpu process의 수를 적어주시면 됩니다.
cat /proc/cpuinfo |grep -c processor
위와 같이 명령어를 입력하면 프로세스의 수가 나옵니다.
lighttp 설치
공식사이트 :
http://www.lighttpd.net
설치방법 ( 2007년 12월 24일 현재 최신 버전 기준)
view plaincopy to clipboardprint?
wget
http://www.lighttpd.net/download/lighttpd-1.4.18.tar.gz
tar xvfz lighttpd-1.4.18.tar.gz
cd lighttpd-1.4.13
./configure --with-pcre
make
make install
cp doc/lighttpd.conf /etc
wget
http://www.lighttpd.net/download/lighttpd-1.4.18.tar.gz
tar xvfz lighttpd-1.4.18.tar.gz
cd lighttpd-1.4.13
./configure --with-pcre
make
make install
cp doc/lighttpd.conf /etc
위와 같이 하면 설치가 완료됩니다.
설정 파일
위 설치방법에서 lighttpd.conf 파일을 /etc 로 이동시켰습니다.
vi /etc/lighttpd.conf 해서 수정 작업 들어갑니다.
lighttpd의 경우 기본적으로 아파치에서 유용하게 사용되는 모듈들을 포함하고 있고 이를 사용하는 것은 lighttpd.conf 파일의 주석을 제거함으로 바로 사용가능합니다.
일단 lighttpd.conf 파일의 제일 위 부분을 보면 아래와 같습니다.
view plaincopy to clipboardprint?
server.modules = (
"mod_rewrite",
# "mod_redirect",
# "mod_alias",
"mod_access",
# "mod_cml",
# "mod_trigger_b4_dl",
"mod_auth",
# "mod_status",
# "mod_setenv",
"mod_fastcgi",
# "mod_proxy",
"mod_simple_vhost",
# "mod_evhost",
# "mod_userdir",
# "mod_cgi",
"mod_compress",
# "mod_ssi",
# "mod_usertrack",
# "mod_expire",
# "mod_secdownload",
# "mod_rrdtool",
"mod_accesslog"
)
server.modules = (
"mod_rewrite",
# "mod_redirect",
# "mod_alias",
"mod_access",
# "mod_cml",
# "mod_trigger_b4_dl",
"mod_auth",
# "mod_status",
# "mod_setenv",
"mod_fastcgi",
# "mod_proxy",
"mod_simple_vhost",
# "mod_evhost",
# "mod_userdir",
# "mod_cgi",
"mod_compress",
# "mod_ssi",
# "mod_usertrack",
# "mod_expire",
# "mod_secdownload",
# "mod_rrdtool",
"mod_accesslog"
)
# 은 주석을 의미합니다.
즉 필요치 않은 모듈은 #을 줄앞에 붙여줌으로서 사용하지 않도록 하면 됩니다.
그외 설정은 아래를 따르면 됩니다.
view plaincopy to clipboardprint?
server.document-root = "/home/..../public_html"; # document root 지정
server.error_log = "/var/log/lighttpd/error.log"; # 에러 로그 저장. 디렉토리 생성해주세요.
index-file.name = ( "index.php", "index.html", "index.htm", "default.htm") # index file 지정
mimetype.assign = ... # 그냥 두시면 됩니다.
accesslog.filename = "/var/log/lighttpd/access.log"; # access log 저장
url.access-deny = ( "~", ".inc") # 특정 파일 형식에 대해 접근 금지 시킬 수 있습니다.
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" ) # mod_fastcgi나 mod_cgi 사용시 지정될 파일입니다.
# 아파치의 vhost와 같은 정의를 아래와 같이 쉽게 할 수 있습니다. 도메인에 대한 document-root 지정
# 1개 이상의 vhost일 경우 아래 3라인을 복사해서 주죽 써나가시면 됩니다.
# 좀 더 쉽게 하려면 가상호스트 모듈 mod_evhost를 이용하면 됩니다.
$HTTP["host"] == "www2.zerophp.com" {
server.document-root = "/home/DOMAINS/WWW"
}
# mod_evhost 사용시 vhost 지정
# %3 는 subdomain 1의 이름입니다. 아래와 같은 패턴이 정의되어 있습니다.
# %% => % sign
# %0 => domain name + tld
# %1 => tld
# %2 => domain name without tld
# %3 => subdomain 1 name
# %4 => subdomain 2 name
evhost.path-pattern = "/var/www/hosts/%3/"
server.username = "nobody" # 웹서버가 사용한 uid
server.groupname = "nobody" # 웹서버가 사용할 gif
# 아래가 php의 fastcgi 연결 부분입니다.
# 다른 부분은 그대로 두고 --enable-fastcgi, --enable-force-cgi-redirect 옵션으로 컴파일한 php 실행 파일 경로만 신경쓰시면 됩니다.
fastcgi.server = ( ".php" => ( "localhost" => ( "socket" =>
"/var/run/lighttpd/php-fastcgi.socket", "bin-path" =>
"/usr/local/php/bin/php" )))
server.document-root = "/home/..../public_html"; # document root 지정
server.error_log = "/var/log/lighttpd/error.log"; # 에러 로그 저장. 디렉토리 생성해주세요.
index-file.name = ( "index.php", "index.html", "index.htm", "default.htm") # index file 지정
mimetype.assign = ... # 그냥 두시면 됩니다.
accesslog.filename = "/var/log/lighttpd/access.log"; # access log 저장
url.access-deny = ( "~", ".inc") # 특정 파일 형식에 대해 접근 금지 시킬 수 있습니다.
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" ) # mod_fastcgi나 mod_cgi 사용시 지정될 파일입니다.
# 아파치의 vhost와 같은 정의를 아래와 같이 쉽게 할 수 있습니다. 도메인에 대한 document-root 지정
# 1개 이상의 vhost일 경우 아래 3라인을 복사해서 주죽 써나가시면 됩니다.
# 좀 더 쉽게 하려면 가상호스트 모듈 mod_evhost를 이용하면 됩니다.
$HTTP["host"] == "www2.zerophp.com" {
server.document-root = "/home/DOMAINS/WWW"
}
# mod_evhost 사용시 vhost 지정
# %3 는 subdomain 1의 이름입니다. 아래와 같은 패턴이 정의되어 있습니다.
# %% => % sign
# %0 => domain name + tld
# %1 => tld
# %2 => domain name without tld
# %3 => subdomain 1 name
# %4 => subdomain 2 name
evhost.path-pattern = "/var/www/hosts/%3/"
server.username = "nobody" # 웹서버가 사용한 uid
server.groupname = "nobody" # 웹서버가 사용할 gif
# 아래가 php의 fastcgi 연결 부분입니다.
# 다른 부분은 그대로 두고 --enable-fastcgi, --enable-force-cgi-redirect 옵션으로 컴파일한 php 실행 파일 경로만 신경쓰시면 됩니다.
fastcgi.server = ( ".php" => ( "localhost" => ( "socket" =>
"/var/run/lighttpd/php-fastcgi.socket", "bin-path" =>
"/usr/local/php/bin/php" )))
거의 대부분 기본 설정을 쓰시면 됩니다.
다만 사용하려는 모듈의 지정과 fastcgi.server, vhost 등 실제 값이 필요한 부분만 설정해주시면 됩니다.
실행은 다음과 같이 하면 됩니다.
lighttpd -f /etc/lighttpd.conf
일단 php with fastcgi, xcache, lighttpd 설치와 설정에 대해서 간단히 적었습니다.
더 상세히 적고 싶지만 저 역시 아직 공부하는 중이라 필요한 부분들만 적었습니다.
서버 관리를 하신다면 그렇게 어렵지 않을 거라 생각합니다.
참고로.. 제로보드XE에서 주소를 이쁘게 하는 mod_rewrite를 lighttpd에서도 쓸수 있는데 이걸 각 서브도메인별로 지정하는걸 모르겠네요.
일단 저는 lighttpd.conf에 지정해 놓았습니다.
먼저 server.module에서 mod_rewrite를 사용하게 해 놓으시구요.
view plaincopy to clipboardprint?
url.rewrite = (
"^/([a-zA-Z0-9_]+)/files/attach/images/(.*)" => "./files/attach/images/$2",
"^/([a-zA-Z0-9_]+)/modules/(.*)" => "./modules/$2",
"^/([a-zA-Z0-9_]+)/common/(.*)" => "./common/$2",
"^/([a-zA-Z0-9_]+)/([[:digit:]]+)page$" => "./index.php?mid=$1&page=$2",
"^/rss/([[:digit:]]+){0,14}/([[:digit:]]+){0,14}/([[:digit:]]+)$"
=>
"./index.php?module=rss&act=rss&start_date=$1&end_date=$2&page=$3",
"^/rss/([[:digit:]]+)$" => "./index.php?module=rss&act=rss&page=$1",
"^/rss$" => "./index.php?module=rss&act=rss",
"^/admin$" => "./index.php?module=admin",
"^/([a-zA-Z0-9_]+)/api$" => "./index.php?mid=$1&act=api",
"^/([[:digit:]]+)$" => "./index.php?document_srl=$1",
"^/([[:digit:]]+)/([a-zA-Z0-9_]+)$" => "./index.php?document_srl=$1&act=$2",
"^/([[:digit:]]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)$"
=> "./index.php?document_srl=$1&act=$3&key=$2",
"^/([a-zA-Z0-9_]+)/([[:digit:]]+)$" => "./index.php?mid=$1&document_srl=$2",
"^/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)$" => "./index.php?mid=$1&act=$2",
"^/([a-zA-Z0-9_]+)/page/([[:digit:]]+)$" => "./index.php?mid=$1&page=$2",
"^/([a-zA-Z0-9_]+)/category/([[:digit:]]+)$" => "./index.php?mid=$1&category=$2",
"^/([a-zA-Z0-9_]+)/category/([[:digit:]]+)/page/([[:digit:]]+)$"
=> "./index.php?mid=$1&category=$2&page=$3",
"^/([a-zA-Z0-9_]+)/([[:digit:]]+)/([[:digit:]]+)$"
=>
"./index.php?mid=$1&search_target=regdate&search_keyword=$2$3",
"^/([a-zA-Z0-9_]+)/([[:digit:]]+)/([[:digit:]]+)/([[:digit:]]+)$"
=>
"./index.php?mid=$1&search_target=regdate&search_keyword=$2$3$4",
"^/([a-zA-Z0-9_]+)/tag/(.*)$" => "./index.php?mid=$1&search_target=tag&search_keyword=$2",
"^/([a-zA-Z0-9_]+)/writer/(.*)$"
=>
"./index.php?mid=$1&search_target=nick_name&search_keyword=$2",
"^/([a-zA-Z0-9_]+)(/){0,1}$" => "./index.php?mid=$1" )
http://www.82i.com/@/zboard.php?id=faq&page=1&sn1=&divpage=1&sn=off&ss=on&sc=on&select_arrange=headnum&desc=asc&no=42