tp3.1在php5.6+模板不显示或者日志文件很多错误解决办法

今天在3.1和laravel5.4部署同一台服务器上的时候发现tp模板不显示,一片空白,首先服务器试着安装了5.6之后再运行3.1是可以出来呢,但是发现好多警告,preg匹配的函数错误

首先百度第二篇就看到了

下面把博文贴出来


随着php7的兴起,越来越多的公司用php7了,下面记录一次thinkphp3.1.3项目移植到php7解决兼容性的过程。

先在thinkphp论坛搜索了下,搜到最多的答案就是修改Think\Lib\Template\ThinkTemplate.class.php文件,但是依然会有兼容性的问题。下面总结下步骤:

1、Mysql必须切换成PDO的驱动的连接方式。

请查看你的数据库配置文件,更换成下面对应的数据库参数:

 
 
  1. return array (
  2. 'DB_TYPE' => 'pdo', //原来的mysql换成pdo
  3. 'DB_HOST' => '127.0.0.1',
  4. 'DB_NAME' => 'thinkphp',
  5. 'DB_USER' => 'root',
  6. 'DB_PWD' => '',
  7. 'DB_PORT' => '3306',
  8. 'DB_PREFIX' => '',
  9. 'DB_CHARSET' => 'utf8',
  10. 'DB_DSN' => 'mysql:host=127.0.0.1;dbname=thinkphp;charset=utf8', //这行一定要加
  11. );

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教程后面添加一个“?”

完整代码如下

 
 
  1. .htaccess
  2. RewriteEngine on
  3. RewriteCond $1 !^(index.php|images|robots.txt)
  4. 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中注意以下部分

 
 
  1. location ~ \.php$ {
  2. fastcgi_pass 127.0.0.1:9000;
  3. fastcgi_index index.php;
  4. fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
  5. include fastcgi_params;
  6. }

路径需要根据你主机主目录的实际情况填写

配置完以上部分,重启一下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行(左右)

 
 
  1. $content = preg_replace_callback($patterns, function($r) {
  2. return $this->parseXmlTag($tagLib, $tag, $r[1], '');
  3. },$content);

改为:

 
 
  1. $content = preg_replace_callback($patterns, function($r) use ($tagLib,$tag) {
  2. return $this->parseXmlTag($tagLib, $tag, $r[1], '');
  3. },$content);

把426行(左右)

 
 
  1. $content = preg_replace_callback($patterns, function($r) {
  2. return $this->parseXmlTag($tagLib, $tag, $r[1], $r[2]);
  3. },$content);

改为:

 
 
  1. $content = preg_replace_callback($patterns, function($r) use($tagLib,$tag) {
  2. return $this->parseXmlTag($tagLib, $tag, $r[1], $r[2]);
  3. },$content);

(二)修改ThinkPHP\Lib\Core\Dispatcher.class.php

这一步是为了让参数兼容

把134行左右:

 
 
  1. preg_replace('@(\w+)\/([^\/]+)@e', '$var[\'\\1\']=strip_tags(\'\\2\');', implode('/',$paths));

改为:

 
 
  1. preg_replace_callback('@(\w+)\/([^\/]+)@',function($r) use (&$var){
  2. $var[$r['1']] = strip_tags($r[2]);
  3. },implode('/',$paths));

附上博主修改好的文件

修改好的文件


备注:用了以下函数、插件的还需要修改

1、修改PPHPExcel

打开PHPExcel\Extend\Vendor\PHPExcel\Calaculation\Functions.php第580行,删掉break;就可以了

2、mysql_get_server_info函数

mysql_get_server_info函数不可用了,暂未找到替代函数

好了,到此就大功告成了!


到这里解决了一大半部分至于mysql_get_server_info

可以数据库查询:

  1. select VERSION();

这算一种方法: mysqli_get_server_info

猜你喜欢

转载自blog.csdn.net/u010757785/article/details/77058936