作者:星知苑 时间:2015-09-08 17:48:36
这次教程主要以windows 2008 sp2 32bit standard配置PHP 7.0RC2+Nginx 1.9.4+Mysql 5.6.26,并且开启HTTPS访问。
一、准备工作
1、Nginx+php+mysql等下载并解压:百度网盘
2、上述软件可能用到的VC++运行库下载:百度网盘
二、精简并安装Mysql
1、解压mysql-5.6.26-win32.zip到D:mysql-5.6.26-win32,并且重命名my-default.ini为my.ini[break]
2、删除docs、include、mysql-test、scripts和sql-bench文件夹,以及COPYING和README文件,删除剩余文件夹中pdb后缀名的文件
3、简单配置下my.ini,修改如下:
# basedir = ..... # datadir = ..... 修改为: basedir = "D:mysql-5.6.26-win32" datadir = "D:mysql-5.6.26-win32data"
4、添加mysql服务
CMD命令如下:
D:mysql-5.6.26-win32bin>mysqld -install MySQL --defaults-file="D:mysql-5.6.26-win32my.ini" D:mysql-5.6.26-win32bin>net start MySQL如果需要关闭服务,CMD命令输入“net stop MySQL”(不用输入双引号)
如果需要卸载服务,CMD命令输入“sc delete MySQL”(不用输入双引号)
二、安装PHP
1、解压php-7.0.0RC2-nts-Win32-VC14-x86.zip到D:PHP并且重命名php.ini-production为php.ini
2、修改php.ini
第725行 ; extension_dir = "ext" 先去前面的分号再改为 extension_dir = "D:phpext" 第735行enable_dl = Off 改为 enable_dl = On 第742行 ;cgi.force_redirect = 1 先去前面的分号再改为 cgi.force_redirect = 0 第770行 ;fastcgi.impersonate = 1 去掉前面的分号 第782行 ;cgi.rfc2616_headers = 0 先去前面的分号再改为 cgi.rfc2616_headers = 1 第879、883行,去掉前面的“;”extension=php_mysqli.dll和extension=php_pdo_mysql.dll (支持MYSQL数据库)
3、可以去掉extension=前面的“;”开启相应的扩展
三、安装Nginx
1、解压nginx-1.9.4到D:nginx-1.9.4并且修改D:nginx-1.9.4confnginx.conf
2、修改nginx.conf如下:
修改65-71行 #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; #} 先将前面的“#”去掉,再把“/scripts”改为“$document_root”,这里的“$document_root”就是指前面“root”所指的站点路径,这是改完后的: location ~ .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; }
四、BAT一键运行
1、一键运行;解压RunHiddenConsole到D,并把以下代码保存为start.bat
@echo off echo Starting PHP FastCGI... D:RunHiddenConsole.exe D:PHPphp-cgi.exe -b 127.0.0.1:9000 -c D:PHPphp.ini echo Starting nginx... D:RunHiddenConsole.exe D:nginx-1.9.4nginx.exe -p D:nginx-1.9.4 echo Starting mysql... net start MySQL
2、一件结束;把以下代码保存为stop.bat
@echo off echo Stopping nginx... taskkill /F /IM nginx.exe > nul echo Stopping PHP FastCGI... taskkill /F /IM php-cgi.exe > nul echo Stopping MySQL... net stop MySQL exit
3、phpinfo输出信息
五、开启HTTPS访问
1、SLL免费证书可以去沃通申请,沃通免费申请地址
2、我这边申请好了,把for nginx.zip提取到D:nginx-1.9.4conf
3、修改D:nginx-1.9.4confnginx.conf文件
修改98-115行: #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; # } #} 去掉每行前面的#,并且添加 location ~ .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; } 修改后完整如下: server { listen 443 ssl; server_name localhost; ssl_certificate 1_www.myxzy.com_bundle.crt; ssl_certificate_key 2_www.myxzy.com.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.php index.html index.htm; } location ~ .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; } }
4、HTTPS下phpinfo输出信息(域名本地host来测试)