元旦,不说了,没得玩,元旦的前一天电脑很蓝,告诉我你得重装系统了。于是又开始新一波的装系统(大神装的,不是我),配环境。先从配置PHP的环境配置说吧。
本次实验的主要材料
php -7.1.22包
nginx-1.15.8
Composer-Setup.exe
php_redis-3.1.6-7.1-ts-vc14-x64
在php-7.2以前,Object等关键字是软保留字,如果你的项目有Object为类名的,一定不要升级。PHP 7.2禁止类名为Object的巨坑
步骤:
1、配置php.ini文件
extension_dir = "ext"
enable_dl = On
cgi.force_redirect = 0
cgi.fix_pathinfo=1
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
#对于 php的项目代码,需要开启该项
extension=php_curl.dll
extension=php_mbstring.dll
#对于安装composer需要开启该项
extension=php_openssl.dll
#对于redis扩展,需要开启该项
extension=php_redis.dll
#时区设置
date.timezone = UTC
2、配置nginx.conf文件
经过的坑:一直报 No input file specified.
最后发现是 document_root 没有带$符号
server {
listen 80;
server_name order.test.yunshanmeicai.com;
location / {
#项目的根目录
root D:\work;
index index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
#项目的根目录
root D:\work;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# 替换scripts 为 $document_root 代表项目根目录意思。
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
3、配置启动php-cli和nginx
编写启动bat脚本
@echo off
REM Windows 下无效
REM set PHP_FCGI_CHILDREN=5
REM 每个进程处理的最大请求数,或设置为 Windows 环境变量
set PHP_FCGI_MAX_REQUESTS=1000
echo Starting PHP FastCGI...
RunHiddenConsole D:\php-7.1.22/php-cgi.exe -b 127.0.0.1:9000 -c D:\php-7.1.22/php.ini
echo Starting nginx...
RunHiddenConsole D:\nginx-1.15.8/nginx.exe -p D:\nginx-1.15.8
编写停止代码
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit
4、增加info.php文件,我的info.php文件在我的 D:\work的根目录。
<?php phpinfo(); ?>
访问:
http://localhost/info.php 成功!如果你失败了,检查下,坚持下去。
5、修改nginx.conf的配置,结合代码启动。
server {
listen 80;
server_name order.test.yunshanmeicai.com;
#项目根目录
root C:\Users\武刚鹏\Desktop\my-work\mall\commodity-order\public;
index index.php;
location / {
#所有的请求都走向 index.php
if (!-f $request_filename){
rewrite ^.*$ /index.php last;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root C:\Users\武刚鹏\Desktop\my-work\mall\commodity-order\public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
6、解决启动项目过程的问题,最后完成环境搭建。
php的也有许许多多的扩展库,需要使用composer来管理。
开启 php.ini的extension=php_openssl.dll,然后安装即可。
启动项目过程中,一般是遇到什么错处理什么错。
上网搜了下,项目中使用到了 curl库,于是又开启extension=php_curl.dll
Redis的错误,是因为没有安装Redis的扩展。注意php.info的界面提示,上面的php.info已经画出重点。
ts 线程安全,64位
http://pecl.php.net/package/redis/3.1.4RC1/windows
最后又出现了个错误
看代码
private $cache_path = '\tmp';
public function __construct($params)
{
parent::__construct($params);
if (!empty($params['cache_path'])) {
$this->cache_path = $params['cache_path'];
}
}
由于项目是在linux上部署的,代码上的 $cache_path='\tmp' 在linux环境是没有问题的,我是在windows开发,没办法,我就把代码改了。这个代码是排除在git之外的,改了也无碍。
private $cache_path = 'C:\Users\武刚鹏\tmp';
最后项目的环境以及代码部署完成。
如果你看到了这里:
安装需要的RunHiddenConsole.exe 见下面文章
http://www.cnblogs.com/huayangmeng/archive/2011/06/15/2081337.html