php+nginx+sqlite3 windows环境搭建
前言
不太喜欢集成的环境,自己手搓一个 ,
东西我都知道是干啥的,安心
准备
PHP For Windows: Binaries and sources Releases
以上是各个文件的下载的地方
配置
在php的文件里找到php.ini-development拷贝一份并命名为php.ini
找到一下选项解除注释
extension_dir = "./ext"
cgi.fix_pathinfo = 1
extension=pdo_sqlite
extension=sqlite3
nginx设置
找到conf文件下的nginx.conf
server {
listen 81;//这里是要修改的,默认是80
server_name localhost;//这里 默认,改成域名的话需要在host里面添加解析
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root D:\home\StuManager;//这个修改成项目的根目录
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
//以下是被取消注释的部分
location ~ \.php$ {
root D:\home\StuManager;//和上面的一样改成项目的根目录
fastcgi_pass 127.0.0.1:9001;//默认9000,改成自己想要的
fastcgi_index index.php;
//下面直接照抄就行
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
使用
以下是启动脚本
@echo off
echo Starting PHP FastCGI...
;这里的端口要和nginx.conf中的fastcgi_pass中设置的一致
;改成你的路径
start /b D:\home\StuManager\ENV\php-8.2.10/php-cgi.exe -b 127.0.0.1:9001 -c D:\home\StuManager\ENV\php-8.2.10/php.ini
echo Starting nginx...
cd D:\home\StuManager\ENV\nginx-1.24.0
start /b nginx.exe
echo server at http://localhost:81
;这里打印地址方便打开网页
pause
/b选项使命令在后台运行不产生 命令行窗口
以下是关闭脚本
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit
直接照抄就行
运行的时候别忘了加个index.html或者phpinfo.php来测试以下是否有效
以下是测试sqlite3的php脚本
<?php
class MyDB extends SQLite3
{
function __construct()
{
$this->open('test.db');
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
} else {
echo "Opened database successfully\n";
}
?>
成功会在网页打印Opened database successfully,
项目根目录下会生成一个test.db