Windows Subsystem for Linux
(简称 WSL
)是一个为在 Windows 10 上能够原生运行 Linux 二进制可执行文件(ELF 格式)的兼容层。
注意。PHP-FPM 暂时只能通过监听 socket ,不能设置
listen 127.0.0.1:9000
!
GitHub:https://github.com/khs1994-php/wsl
修订记录
PHP-FPM 与 NGINX 只能通过
socket
方式连接,之前页面打开太慢解决不了,查看 GitHub 解决了该问题。解决办法:https://github.com/Microsoft/WSL/issues/2100Windows 支持 Debian 9 我们可以在 Docker 中编译 PHP 之后将编译好的文件复制出来即可,本人目前采用此方法。
如何启用
WSL
这里不再赘述,下方执行命令过程中出错,可以使用sudo
再次尝试执行。
软件列表
基于如下软件
WSL
Debian 9nginx
1.13.9PHP
7.2.3Mysql
5.7.20
nginx
编辑 /etc/apt/sources.list.d/nginx.list
文件。
1 | deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx |
添加密钥
1 | $ curl -fsSL http://nginx.org/packages/keys/nginx_signing.key | sudo apt-key add - |
安装
1 | $ sudo apt update |
打开 127.0.0.1
看到 nginx 默认页面。
新增配置文件
apt 安装的 nginx 没有 fastcgi.conf
配置文件,我们必须手动加入
1 | $ cd /etc/nginx |
修改主配置文件
https://github.com/Microsoft/WSL/issues/2100
解决 PHP
页面打开缓慢
1 | $ sudo vi /etc/nginx/nginx.conf |
PHP
详细编译说明请查看:https://www.khs1994.com/php/development/build.html
从 Docker 复制编译好的 PHP 请查看 GitHub,有疑问请提出 issue.
MySQL
使用 Docker for Windows
1 | $ docker run -it -d --name wsl-lnmp-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=mytest -e MYSQL_DATABASE=test --mount src=wsl-lnmp-mysql-data,target=/var/lib/mysql mysql |
使用 WSL
1 | $ sudo apt install mysql-server |
nginx 配置
编辑 /etc/nginx/conf.d/php.conf
1 | server { |
尝试通过 pecl 安装 PHP 扩展
执行过程中若提示错误,请使用 sudo
1 | $ sudo pecl update-channels |
编辑配置文件 /usr/local/php/etc/php.ini
在文件开头添加
1 | extension=redis |