2008年11月3日 星期一

Lighttpd+Mysql+PHP+GD 安裝

lighttpd 安裝
安裝 PHP as FastCGI
安裝 lighttpd Web Server
PHP extensions 安裝備忘
eAccelerator: PHP 加速器
htscanner: .htaccess 的 PHP 應用
操作環境 CentOS4.4
==========================================================
安裝MYSQL mysql-max-5.0.27-linux-i686-glibc23.tar.gz

groupadd mysql
useradd -g mysql mysql
cd /usr/local
這裡解壓
tar -zxvf /root/mysql-max-5.0.27-linux-i686-glibc23.tar.gz
mv mysql-max-5.0.27-linux-i686-glibc23/ mysql
cd mysql
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
chgrp -R mysql .
bin/mysqld_safe --user=mysql &
這是所有的步驟...

cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf

cd support-files/
./mysql.server start

測試
/usr/local/mysql/bin/mysqladmin version


OpenSSL 安裝:
下載:http://www.openssl.org/
先使用 rpm -qa | grep openssl 檢查一下有無安裝,
我裝的時候已經有裝了所以在 configure 時就只 --enable-ssl=static 若是自行安裝的請用
--with-ssl=/usr/local/ssl

代碼:
tar zxvf openssl-0.9.8e.tar.gz.tar
cd openssl-0.9.8e
./config

make
make test
sudo make install

以下裝GD,同前奏是裝zlib,libpng,jpeg,freetype。
32位元 ln -s /usr/lib/libjpeg.so.62 /usr/local/modules/jpeg/lib/libjpeg.so

tar zvxf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure

make && make install


tar zvxf libpng-1.2.14.tar.gz
cd libpng-1.2.14
./configure --prefix=/usr/local/modules/libpng

make && make install

jpeg目錄沒有的目錄只要新建就可以了.

32位元安裝: 增加
mkdir /usr/local/modules/jpeg

mkdir /usr/local/modules/jpeg/bin

mkdir /usr/local/modules/jpeg/lib

mkdir /usr/local/modules/jpeg/bin/cjpeg

mkdir /usr/local/modules/jpeg/man

mkdir /usr/local/modules/jpeg/man/man1

mkdir /usr/local/modules/jpeg/include

七個目錄

先列出配置gd2需要的網址

gd-2.0.33.tar.gz
www.boutell.com/gd

jpegsrc.v6b.tar.gz
ftp.uu.net/graphics/jpeg
www.ijg.org

libpng-1.2.14.tar.tar
www.libpng.org/pub/png/libpng.html
libpng.sourceforge.net
sourceforge.net/projects/libpng

zlib-1.2.3.tar.gz
www.zlib.net
sourceforge.net/projects/zlib

freetype-2.2.1.tar.gz
www.freetype.org
freetype.sourceforge.net/index2.html
sourceforge.net/projects/freetype

##
安裝jpegsrc
tar zvxf jpegsrc.v6b.tar.gz
cd jpeg-6b
./configure --prefix=/usr/local/modules/jpeg --enable-shared

make && make install

安裝freetype
tar zvxf freetype-2.3.1.tar.gz
cd freetype-2.3.1
./configure --prefix=/usr/local/modules/freetype

make && make install
ln -s /usr/local/modules/freetype/bin/freetype-config /usr/bin/freetype-config

安裝libxml2-2.6.27
tar zvxf libxml2-2.6.27.tar.gz
cd libxml2-2.6.27
mkdir -p /usr/local/libxml2
./configure --prefix=/usr/local/libxml2

make && make install
cp xml2-config /usr/bin

安裝gd-2
tar zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --prefix=/usr/local/modules/gd

make && make install

安裝PHP
tar zxvf php-5.1.6.tar.tar
cd php-5.1.6

./configure --prefix=/usr/local/php-fcgi --enable-fastcgi --enable-force-cgi-redirect --with-mysql=/usr/local/mysql --with-iconv --with-gd=/usr/local/modules/gd --with-zlib --with-xml=/usr/local/libxml2 --with-jpeg-dir=/usr/local/modules/jpeg -with-freetype-dir=/usr/local/modules/freetype --enable-exif --enable-bcmath --enable-wddx --with-dom --with-iconv --enable-mbstring=all --with-curl --with-openssl

make && make install

cp php.ini-recommended /usr/local/php-fcgi/lib/php.ini
echo "cgi.fix_pathinfo=1" >> /usr/local/php-fcgi/lib/php.ini

安裝 lighttpd

需求套件: gcc, pcre-devel

yum -y install pcre-devel

wget http://www.lighttpd.net/download/lighttpd-1.4.20.tar.bz2
wget http://www.lighttpd.net/download/lighttpd-1.4.20.tar.gz

tar zxvf lighttpd-1.4.20.tar.gz

cd lighttpd-1.4.20

./configure --prefix=/usr/local/lighttpd --with-openssl --with-pcre --with-bzip2 --enable-lfs --with-linux-aio

make && make install

cd doc --------文件

mkdir /etc/lighttpd

cp lighttpd.conf /etc/lighttpd

cp sysconfig.lighttpd /etc/sysconfig/lighttpd

cp rc.lighttpd.redhat /etc/init.d/lighttpd

vi /etc/rc.d/init.d/lighttpd

lighttpd="/usr/local/lighttpd/sbin/lighttpd"

vi /etc/lighttpd/lighttpd.conf

#取消註解需要的模組
server.modules = (
"mod_alias",
"mod_access",
"mod_fastcgi",
"mod_cgi",
"mod_accesslog" )

server.document-root = "/home/htdocs/"
server.errorlog = "/usr/local/lighttpd/logs/lighttpd.error.log"
accesslog.filename = "/usr/local/lighttpd/logs/access.log"
url.access-deny = ( "~", ".inc", ".htaccess" )
server.pid-file = "/var/run/lighttpd/lighttpd.pid"

#取消註解
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/local/php-fcgi/bin/php"
)
)
)

#取消註解
cgi.assign = ( ".pl" => "/usr/bin/perl",
".cgi" => "/usr/bin/perl" )

#加入底下這行:
alias.url = ( "/cgi-bin" => "/var/www/cgi-bin" )

#若有多個 alias, 全寫進小括弧內, 並以逗號區隔

更多的 lighttpd.conf 設定參考:
Configuration File Syntax
LIGHTTPD Wiki

mkdir /var/run/lighttpd

cd /etc/logrotate.d (若預設沒有安裝 httpd 是沒有這檔案)

vi httpd

複製 '/bin/kill ...' 這行, 並將原本的設置打上註解符號, 另一行改成 lighttpd.pid

#/bin/kill -HUP `cat /var/run/httpd/httpd.pid 2>/dev/null` ...

/bin/kill -HUP `cat /var/run/lighttpd/lighttpd.pid 2>/dev/null` ...

這時候輸入 /etc/rc.d/init.d/lighttpd start
如果沒有錯誤的話,哪麼我們基本配置已做好,下面我們做加速入安全設置.

eAccelerator: PHP 加速器
安裝eaccelerator-0.9.5
下載:http://nchc.dl.sourceforge.net/sourceforge/eaccelerator/eaccelerator-0.9.5.tar.tar
代碼:

tar jxf eaccelerator-0.9.5.tar.tar

cd eaccelerator-0.9.5

/usr/local/php-fcgi/bin/phpize

./configure --enable-eacclerator --with-php-config=/usr/local/php-fcgi/bin/php-config

make && make install

cat eaccelerator.ini >> /usr/local/php-fcgi/lib/php.ini

vi /usr/local/php-fcgi/lib/php.ini

zend_extension="/usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-

20060613/eaccelerator.so"
eaccelerator.log_file = "/var/log/httpd/eaccelerator_log"

mkdir /tmp/eaccelerator
chmod 777 /tmp/eaccelerator

以下是完整代碼.
///用這個替代,注意路徑,根據實際來定路徑(可以用find命令搜索eaccelerator.so所在路徑)

eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
[Zend]
zend_extension="/usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-

20050922/eaccelerator.so"
建立相對目錄:
代碼:
mkdir /tmp/eaccelerator
chmod 777 /tmp/eaccelerator

/usr/local/php-fcgi/bin/php -m 檢查有無報錯

若是裝PHP5 需要打開 short_open_tag = on 才能使用短標語

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

htscanner

作用: 利用 .htaccess 設置 php_flag、php_value 變更 php 參數 (Ref: Tsung's Blog & PHP 手冊)

wget http://pecl.php.net/get/htscanner-0.8.0.tgz

tar zxf htscanner-0.8.0.tgz

cd htscanner-0.8.0

/usr/local/php-fcgi/bin/phpize

./configure \
--enable-htscanner \
--with-php-config=/usr/local/php-fcgi/bin/php-config

make && make install

cat ./docs/htscanner.ini >> /usr/local/php-fcgi/lib/php.ini

vi /usr/local/php-fcgi/lib/php.ini

extension_dir="/usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-20020429/"
extension="htscanner.so"
htscanner.config_file=".htaccess"
htscanner.default_docroot="/var/www/html"
htscanner.default_ttl=300
htscanner.stop_on_error=0

ps.原本無 "htscanner." 要加上去才有效果

==========================================================
# server.use-ipv6 = "disable" # 缺省為禁用
# server.event-handler = "linux-sysepoll" # Linux環境下epoll系統調用可提高吞吐量
# #server.max-worker = 10 # 如果你的系統資源沒跑滿,可考慮調高 lighttpd進程數
# server.max-fds = 4096 # 默認的,應該夠用了,可根據實際情況調整
# server.max-connections = 4096 # 默認等於 server.max-fds
# server.network-backend = "linux-sendfile"
# server.max-keep-alive-requests = 0 # 在一個keep-alive會話終止連接前能接受處理的最大請求數

。0為禁止

限制IP數量
server.modules = (
..........
"mod_evasive"
.......... )


server.use-ipv6 = "disable"
server.event-handler = "linux-sysepoll"
#server.max-worker = 10
server.max-fds = 4096
server.max-connections = 4096
server.network-backend = "linux-sendfile"
server.max-keep-alive-requests = 4096
server.max-keep-alive-idle = 30
connection.kbytes-per-second = 256
evasive.max-conns-per-ip = 1 -- 限制一個IP可以讀取

限制流量
$HTTP["host"] == "192.168.1.222" {
server.document-root = "/home/htdocs/download/" -- 針對單一目錄限制流量
server.kbytes-per-second = 256
}

沒有留言: