NetBSD配置nginx php-fpm

安装nginx

pkgin -y install nginx

配置nginx

默认配置文件路径/usr/pkg/etc/nginx/nginx.conf

vim /usr/pkg/etc/nginx/nginx.conf

找到location模块,往index这一行后面添加index.php

location / {
    root   share/exmples/nginx/html;
    index  index.html index.htm index.php;
}

往下翻找到# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
把location模块前面的#号注释符去掉,内容如下:

location ~ \.php$ {
#    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME /你的网站根目录$fastcgi_script_name;
    include        /usr/pkg/etc/nginx/fastcgi_params;
}

默认的根目录是/usr/pkg/share/examples/nginx/html
所以SCRIPT_FILENAME这一行后面我就写/usr/pkg/share/examples/nginx/html

按左上角Esc键,输入:wp 保存退出

开机自启

cp /usr/pkg/share/examples/rc.d/nginx /etc/rc.d
echo "nginx=YES" >> /etc/rc.conf

启动nginx

service nginx start

安装php

NetBSD仓库的PHP版本有56、74、80、81,我这里就选择80,需要输入完整的包名及版本
我也搞不懂为非要非要精确到小数点,我试了php80 php8.0 php-80 php-8.0都不行
可以用pkgin search php查询详细的版本

pkgin -y install php-8.0.17 php80-fpm 

开机自启

cp /usr/pkg/share/examples/rc.d/php_fpm /etc/rc.d
echo "php_fpm=YES" >> /etc/rc.conf

启动php-fpm

service php_fpm start

测试php

echo "<?php phpinfo(); ?>" >/usr/pkg/share/examples/nginx/html/info.php

浏览器打开ip或者/info.php

成功解析php

最后修改:2022 年 07 月 13 日
赏点儿?