iStoreOS 安装web服务+php
Posted by he; tagged with none
在 iStoreOS 上安装 PHP 并配置 Web 服务,可以按照以下步骤进行:
1. 更新系统包
首先,确保系统包是最新的:
opkg update
2. 安装 PHP
iStoreOS 基于 OpenWrt,可以使用 opkg
包管理器安装 PHP。以下是安装 PHP 的命令:
opkg install php8 php8-cgi php8-mod-curl php8-mod-json php8-mod-mbstring php8-mod-opcache php8-mod-pdo php8-mod-session php8-mod-sqlite3
根据需求选择安装的 PHP 模块。
3. 安装 Web 服务器
常用的 Web 服务器有 uhttpd
和 nginx
。以下是安装 uhttpd
的步骤:
opkg install uhttpd
4. 配置 Web 服务器
编辑 /etc/config/uhttpd
配置文件,启用 PHP 支持:
config uhttpd 'main' list listen_http '0.0.0.0:80' list listen_http '[::]:80' option home '/www' option cgi_prefix '/cgi-bin' option lua_prefix '/lua' option lua_handler '/usr/lib/uhttpd_lua.so' option script_timeout '60' option network_timeout '30' option http_keepalive '20' option tcp_keepalive '1' option ubus_prefix '/ubus' option interpreter '.php=/usr/bin/php-cgi'
确保 interpreter '.php=/usr/bin/php-cgi'
这一行存在。
5. 创建 Web 根目录
默认 Web 根目录为 /www
,创建并设置权限:
mkdir -p /wwwchmod 755 /www
6. 测试 PHP
在 /www
目录下创建 index.php
文件:
echo "<?php phpinfo(); ?>" > /www/index.php
7. 启动并设置开机启动
启动 uhttpd
并设置为开机启动:
/etc/init.d/uhttpd start /etc/init.d/uhttpd enable
8. 访问测试
在浏览器中输入路由器的 IP 地址(如 http://192.168.1.1
),如果看到 PHP 信息页面,说明配置成功。
9. 其他配置
防火墙:确保 80 端口开放。
PHP 配置:编辑
/etc/php.ini
进行自定义配置。
如果 80 端口已被占用,可以选择以下方法解决:
方法 1:更换 Web 服务器的监听端口
将 Web 服务器的监听端口改为其他未被占用的端口(如 8080)。
修改 uhttpd
配置文件
编辑 /etc/config/uhttpd
,将 80
改为其他端口(如 8080
):
config uhttpd 'main' list listen_http '0.0.0.0:8080' list listen_http '[::]:8080' option home '/www' option interpreter '.php=/usr/bin/php-cgi'
保存后重启 uhttpd
:
/etc/init.d/uhttpd restart
访问时使用新端口,如 http://192.168.1.1:8080
。