Windows下Nginx+PHP+ThinkPHP的安装与配置
下载:
- PHP: PHP5.6
- Nginx:Nginx
- ThinkPHP:ThinkPHP
- RunHiddenConsole:RunHiddenConsole 隐藏控制台界面工具
1.解压PHP5.6
2.解压Nginx
3.解压ThinkPHP:
4.修改PHP文件夹目录下的php.ini-development文件,把“-development”去掉就可以,文件内容先不做任何修改。
5.修改Nginx配置文件nginx.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root D:\php\xxx\public;
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;
}
location ~ .*\.php.* {
root D:\php\xxx\public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
set $real_script_name $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
}
# 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;
#}
}
6.下载RunHiddenConsole.exe和配置文件
start_nginx.bat:
@echo off
set PHP_FCGI_MAX_REQUESTS=1000
echo Starting PHP FastCGI...
RunHiddenConsole D:\php\php-5.6.40-Win32-VC11-x64\php-cgi.exe -b 127.0.0.1:9000 -c D:\php\php-5.6.40-Win32-VC11-x64\php.ini
echo Starting nginx...
RunHiddenConsole D:\php\nginx-1.15.9\nginx.exe
pause
stop_nginx.bat:
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit
7.双击RunHiddenConsole.exe
8.打开浏览器,输入“http://localhost/index.php”
完成!!
- 常见问题:
1.开启GD库:找到php文件夹下面的php.ini文件,把extension=php_gd2.dll前面的;去掉
2.curl_init扩展:把extension=php_curl.dll前面的;去掉
3.安装mysqli扩展:把extension=php_mysqli.dll前面的;去掉
4.更改PHP扩展位置的目录路径:extension_dir=“ext” 默认是C盘下的,更改成php文件夹下面的ext文件夹
5.could not find driver错误:把extension=php_pdo_mysql.dll前面的;去掉