Cygwin运行Lighttpd + FCGI + PHP

  • 本文欢迎各种形式的转载,但请18岁以上的转载者注明文章出处,尊重我的劳动,也尊重你的智商;

  因为苦逼的云服务器,只有可怜的内存,同时还要和我的Windows代理程序一起运行,所以只能用lighttpd,占有内存最小,所以只能用cygwin了。在网上搜索了很久,主要参考了最后那两篇文章,害怕自己最后忘了,干脆就把整个配置过程记录下来。

Cygwin和相关组件安装​

安装cygwin 

     cygwin很好装,从 www.cygwin.com上下载setup.exe,一路点击就可以了,选择镜像代理时,选择一个国内的镜像就好了,我在安装时简单比较了下,感觉还是选择东软的镜像(http://mirrors.neusoft.edu.cn/cygwin/)比较快,毕竟是专注开源代理二十年啊!

安装apt-cyg

    cygwin的安装包管理器就是​setup.exe,每次需要增加或删除都需要用这个执行程序,用起来很不方便。这样,apt-cyg就是一个很好的解决方案,用起来和apt-get差不多,非常好用,基于bash脚本的,安装流程如下:

wget  https://rawgit.com/transcode-open/apt-cyg/master/apt-cyg

chmod +x apt-cyg

mv apt-cyg /usr/local/bin/

​安装lighttpd和PHP

​      这两个都可以用setup.exe或apt-cyg来安装,setup.exe是GUI界面,点开以后直接选择就可以了,用 apt-cyg安装则执行如下命令即可:

​   apt-cyg install lighttpd

   apt-cyg install php

配置lighttpd以服务方式运行

安装cygserver

cygserver

 是为Cygwin作为后台服务运行而设计的,默认安装Cygwin的时候并没有启动它。我们需要打开它,并将它作为Windows的标准服务来安装。

在Cygwin中输入命令:

cygserver-config

按照界面提示进行cygserver的安装,并同意将其安装为服务。

运行该服务:

cygrunsrv --start cygserver

cygrunsrv其实是启动的Windows标准服务cygserver,这个命令也可以在Cmd下这样做:

net start cygserver

或者也可以按下按键 Windows+R ,键入 services.msc 回车,找到 CYGWI cygwerver服务,并启动之。

这三种启动服务的方法的作用都一样,下面统一使用 cygrunsrv 的方法。

查看cygserver服务的状态:

cygrunsrv --query cygserver# 显示Service             : cygserver
Display name        : CYGWIN cygserver
Current State       : Running
Controls Accepted   : Stop
Command             : /usr/sbin/cygserver

测试Lighttpd

安装Lighttpd包,由于 系统需求 中提到的假设,安装过程略。

测试Lighttpd的运行:

/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf

如果出现下面这样的报错,需要调整lighttpd.conf中的某些和网络相关的配置。因为Lighttpd是运行在Linux下的,默认的配置在Windows下面是不受支持的。

2013-01-11 11:01:59: (/usr/src/ports/lighttpd/lighttpd-1.4.32-2/src/lighttpd-1.4.32/src/configfile.c.1339) the selected event-handler in unknown or not supported: linux-sysepoll 
2013-01-11 11:01:59: (/usr/src/ports/lighttpd/lighttpd-1.4.32-2/src/lighttpd-1.4.32/src/server.c.646) setting default values failed 
2013-01-11 11:07:36: (/usr/src/ports/lighttpd/lighttpd-1.4.32-2/src/lighttpd-1.4.32/src/network.c.260) warning: please use server.use-ipv6 only for hostnames, not without server.bind / empty address; your config will break if the kernel default for IPV6_V6ONLY changes 
2013-01-11 11:07:36: (/usr/src/ports/lighttpd/lighttpd-1.4.32-2/src/lighttpd-1.4.32/src/network.c.802) server.network-backend has a unknown value: linux-sendfile 
2013-01-11 11:11:34: (/usr/src/ports/lighttpd/lighttpd-1.4.32-2/src/lighttpd-1.4.32/src/server.c.915) can't have more connections than fds/2:  1024 256 

涉及的配置项如下,将他们全部注释:

  • server.event-handler 约在181行
  • server.use-ipv6 约在93行
  • server.network-backend 约在191行
  • server.max-fds 约在207行
  • server.max-connections 约在245行

如果在运行的时候提示目录权限之类问题,则可以修改 Lighttpd.conf 中的 16~20 行配置,设置正确的目录和权限。

如果执行正常,那么不会输出任何信息,Lighttpd会一直在前台运行。

此时可以去浏览器中输入 http://localhost

 测试一下,当然,要看到内容,需要确保你的Lighttpd.conf中的主页地址配置正确,即使你看到的是404错误,其实也说明你的服务器配置成功了,只是没有默认的页面而已。

将Lighttpd安装成服务

使用cygrunsrv可以将Lighttpd安装成Windows系统服务

cygrunsrv -I lighttpd -d 'CYGWIN lighttpd'

-p '/usr/sbin/lighttpd' -a '-D -f /etc/lighttpd/lighttpd.conf'

然后运行它

cygrunsrv --start lighttpd

查询运行状态

cygrunsrv --query lighttpd

Service             : lighttpd
Display name        : CYGWIN lighttpd
Current State       : Running
Controls Accepted   : Stop
Command             : /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf


配置Lighttpd以FCGI的方式支持PHP


打开lighttpd模块支持

修改/etc/lighttpd/modules.conf 开启相关模块:

server.modules = (

  "mod_access", 

  "mod_rewrite",

 }

....​

include "conf.d/compress.conf"​

....​

include "conf.d/fastcgi.conf"

....​

​include "conf.d/cgi.conf"

....​

include "conf.d/simple_vhost.conf"


修改fastcgi.conf配置文件,支持PHP

修改 /etc/lighttpd/conf.d/fastcgi.conf 如下:

fastcgi.server = ( ".php" =>

                   ( "php-local" =>

                     (

                       "socket" => socket_dir + "/php-fastcgi-1.socket",

                       "bin-path" => "/usr/bin/php-cgi", 

                       "max-procs" => 1,

                       "broken-scriptfilename" => "enable",

                     )

                   ),

                )

​其中 "bin-path"  指向PHP-CGI程序的位置。

测试PHP效果

在lighttp的缺省HTML文件目录下添加一个文件info.php

​ /srv/www/htdocs/info.php

该文件内容如下:

<?php

phpinfo();

?>

然后在浏览器输入 http://127.0.0.1/info.php访问,得到如下响应界面,即为配置成功:

phpinfo
参考链接: 1. 使用Cygwin在Windows中以服务方式安装Lighttpd   2.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值