越狱iOS 10.3.3(32位iPhone 5)搭建Web Server启动问题求助
嘿,我来帮你搞定在越狱的iPhone 5(iOS10.3.3)上启动lighttpd和PHP的事儿!既然你已经装好了这俩工具,接下来分几步操作就行:
一、手动启动lighttpd服务
首先你得通过SSH连接到你的iPhone(比如用电脑端Terminal或手机端iTerminal),或者直接打开MobileTerminal操作:
先检查lighttpd配置文件是否正常
运行命令:lighttpd -t -f /etc/lighttpd/lighttpd.conf如果输出
OK就说明配置没问题;要是报错,就打开配置文件排查路径、模块名这类细节。手动启动lighttpd
直接运行启动命令:lighttpd -f /etc/lighttpd/lighttpd.conf想让它后台运行(不占终端窗口)就加个
&:lighttpd -f /etc/lighttpd/lighttpd.conf &停止服务用这个命令:
killall lighttpd
二、确保PHP配置生效
你已经装了PHP,得让lighttpd能解析PHP文件,所以要修改lighttpd的配置:
打开lighttpd配置文件
用nano编辑器打开:nano /etc/lighttpd/lighttpd.conf加载PHP相关模块
找到server.modules段落,确保里面包含mod_fastcgi(没有的话就新增一行):server.modules = ( ... "mod_fastcgi", ... )添加FastCGI配置支持PHP
在配置文件末尾加上这段(PHP路径不确定的话,用which php-cgi命令查询,一般是/usr/bin/php-cgi):fastcgi.server = ( ".php" => (( "socket" => "/tmp/php-fastcgi.sock", "bin-path" => "/usr/bin/php-cgi", "max-procs" => 1, "bin-environment" => ( "PHP_FCGI_CHILDREN" => "4", "PHP_FCGI_MAX_REQUESTS" => "1000" ), "broken-scriptfilename" => "enable" )) )保存退出(nano里按
Ctrl+O回车,再按Ctrl+X)。重启lighttpd让配置生效
killall lighttpd && lighttpd -f /etc/lighttpd/lighttpd.conf &
三、设置开机自启动(可选)
不想每次重启手机都手动启动服务?可以配置launchd让它开机自动运行:
创建launchd配置文件
用nano创建:nano /Library/LaunchDaemons/com.lighttpd.plist粘贴以下内容:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.lighttpd</string> <key>ProgramArguments</key> <array> <string>/usr/sbin/lighttpd</string> <string>-f</string> <string>/etc/lighttpd/lighttpd.conf</string> </array> <key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/> </dict> </plist>保存退出。
设置正确的权限
运行这两个命令:chmod 644 /Library/LaunchDaemons/com.lighttpd.plist chown root:wheel /Library/LaunchDaemons/com.lighttpd.plist加载配置并启动
launchctl load /Library/LaunchDaemons/com.lighttpd.plist以后重启手机,lighttpd就会自动启动了。
四、测试是否成功
找到lighttpd的网站根目录(配置文件里的
server.document-root,默认一般是/var/www/),创建测试文件info.php:nano /var/www/info.php粘贴内容:
<?php phpinfo(); ?>保存退出。
查看iPhone的局域网IP(设置-无线局域网-点击当前WiFi旁的i图标),用浏览器访问
http://你的iPhoneIP/info.php,如果能看到PHP信息页面,就说明一切正常啦!
内容的提问来源于stack exchange,提问作者camila314

