wnmp環(huán)境搭建
我的服務(wù)器只有C盤篮绿,所有文件都放在C盤威沫,在C盤新建Wnmp目錄
1:MariaDB
- 官網(wǎng)下載直接安裝即可下載地址https://downloads.mariadb.org
- 安裝路徑:
C:\Wnmp\MariaDB 10.4\
- 配置默認(rèn)密碼芯丧,以及設(shè)置是否開(kāi)啟遠(yuǎn)程鏈接(遠(yuǎn)程連接需要防火墻同時(shí)打開(kāi)端口)
- 然后是配置服務(wù)名
- 安裝完成蘸泻,自帶了一個(gè)
HeidiSQL
可以用來(lái)測(cè)試是否安裝并運(yùn)行永品,安裝完成會(huì)跟隨開(kāi)機(jī)一起啟動(dòng)滚躯,可以不用額外的配置
2:nginx
- 下載地址:http://nginx.org/en/download.html
- 解壓到
C:\Wnmp\nginx-1.17.0
- 在php講解配置nginx
- 新建3個(gè)bat啟動(dòng)腳本放在
C:\Wnmp\nginx-1.17.0
方便管理
start.bat
start nginx
restart.bat
nginx.exe -s reload
stop.bat
nginx.exe -s quit
3:php
- 下載地址:https://windows.php.net/download#php-7.3,nginx選擇非線程安全版本即可
- 解壓到
C:\Wnmp\php
- 防止進(jìn)程關(guān)閉
RunHiddenConsole.exe
- 們將
php.ini-production
(相當(dāng)于舊版的php.ini-recommended
)后綴改為ini柳畔,用notepad++編輯馍管,找到
extension_dir = "./ext"
這一行,改為
extension_dir = "C:/wnmp/php/ext"
然后把后面的
;extension=php_mysql.dll
;extension=php_pdo_mysql.dll
;cgi.fix_pathinfo=1
前的分號(hào)刪除掉
extension=php_mysql.dll
extension=php_pdo_mysql.dll
cgi.fix_pathinfo=1
網(wǎng)上教程上的
;extension=php_mysql.dll
在php7中也沒(méi)有了薪韩,其實(shí)在之前的Mariadb中确沸,sqli已經(jīng)強(qiáng)制性了,使用sql會(huì)warning(不確定是不是真的),mysqli中的i意為improvement
另外php_pdo_mysql.dll的擴(kuò)展一定要打開(kāi)
配置nginx
新建一個(gè)
php_processes.conf
內(nèi)容如下# DO NOT MODIFY!!! THIS FILE IS MANAGED BY THE WNMP CONTROL PANEL. upstream php_processes { server 127.0.0.1:9000 weight=1; }
nodepad++打開(kāi)配置文件
C:\Wnmp\nginx-1.17.0\conf\nginx.conf
躬存,所有配置如下#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid logs/nginx.pid; events { # Max value 16384 worker_connections 8192; # Accept multiple connections multi_accept on; } http { include php_processes.conf; include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; ssl_session_timeout 10m; ssl_protocols TLSv1.2 TLSv1.1 TLSv1 SSLv3; ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!ADH:!AECDH:!MD5:!DSS; ssl_prefer_server_ciphers on; gzip on; # http server # Begin HTTP Server server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; ## Root and index files. root C:\Wnmp\www; index index.php index.html index.htm; ## If no favicon exists return a 204 (no content error). location = /favicon.ico { try_files $uri =204; log_not_found off; access_log off; } ## Don't log robots.txt requests. location = /robots.txt { allow all; log_not_found off; access_log off; } ## Try the requested URI as files before handling it to PHP. location /app/blog/ { if (!-e $request_filename) { rewrite ^(.*)$ /foldername/index.php$1 last; } } location ~ .*\.php(\/.*)*$ { try_files $uri =404; fastcgi_pass php_processes; fastcgi_index index.php; set $path_info ""; set $real_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { set $real_script_name $1; set $path_info $2; } fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; include fastcgi_params; } #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 html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$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; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
這里有個(gè)很大的坑就是我安裝的博客并不在根目錄下而是在根目錄下的app/blog/下面
typecho需要開(kāi)啟偽靜態(tài)张惹,網(wǎng)上大都是這個(gè)樣子的
if (!-e $request_filename) { rewrite ^(.*)$ /foldername/index.php$1 last; }
若php應(yīng)用安裝在根目錄下沒(méi)有問(wèn)題,但是不在根目錄下會(huì)造成只有首頁(yè)能訪問(wèn)岭洲,無(wú)法訪問(wèn)后臺(tái)和文章界面
正確的應(yīng)該修改成如下
location /app/blog/ { if (!-e $request_filename) { rewrite ^(.*)$ /foldername/index.php$1 last; } }
啟動(dòng)php
在
C:\Wnmp
新建start-php.bat
內(nèi)容如下
RunHiddenConsole C:/wnmp/php/php-cgi.exe -b 127.0.0.1:9000 -c C:/wnmp/php/php.ini
啟動(dòng)
- 先啟動(dòng)
C:\Wnmp
下面的start-php.bat
- 然后啟動(dòng)nginx
- 搭建工作就完成的差不多了,現(xiàn)在到www目錄下坎匿,新建一個(gè)phpinfo.php的探針盾剩,內(nèi)容如下:
<?php
phpinfo();
?>
打開(kāi)瀏覽器訪問(wèn)http://localhost/phpinfo.php,如果看到php探針信息替蔬,就說(shuō)明搭建成功了告私。
總結(jié)
在搭建的時(shí)候最坑的就是偽靜態(tài)路徑那個(gè)問(wèn)題,百度谷歌了很多次沒(méi)有解決承桥,后面睡覺(jué)前手機(jī)上看到一篇文章php項(xiàng)目路徑不在根目錄還需要額外的配置才解決驻粟。
總之集成環(huán)境很多,像wnmp,xampp
蜀撑,都可以實(shí)現(xiàn)類似的功能挤巡,但自己搭建多了一個(gè)實(shí)踐的過(guò)程。
知其然酷麦,才能知其所以然
參考
搭建wnmp的時(shí)候參考了八個(gè)比特的博客
原文鏈接:WNMP搭建筆記
版權(quán)聲明:本文采用知識(shí)共享署名-非商業(yè)性使用 4.0 國(guó)際許可協(xié)議進(jìn)行許可