前言
由於咱以前是用PHP做的東西,又不想重新用 OpenResty自帶的編寫,所以呢咱設置下,可以像以前Apache那樣訪問PHP文件
首先去下載 PHP
https://windows.php.net/download#php-7.3
或者在文章最上面的git 鏈接上下載
解壓到自己的電腦上
改一下名字,名字太長..
把php.ini-development 這個文件復制出來一份,,然后名字改為 php.ini
修改 php.ini
去掉前面的 ;
cgi.fix_pathinfo=1
打開並修改openresty里面的 nginx.conf文件
1.去掉屏蔽
修改后
2.修改路徑
1.php路徑和html路徑這樣設置一樣,會導致啟動錯誤
2.把路徑統一寫到外面,可以解決錯誤
root C:\openresty-1.15.8.2-win64\html;
請根據自己的填寫
3.修改
修改為
$document_root$fastcgi_script_name;
參考代碼
server { #虛擬主機 listen 80; # 監聽端口 server_name localhost; # 監聽域名 #charset koi8-r; #access_log logs/host.access.log main; root "C:\openresty-1.15.8.2-win64\html";#PHP文件訪問路徑和html路徑設置的訪問一樣,單獨拿出來這個路徑 location / {#就是http://IP/無論什么名字都會進來 #root html; index index.html index.htm index.php;#如果沒有前面的,就自動訪問index.php } #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 # 172.26.94.113 127.0.0.1 location ~ \.php$ {#~區分大小寫 \前面任意 后面跟着 .php $ 代表結束 http://IP/任意/任意.php #root html; fastcgi_pass 127.0.0.1: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; #} }
配置完了OpenResty
如果啟動過 Nginx 需要先關閉
然后重新啟動
里面有了說明啟動了
然后進入命令提示行
輸入命令
C:\php7/php-cgi.exe -b 127.0.0.1:9000 -c C:\php7/php.ini
提示:
C:/php7/php-cgi.exe -b 127.0.0.1:9000 -c C:/php7/php.ini
C:/php7根據自己的文件解壓路徑填寫
按回車 運行命令
如果出現以下錯誤
需要安裝
根據自己的系統選擇安裝
然后重試
正常啟動后
現在測試下,根目錄放個 ceshi.php的文件
里面寫上
<?php echo 1234; ?>
把自己以前的文件全部拷貝到這個目錄就可以
補充
如果現在關閉控制台
PHP功能也會關閉
咱用這個來解決這個問題
打開下面的文件,改一下自己的php 和 nginx 路徑
然后雙擊啟動即可