记录thinkphp3.13移植到php7过程
来源:互联网 发布:淘宝家装APP 编辑:程序博客网 时间:2024/06/09 20:03
随着php7的兴起,越来越多的公司用php7了,下面记录一次thinkphp3.1.3项目移植到php7解决兼容性的过程。
先在thinkphp论坛搜索了下,搜到最多的答案就是修改Think\Lib\Template\ThinkTemplate.class.php文件,但是依然会有兼容性的问题。下面总结下步骤:
1、Mysql必须切换成PDO的驱动的连接方式。
请查看你的数据库配置文件,更换成下面对应的数据库参数:
return array (
'DB_TYPE' => 'pdo', //原来的mysql换成pdo
'DB_HOST' => '127.0.0.1',
'DB_NAME' => 'thinkphp',
'DB_USER' => 'root',
'DB_PWD' => '',
'DB_PORT' => '3306',
'DB_PREFIX' => '',
'DB_CHARSET' => 'utf8',
'DB_DSN' => 'mysql:host=127.0.0.1;dbname=thinkphp;charset=utf8', //这行一定要加
);
2、重定向修改。
打开除了默认主页的其他页面,会发现提示No input file specified.
下面是百度到的答案,博主用的是apache,index后面加上了?就搞定。
No input file specified修改
(一)IIS Noinput file specified
方法一:改PHP.ini中的doc_root行,打开ini文件注释掉此行,然后重启IIS
方法二:
请修改php.ini找到
; cgi.force_redirect = 1
去掉前面分号,把后面的1改为0
即
cgi.force_redirect = 0
(二)apacheNo input file specified
apache No input filespecified,今天是我们配置apache RewriteRule时出现这种问题,解决办法很简单如下
打开.htaccess 在RewriteRule 后面的index.php教程后面添加一个“?”
完整代码如下
.htaccess
RewriteEngine on
RewriteCond $1 !^(index.php|images|robots.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
如果是apache服务器出问题,看看是不是的Apache 把 .php 后缀的文件解析哪里有问题了。
总结
Apache 将哪些后缀作为 PHP 解析。例如,让 Apache 把 .php 后缀的文件解析为PHP。可以将任何后缀的文件解析为 PHP,只要在以下语句中加入并用空格分开。这里以添加一个 .phtml 来示例。
AddType application/x-httpd-php .php .phtml
为了将 .phps教程作为 PHP 的源文件进行语法高亮显示,还可以加上:
AddType application/x-httpd-php-source .phps
用通常的过程启动 Apache(必须完全停止 Apache 再重新启动,而不是用 HUP 或者USR1 信号使 Apache 重新加载)。
(三)nginx配置遭遇No inputfile specified
虚拟机测试nginx 遭遇 Noinput file specified,多方查找终于找到解决办法
1、 php.ini(/etc/php5/cgi/php.ini)的配置中这两项
cgi.fix_pathinfo=1 (这个是自己添加的)
doc_root=
2、nginx配置文件/etc/nginx/sites-available/default中注意以下部分
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
include fastcgi_params;
}
路径需要根据你主机主目录的实际情况填写
配置完以上部分,重启一下service nginx restart,应该没问题了
3、修改preg_replace为preg_replace_callback函数
因为preg_replace不能用/e修饰符,所以用preg_replace_callback代替preg_replace,修改ThinkTemplate.class就可以了。
其中有Think\Lib\Template\ThinkTemplate.class.php和ThinkPHP\Lib\Core\Dispatcher.class.php两处需要修改
(一)修改Think\Lib\Template\ThinkTemplate.class.php
这一步是为了让模板兼容
请先覆盖Thinkphp论坛解决方案
覆盖完这个文件先别急,这时候运行会发现报错了:
Call to undefined method TagLib::_()
这是因为闭包函数不能直接使用外部变量。
把417行(左右)
$content = preg_replace_callback($patterns, function($r) {
return $this->parseXmlTag($tagLib, $tag, $r[1], '');
},$content);
改为:
$content = preg_replace_callback($patterns, function($r) use ($tagLib,$tag) {
return $this->parseXmlTag($tagLib, $tag, $r[1], '');
},$content);
把426行(左右)
$content = preg_replace_callback($patterns, function($r) {
return $this->parseXmlTag($tagLib, $tag, $r[1], $r[2]);
},$content);
改为:
$content = preg_replace_callback($patterns, function($r) use($tagLib,$tag) {
return $this->parseXmlTag($tagLib, $tag, $r[1], $r[2]);
},$content);
(二)修改ThinkPHP\Lib\Core\Dispatcher.class.php
这一步是为了让参数兼容
把134行左右:
preg_replace('@(\w+)\/([^\/]+)@e', '$var[\'\\1\']=strip_tags(\'\\2\');', implode('/',$paths));
改为:
preg_replace_callback('@(\w+)\/([^\/]+)@',function($r) use (&$var){
$var[$r['1']] = strip_tags($r[2]);
},implode('/',$paths));
附上博主修改好的文件
修改好的文件
备注:用了以下函数、插件的还需要修改
1、修改PPHPExcel
打开PHPExcel\Extend\Vendor\PHPExcel\Calaculation\Functions.php第580行,删掉break;就可以了
2、mysql_get_server_info函数
mysql_get_server_info函数不可用了,暂未找到替代函数
好了,到此就大功告成了!
转自:http://blog.leanote.com/post/qiuyunbest/7c5ca2470bb3
- 记录thinkphp3.13移植到php7过程
- WifiDog移植到Ralink_ApSoC_SDK_4210过程记录
- 移植opencv2.4.9到android过程记录
- 记录nginx配置php7过程
- 移植rtmp到rtsp摄像机的过程记录(sdk2rtmp软件)
- 移植x264过程记录1
- 【TBRR】移植到2010记录
- linux的maven+turbine+turque java项目移植到windows eclipse的过程记录
- 全球独家原创:linux-3.4.5内核移植到MPC880过程记录
- Qt4.8.7 linux 程序移植到 Qt5.9 windows 记录过程
- WINCE4.2+sqlce1.0程序移植到WINCE5.0中的过程记录
- live555移植到Android过程.
- STM32F030C8移植到GD32F130C8过程
- boa-0.94.13移植到uclinux arm s3c4510b的过程
- thinkphp3.2学习记录
- ThinkPHP3.2.2学习记录
- OpenCV2.4.13 ARM版移植过程记录
- U-Boot移植过程概要记录
- 原始 socket 编程
- loadrunner Web_类函数之web_service_set_security()
- 习题二第4题
- 【LeetCode算法练习(C++)】Longest Common Prefix
- ORACLE_11g_Win64安装
- 记录thinkphp3.13移植到php7过程
- win10下Apache无法启动的解决方法
- nginx-lua worker 之间数据共享
- 1020月饼(贪心算法)
- 开始接触 Cocos2dx3.15
- JS极速适配
- Java300StudyNote(6)-JVM核心之JVM运行和类加载全过程(1)
- Git使用大全
- Paint滤镜效果