ubuntulighttpd:Ubuntu Lighttpd轻量级web服务器来源: 发布时间:星期四, 2009年2月12日 浏览:48次 评论:0
Lighttpd和PHP搭配现在越来越常见了但是老实说如非必要我还是推荐你使用Apache和PHP搭配方式毕竟LAMP构架成熟度和稳定度都是经过时间考验 那么什么时候Lighttpd和PHP搭配更值得选择呢?可以从以下几点考虑:如果访问量比较大硬件资源吃紧那么Lighttpd适合你;如果和稳定相比你倾向速度多些那么Lighttpd适合你 OS:ubuntu server 8.04.1 software:lighttpd-1.4.20 software:PHP 5.2.6.tar.gz apt-get libmysqlclient15-dev libpng12-dev 1. 安装 php.5.2.6 tar zxvf php.5.2.6.tar.gz cd php.5.2.6 ./configure --prefix=/usr/local/php --enable-fastcgi --enable-force-cgi-redirect --with-config-file-path=/usr/local/php/etc --disable-ipv6 --enable-libxml --with-gd --enable-gd-native-ttf --with-mysql=/usr/lib/mysql/lib --with-mysqli=/usr/bin/mysql_config --enable-xml --with-freetype-dir '--with-jpeg-dir --with-png-dir --with-ttf=shared --enable- --with-zlib-dir --with-ttf make make 2.安装lighttpd tar zxvf lighttpd-1.4.20.tar.gz cd lighttpd-1.2.40 ./configure --prefix=/usr/local/lighttpd --disable-ipv6 --with-mysql=/usr/bin/mysql_config --with-zlib --with-bzip2 --with-fam --with-memcache make make mkdir -p /usr/local/lighttpd/etc mkdir -p /usr/local/lighttpd/log mkdir -p /usr/local/lighttpd/run cp ./doc/lighttpd.conf /usr/local/lighttpd/etc/ 3.配置lighttpd.conf server.modules = ( "mod_rewrite", "mod_redirect", "mod_alias", "mod_fastcgi", "mod_simple_vhost", "mod_evhost", "mod_cgi", "mod_accesslog" ) server.document-root = "/var/www/" #web访问根目录 server.errorlog = "/usr/local/lighttpd/log/error.log" #日志 index-file.names = ( "index.php", "index.html", "index.htm", "default.htm" ) #支持格式 mimetype.assign = ( ".pdf" => "application/pdf", ".sig" => "application/pgp-signature", ".spl" => "application/futuresplash", "." => "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", ".g" => "image/g", ".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", "" => "application/octet-stream", ) url.access-deny = ( "~", ".inc" ) $HTTP["url"] =~ "\.pdf$" { server.range-requests = "disable" } -file.exclude-extensions = ( ".php", ".pl", ".fcgi" ) server.port = 80 #监听端口 server.bind = "192.168.6.106" #绑定IP server.pid-file = "/var/run/lighttpd.pid" server.username = "www-data" #运行服务用户 server.groupname = "www-data" #运行服务用户组 fastcgi.server = ( ".php" => ( "localhost" => ( "" => "/usr/local/lighttpd/run/php-fastcgi.", "bin-path" => "/usr/local/php/bin/php-cgi" #php-cgi ) ) ) server.max-fds = 20480 # 文件描述符数目 server.max-keep-alive-requests = 0 #保持会话连接 server.network-backend = "linux-sendfile" server.event-handler = "linux-sysepoll" # Linux环境下epoll系统可提高吞吐量 保存退出` 然后写个启动脚本` #!/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/loca/lighttpd/sbin:/usr/loca/lighttpd/bin DAEMON=/usr/local/lighttpd/sbin/lighttpd NAME=lighttpd DESC="web server" PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME ENV="env -i LANG=C PATH=/usr/local/lighttpd/bin:/usr/local/lighttpd/bin:/bin" SSD="/sbin/start-stop-daemon" DAEMON_OPTS="-f /usr/local/lighttpd/conf/lighttpd.conf" test -x $DAEMON || exit 0 -e mkdir -p /var/run/lighttpd > /dev/null 2> /dev/null chown www-data:www-data /var/run/lighttpd chmod 0750 /var/run/lighttpd . /lib/lsb/init-functions "$1" in start) log_daemon_msg "Starting $DESC" $NAME ! $ENV $SSD --start --quiet\ --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS ; then log_end_msg 1 log_end_msg 0 fi ;; stop) log_daemon_msg "Stopping $DESC" $NAME $SSD --quiet --stop --oknodo --retry 30\ --pidfile $PIDFILE --exec $DAEMON; then rm -f $PIDFILE log_end_msg 0 log_end_msg 1 fi ;; reload) log_daemon_msg "Reloading $DESC configuration" $NAME $SSD --stop --signal 2 --oknodo --retry 30\ --quiet --pidfile $PIDFILE --exec $DAEMON; then $ENV $SSD --start --quiet \ --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS ; then log_end_msg 0 log_end_msg 1 fi log_end_msg 1 fi ;; restart|force-reload) $0 stop [ -r $PIDFILE ] && while pidof lighttpd |\ grep -q `cat $PIDFILE 2>/dev/null` 2>/dev/null ; do sleep 1; done $0 start ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 exit 1 ;; esac exit 0 放在/etc/init.d/lighttpd 然后在 /var/www 里写个php 脚本 <php? phpinfo; ?> 好了启动 lighttpd /etc/init.d/lighttpd start * Starting web server lighttpd [ OK ] 现在就可以打开IE http://192.168.6.106 看到 php调试页面就可以了 PS :安装时候要注意建立 lithttpd 配置文件夹 php-fastcgi. 目录 log目录是运行lighttpd用户权限不然会报错~ 好了现在我在讲下lighttpd有个负载功能相信大家都看到了 配置文件里: fastcgi.server = ( ".php" => ( "localhost" => ( "" => "/usr/local/lighttpd/run/php-fastcgi.", "bin-path" => "/usr/local/php/bin/php-cgi" #php-cgi ) ) ) 我们在 lighttpd 源码包里面把spawn-php.sh 拷贝到 /usr/local/sbin/ 下 复制成 3份 cp spawn-php.sh spawn-php-2.sh cp spawn-php.sh spawn-php-3.sh 然后分别配置 3个文件 SPAWNFCGI="/usr/local/lighttpd/bin/spawn-fcgi" #spawn-fcgi 路径 FCGIPROGRAM="/usr/local/php/bin/php-cgi" #php-cgi路径 FCGIPORT="1026" #运行端口 spawn-php-2.sh 改为 1027 spawn-php-3sh 改为 1028 FCGI_WEB_SERVER_ADDRS="127.0.0.1,192.168.6.106" #绑定服务器IP 好了然后把每个都运行起来~~ ./spawn-php.sh spawn-fcgi.c.206: child spawned successfully: PID: 5233 ./spawn-php-2.sh ................. 然后修改 /usr/local/lighttpd/etc/lighttpd.conf 把 fastcgi.server = ( ".php" => ( "localhost" => ( "" => "/usr/local/lighttpd/run/php-fastcgi.", "bin-path" => "/usr/local/php/bin/php-cgi" #php-cgi ) ) ) 替换成 #fastcgi.server = ( ".php" => (( "host" => "127.0.0.1", "port" => 1026 ), ( "host" => "127.0.0.1", "port" => 1027 ), ( "host" => "127.0.0.1", "port" => 1028 ) ) 保存退出从启服务~~ /etc/init.d/lighttpd restart 从新访问 http://192.168.6.106~ 可以在 服务器上 top看到明显多了 很多运行进程~ 当然我这么起不到什么作用把 spawn-php.sh 可以拷贝到别linux服务器上运行 才也可以``但是要记得把 spawn-fcgi 也要拷贝过去哦~~大家可以试试看~ 0
相关文章读者评论发表评论 |