CentOS下编译安装lighttpd和PHP(vps)

1、下载php

wget http://cn2.php.net/get/php-5.2.14.tar.gz/from/am.php.net/mirror
tar -xzvf php-5.2.14.tar.gz

2、安装PHP

#先安装依赖的库文件
yum install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel pcre pcre-devel zlib-devel bzip2-devel glibc glibc-devel glib2 glib2-devel

安装无法通过yum安装的...

#安装libiconv
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
tar -xzvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure --prefix=/usr
make -j
make install
#安装libmcrypt
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
tar -xzvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --prefix=/usr
make -j
make install
#安装libmhash
wget http://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
tar -xzvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure --prefix=/usr
make -j
make install
#安装mcrypt
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
tar -xzvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure --prefix=/usr
make -j
make install

安装php

cd php-5.2.14
#重点是--enable-fastcgi --enable-force-cgi-redirect
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/lib --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-dist /usr/local/php/etc/php.ini

安全配置更改

vim /usr/local/php/etc/php.ini
disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source
cgi.fix_pathinfo=1

安装xCache

#安装xCache
wget http://xcache.lighttpd.net/pub/Releases/1.3.0/xcache-1.3.0.tar.gz
tar -xzvf xcache-1.3.0.tar.gz
cd xcache-1.3.0
/usr/local/php/bin/phpize
./configure --enable-xcache --enable-xcache-coverager --enable-xcache-disassembler --with-php-config=/usr/local/php/bin/php-config
make
make install
#修改xcache.ini,并加入php.ini
[xcache-common]
;; install as zend extension (recommended), normally "$extension_dir/xcache.so"
zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so
; zend_extension_ts = /usr/local/lib/php/extensions/non-debug-zts-xxx/xcache.so
;; For windows users, replace xcache.so with php_xcache.dll
##zend_extension_ts = c:/php/extensions/php_xcache.dll
;; or install as extension, make sure your extension_dir setting is correct
; extension = xcache.so
;; or win32:
; extension = php_xcache.dll

[xcache.admin]
xcache.admin.enable_auth = On
xcache.admin.user = "liheyuan"
; xcache.admin.pass = md5($your_password)
xcache.admin.pass = "80efac8bfe48663ccddaa7162bc3e6f4"

[xcache]
; ini only settings, all the values here is default unless explained

; select low level shm/allocator scheme implemenation
xcache.shm_scheme = "mmap"
; to disable: xcache.size=0
; to enable : xcache.size=64M etc (any size > 0) and your system mmap allows
xcache.size = 4M
; set to cpu count (cat /proc/cpuinfo |grep -c processor)
xcache.count = 2
; just a hash hints, you can always store count(items) > slots
xcache.slots = 8K
; ttl of the cache item, 0=forever
xcache.ttl = 360
; interval of gc scanning expired items, 0=no scan, other values is in seconds
xcache.gc_interval = 1800

; same as aboves but for variable cache
xcache.var_size = 4M
xcache.var_count = 1
xcache.var_slots = 8K
; default ttl
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300

xcache.test = Off
; N/A for /dev/zero
xcache.readonly_protection = Off
; for *nix, xcache.mmap_path is a file path, not directory.
; Use something like "/tmp/xcache" if you want to turn on ReadonlyProtection
; 2 group of php won't share the same /tmp/xcache
; for win32, xcache.mmap_path=anonymous map name, not file path
xcache.mmap_path = "/tmp/path"

; leave it blank(disabled) or "/tmp/phpcore/"
; make sure it's writable by php (without checking open_basedir)
xcache.coredump_directory = ""

; per request settings
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off

[xcache.coverager]
; per request settings
; enable coverage data collecting for xcache.coveragedump_directory and xcache_c

overager_start/stop/get/clean() functions (will hurt executing performance)
xcache.coverager = Off

; ini only settings
; make sure it's readable (care open_basedir) by coverage viewer script
; requires xcache.coverager=On
xcache.coveragedump_directory = ""
#添加到php.ini
cat ./xcache.ini >> /usr/local/php/etc/php.ini

3、下载lighttpd

wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.28.tar.gz
tar -xzvf lighttpd-1.4.28.tar.gz

4、编译、安装lighttpd

cd lighttpd-1.4.28
./configure --prefix=/usr/local/lighttpd
#编译安装
./configure --prefix=/usr/local/lighttpd --with-bzip2 --with-zlib
make
make install
#开机启动
sed -e 's/FOO/lighttpd/g' doc/initscripts/rc.lighttpd.redhat > /etc/init.d/lighttpd
chmod ug+rx /etc/init.d/lighttpd
#创建默认配置文件
cp -p doc/initscripts/sysconfig.lighttpd /etc/sysconfig/lighttpd
mkdir -p /etc/lighttpd
mkdir -p /var/log/lighttpd
chown -R www:www /var/log/lighttpd
cp -R doc/config/conf.d/ doc/config/*.conf doc/config/vhosts.d/ /etc/lighttpd/

配置

#配置
/usr/sbin/useradd www
cd /home/liheyuan
mkdir wwwwwwwwww
chown www:www: wwwwwwwwww
#基本lighttpd配置
vim /etc/lighttpd/lighttpd.conf
server.username = "www"
server.groupname = "www"
static-file.exclude-extensions = ( ".php",".php3",".php4",".php5",".inc",".~", ".pl", ".fcgi", ".scgi" ) #不应该被

当做静态文件解析的拓展名
index-file.names += (
"index.xhtml", "index.html", "index.htm", "default.htm", "index.php"
)
#配置php-fastcgi
vim modules
#找到下面一行,去掉前面的#
include "conf.d/fastcgi.conf"
#如下配置,基本的本地fastcgi
vim conf.d/fastcgi.conf
fastcgi.server = ( ".php" =>
(( "socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/local/php/bin/php-cgi",
"broken-scriptfilename" => "enable",
"max-procs" => 3,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "3",
"PHP_FCGI_MAX_REQUESTS" => "500"
)
))
)
#说明:PHP_FCGI_MAX_REQUESTS的作用是在一个子进程工作一定次数后就干掉它,以免可能出现的问题连累系统,主进程会再创建一个相应的子进程来替补,保证子进程数一直是PHP_FCGI_CHILDREN个。
#配置php
cgi.fix_pathinfo = 1

5、用spwan-fcgi脱离lighttpd启动php-cgi进程。
尽管lighttpd可以自行启动fcgi进程,但最大的问题就是:如果多用户共享服务器,将共享用户权限!这是致命的安全隐患。

wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
tar -xzvf spawn-fcgi-1.6.3.tar.gz
cd spawn-fcgi-1.6.3
./configure --prefix=/usr/local/spawn-fcgi
make
make install

然后构建spwan-cgi启动脚本,类似下面的:
注意这个只能生成字符串,要把字符串拷贝到其他.sh中再运行……我搞不明白为什么……实验好多次参数失败。。。。

#!/bin/bash

## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/usr/local/spawn-fcgi/bin/spawn-fcgi"

#Path for open_basedir
PHP_OPENBASE_DIR="/home/www/xxxxxx/:/tmp/"
#PHP_OPENBASE_DIR="/home/www/xxxxxx/ "

## ABSOLUTE path to the PHP binary
FCGIPROGRAM="/usr/local/php/bin/php-cgi -d open_basedir=$PHP_OPENBASE_DIR"

## TCP port to which to bind on localhost
FCGIPORT="18000"

## number of PHP children to spawn
PHP_FCGI_CHILDREN=3

## maximum number of requests a single PHP process can serve before it is restarted
PHP_FCGI_MAX_REQUESTS=250

## IP addresses from which PHP should access server connections
FCGI_WEB_SERVER_ADDRS="127.0.0.1"

# allowed environment variables, separated by spaces
ALLOWED_ENV="PATH"

## if this script is run as root, switch to the following user
USERID=www
GROUPID=www

################## no config below this line

if test x$PHP_FCGI_CHILDREN = x; then
PHP_FCGI_CHILDREN=5
fi

export PHP_FCGI_MAX_REQUESTS
export FCGI_WEB_SERVER_ADDRS

ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"

if test x$UID = x0; then
EX="$SPAWNFCGI -p $FCGIPORT -f \"$FCGIPROGRAM\" -u $USERID -g $GROUPID -C $PHP_FCGI_CHILDREN"
else
EX="$SPAWNFCGI -p $FCGIPORT -f \"$FCGIPROGRAM\" -C $PHP_FCGI_CHILDREN"
fi

# copy the allowed environment variables
#E=

for i in $ALLOWED_ENV; do
E="$E $i=${!i}"
done

# clean the environment and set up a new one
#echo $EX
#echo "env -i $E $EX"
CMD="env -i $E $EX"
echo $CMD
[/shell]
修改lighttpd
[shell]
vim conf.d/fastcgi.conf
fastcgi.server = ( ".php" =>
(( "host" => "10.0.0.2", "port" => 1030 ),
( "host" => "10.0.0.3", "port" => 1030 ))
)

2 thoughts on “CentOS下编译安装lighttpd和PHP(vps)

  1. 好铺吧

    你好,我也是用的diahosting。用的也是lighttpd,在写伪静态的时候,直接影响到其他的文件报404. 比如 有数字的100.php就会报错,报404.还有这个http://www.haopu8.com/images/level_10.gif 图片是存在的,但加上伪静态后就是报了404,不知道为什么。

    url.rewrite = (
    "^/view-(.*)\.htm$" => "$1/view.php?&num_iid=$2",
    "^/remai-([0-9]+)-([0-9]+)\.htm$" => "$1/remai.php?catid=$2&page=$3",
    "^/huangguandianpu-([0-9]+)-([0-9]+)\.htm$" => "$1/huangguandianpu.php?cid=$2&page=$3",
    "^(.*)baifenbaihaoping-([0-9]+)-([0-9]+)\.htm$" =>"$1/baifenbaihaoping.php?cid=$2&page=$3",
    "^/shop-(.+)-([0-9]+)\.htm$" => "$1/shop.php?nick=$2&page=$3",
    "^/shopmall-([0-9]+)-([0-9]+)\.htm$" => "$1/shopmall.php?cid=$2&page=$3",
    "^/shoucangbang-([0-9]+)-([0-9]+)\.htm$" => "$1/shoucangbang.php?cid=$2&page=$3",
    "^/jianfeishoushen-([0-9]+)\.htm$" => "$1/jianfeishoushen.php?page=$2",
    "^/fengxiong-([0-9]+)\.htm$" => "$1/fengxiong.php?page=$2",
    "^/search-(.*)-([0-9]+)-([0-9]+)\.htm$" => "$1/search.php?q=$2&cid=$3&page=$4",
    "^ErrorDocument 404 /notfound.php",
    )

    这是我的伪静态规则,都找不到为什么》?

    大哥能帮下我不?
    我的QQ:2980053 E-mail:bailywen#gmail.com 能帮下我吗?

    Reply

Leave a Reply to 好铺吧 Cancel reply

Your email address will not be published. Required fields are marked *