一。安装php5.2.9
./configure --prefix=/opt/app/php-cgi --enable-fastcgi --enable-discard-path --enable-force-cgi-redirect --enable-sockets --disable-debug --with-gd --enable-gd-native-ttf --with-mysql --with-config-file-path=/etc/php-cgi
注意修改/etc/php-cgi/php.ini
cgi.fix_pathinfo = 1
make sudo make install
二。安装ZendOptimizer-3.3.3和eaccelerator
1.PHP缓冲(加速)首选xcache,兼容性和性能表现都非常优秀。
2.如果你的PHP环境需要Zend Optimizer,就安装eAccelerator,并把Zend Optimizer的压缩级别调到0。
zend_optimizer.optimization_level=0
ZendOptimizer安装很容易,不表
eaccelerator安装:
export PHP_PREFIX="/opt/app/php-cgi" $PHP_PREFIX/bin/phpize ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config make sudo make install
在/etc/php-cgi/php.ini中添加如下
zend_extension="/opt/app/php-cgi/lib/php/extensions/no-debug-non-zts-20060613/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" eaccelerator.log_file = "/var/log/eaccelerator_log" [Zend] zend_extension_manager.optimizer=/opt/app/Zend-3.3/lib/Optimizer-3.3.3 zend_extension_manager.optimizer_ts=/opt/app/Zend-3.3/lib/Optimizer_TS-3.3.3 zend_optimizer.version=3.3.3 zend_extension=/opt/app/Zend-3.3/lib/ZendExtensionManager.so zend_extension_ts=/opt/app/Zend-3.3/lib/ZendExtensionManager_TS.so zend_optimizer.optimization_level=0
三。安装lighttpd1.4.22
./configure --with-fam --prefix=/opt/app/lighttpd-bbs --sysconfdir=/etc/lighttpd-bbs
groupadd www
useradd -g www -s /sbin/nologin -d /dev/null www
配置:
/etc/lighttpd-bbs/lighttpd.conf
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.document-root = "/opt/webapps/bbs" server.errorlog = "/var/log/lighttpd/bbs-error.log" # files to check for if .../ is requested index-file.names = ("index.php", "index.html", "index.htm", "default.htm" ) ## set the event-handler (read the performance section in the manual) server.event-handler = "linux-sysepoll" # needed on OS X # mimetype mapping mimetype.assign = ( ".pdf" => "application/pdf", ".sig" => "application/pgp-signature", ".spl" => "application/futuresplash", ".class" => "application/octet-stream", ".ps" => "application/postscript", ".torrent" => "application/x-bittorrent", ".dvi" => "application/x-dvi", ".gz" => "application/x-gzip", ".pac" => "application/x-ns-proxy-autoconfig", ".swf" => "application/x-shockwave-flash", ".tar.gz" => "application/x-tgz", ".tgz" => "application/x-tgz", ".tar" => "application/x-tar", ".zip" => "application/zip", ".mp3" => "audio/mpeg", ".m3u" => "audio/x-mpegurl", ".wma" => "audio/x-ms-wma", ".wax" => "audio/x-ms-wax", ".ogg" => "application/ogg", ".wav" => "audio/x-wav", ".gif" => "image/gif", ".jar" => "application/x-java-archive", ".jpg" => "image/jpeg", ".jpeg" => "image/jpeg", ".png" => "image/png", ".xbm" => "image/x-xbitmap", ".xpm" => "image/x-xpixmap", ".xwd" => "image/x-xwindowdump", ".css" => "text/css", ".html" => "text/html", ".htm" => "text/html", ".js" => "text/javascript", ".asc" => "text/plain", ".c" => "text/plain", ".cpp" => "text/plain", ".log" => "text/plain", ".conf" => "text/plain", ".text" => "text/plain", ".txt" => "text/plain", ".dtd" => "text/xml", ".xml" => "text/xml", ".mpeg" => "video/mpeg", ".mpg" => "video/mpeg", ".mov" => "video/quicktime", ".qt" => "video/quicktime", ".avi" => "video/x-msvideo", ".asf" => "video/x-ms-asf", ".asx" => "video/x-ms-asf", ".wmv" => "video/x-ms-wmv", ".bz2" => "application/x-bzip", ".tbz" => "application/x-bzip-compressed-tar", ".tar.bz2" => "application/x-bzip-compressed-tar", # default mime type "" => "application/octet-stream", ) #### accesslog module accesslog.filename = "|/usr/local/sbin/cronolog /var/log/httpd/bbs-access.%Y%m%d.log" url.access-deny = ( "~", ".inc" ) $HTTP["url"] =~ "\.pdf$" { server.range-requests = "disable" } #$HTTP["referer"] !~ "^($|http://*\.test\.com)" { #$HTTP["url"] =~ "\.(js|css|gif|jpg|jpeg)$" { # url.access-deny = ( ".js",".css",".gif",".jpg",".jpeg") #} #} static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".asp") server.port = 80 ## bind to localhost (default: all interfaces) server.bind = "1.2.3.4" server.name = "bbs.test.com" ## error-handler for status 404 #server.error-handler-404 = "/error-handler.html" #server.error-handler-404 = "/error-handler.php" ## to help the rc.scripts #server.pid-file = "/var/run/lighttpd.pid" ## change uid to <uid> (default: don't care) server.username = "xxx" ## change uid to <uid> (default: don't care) server.groupname = "daemon" #### compress module compress.cache-dir = "/tmp/lighttpd-bbs/compress/" compress.filetype = ("text/plain", "text/html","text/javascript","text/css") fastcgi.debug=0 fastcgi.server = ( ".php" => (( "socket" => "/tmp/php-bbs.socket", "broken-scriptfilename" => "enable" ))) #### SSL engine ssl.engine = "disable" #ssl.pemfile = "/etc/ssl/private/lighttpd.pem" #### status module #status.status-url = "/server-status" #status.config-url = "/server-config" status.statistics-url = "/server-statistics" #### url handling modules (rewrite, redirect, access) #url.rewrite = ( "^/$" => "/server-status" ) #url.redirect = ( "^/wishlist/(.+)" => "http://www.123.org/$1" ) #### both rewrite/redirect support back reference to regex conditional using %n #$HTTP["host"] =~ "^www\.(.*)" { # url.redirect = ( "^/(.*)" => "http://%1/$1" ) #} url.rewrite = ( "^/archiver/([a-z0-9\-]+\.html)$" => "archiver/index.php?$1", "^/forum-([0-9]+)-([0-9]+)\.html$" => "forumdisplay.php?fid=$1&page=$2", "^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$" => "viewthread.php?tid=$1&extra=page%%53D$3&page=$2", "^/space-(username|uid)-(.+)\.html$" => "space.php?$1=$2", "^/tag-(.+)\.html$" => "tag.php?name=$1", "^/profile-(username|uid)-(.+)\.html$" => "viewpro.php?$1=$2", "^/upload(.*)$" => "/blog$1" ) #### expire module #expire.url = ( "/buggy/" => "access 2 hours", "/asdhas/" => "access plus 1 seconds 2 minutes") #### ssi #ssi.extension = ( ".shtml" ) #### setenv #setenv.add-request-header = ( "TRAV_ENV" => "mysql://user@host/db" ) #setenv.add-response-header = ( "X-Secret-Message" => "42" ) server.max-keep-alive-requests = 128 server.max-keep-alive-idle = 1 server.network-backend = "linux-sendfile" server.max-fds = 8192 server.stat-cache-engine = "fam" #server.use-noatime = "enable" #server.max-stat-threads = 1 #server.max-read-threads = 2 #server.force-lowercase-filenames = "enable" server.max-request-size = 20480 server.max-read-idle = 60 server.max-write-idle = 60
四,lighttpd启动脚本:
/etc/init.d/lighttpd-bbs
#!/bin/sh # # lighttpd Startup script for the lighttpd server # # chkconfig: - 86 16 # description: Lightning fast webserver with light system requirements # # processname: lighttpd # config: /etc/lighttpd-bbs/lighttpd.conf # config: /etc/sysconfig/lighttpd # pidfile: /var/run/lighttpd-bbs.pid # # Note: pidfile is assumed to be created # by lighttpd (config: server.pid-file). # If not, uncomment 'pidof' line. # Source function library . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/lighttpd ]; then . /etc/sysconfig/lighttpd fi if [ -z "$LIGHTTPD_CONF_PATH" ]; then LIGHTTPD_CONF_PATH="/etc/lighttpd-bbs/lighttpd.conf" fi prog="lighttpd-bbs" lighttpd="/opt/app/lighttpd-bbs/sbin/lighttpd" RETVAL=0 start() { echo -n $"Starting $prog: " daemon $lighttpd -f $LIGHTTPD_CONF_PATH RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc $prog RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog return $RETVAL } reload() { echo -n $"Reloading $prog: " killproc $prog -HUP RETVAL=$? echo return $RETVAL } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; condrestart) if [ -f /var/lock/subsys/$prog ]; then stop start fi ;; reload) reload ;; status) status $lighttpd RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|reload|status}" RETVAL=1 esac exit $RETVAL
五、安装spawn-fcgi
下载spawn-fcgi-1.6.0
./configure --prefix=/opt/app/spawn-fcg make sudo make install
六、fastcgi启动脚本
/etc/init.d/spwan-php-bbs.sh
#!/bin/bash # # fcgi Startup script for fcgi # # processname: fcgi # Source function library . /etc/rc.d/init.d/functions ## ABSOLUTE path to the spawn-fcgi binary SPAWNFCGI="/opt/app/spawn-fcgi/bin/spawn-fcgi" ## ABSOLUTE path to the PHP binary FCGIPROGRAM="/opt/app/php-cgi/bin/php-cgi" ## TCP port to which to bind on localhost #FCGIPORT="1026" FCGI_SOCKET="/tmp/php-bbs.socket" FCGI_PIDFILE="/var/run/spawn-fcgi-bbs.pid" ## number of PHP children to spawn PHP_FCGI_CHILDREN=20 ## maximum number of requests a single PHP process can serve before it is restarted PHP_FCGI_MAX_REQUESTS=500 ## 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="SHELL PATH USER" ## if this script is run as root, switch to the following user USERID=rsync GROUPID=daemon ################## 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" EX="$SPAWNFCGI -s $FCGI_SOCKET -f $FCGIPROGRAM -u $USERID -g $GROUPID -C $PHP_FCGI_CHILDREN -P $FCGI_PIDFILE" else #EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -C $PHP_FCGI_CHILDREN" EX="$SPAWNFCGI -s $FCGI_SOCKET -f $FCGIPROGRAM -C $PHP_FCGI_CHILDREN -P $FCGI_PIDFILE" 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 #env - $E $EX prog="fcgi-bbs" RETVAL=0 start() { echo -n $"Starting $prog: " daemon env - $E $EX RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog return $RETVAL } stop() { echo -n $"Stopping $prog: " rm -f $FCGI_PIDFILE $FCGI_SOCKET killproc $FCGIPROGRAM RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog return $RETVAL } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; condrestart) if [ -f /var/lock/subsys/$prog ]; then stop start fi ;; status) status $FCGIPROGRAM RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|status}" RETVAL=1 esac exit $RETVAL