init.php on line 211,PHP常见错误处理 - 米扑博客

本文记录了一些自己遇到的PHP常见错误和解决方法,方便今后查询。

问题1Could not reliably determine the server's fully qualified domain name

解决方案:

1) 用记事本打开 vim httpd.conf

将里面的 #ServerNamelocalhost:80 注释去掉即可(启动ServerName)

2) 重启apache

sudo ./bin/apachectl restart

3) 通过浏览器访问 http://localhost:80

如果页面显示 “It works!”,即表示apache已安装并启动成功。

补充说明:

using localhost.localdomain for ServerName 说不能确认服务器完全确认域名 localhost.localdoman 这个问题怎么解决

最佳答案:

vi /etc/httpd/conf/httpd.conf  加入一句  ServerName  localhost:80

问题2 PHP网站访问出现如下错误:

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in/home/homer/workspace/proxy_client/index.php on line 1742015-01-10)

解决方案:

出现这个问题是因为网站代码里面没有正确设置时区造成的,从PHP 5.3开始,当使用date()等函数时,如果timezone设置不正确,在每一次调用时间函数时都会产生E_NOTICE 或者 E_WARNING信息。解决的方法有三种:

方法一:使用较低版本的PHP,如PHP 5.2.17

方法二:修改 php.ini配置文件,例如:

/opt/php-5.5.15-server/lib/php.ini

/opt/php-5.5.15-server/etc/php.ini

修改上述两文件的

date.timezone = "Asia/Shanghai"或date.timezone = PRC

步骤如下:

1) 打开php.ini 配置文件 ,找到

[Date]

; Defines the default timezone used by the date functions

; http://php.net/date.timezone

;date.timezone =

修改为:

[Date]

; Defines the default timezone used by the date functions

; http://php.net/date.timezone

date.timezone = PRC

;date.timezone = "Asia/Shanghai"

2)重启apache服务,使配置生效

sudo ./bin/apachectl restart

方法三:在网页页头使用date_default_timezone_set()函数设置

例如: <?php date_default_timezone_set('PRC');  ?>

// 表示中国东8区时间,测试 echo date('Y-m-d H:i:s');

方法四:在页头使用 ini_set('date.timezone','Asia/Shanghai');

对于中国可选值:Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi (依次为重庆,上海,乌鲁木齐)港台地区可用:Asia/Macao ,Asia/Hong_Kong ,Asia/Taipei (依次为澳门,香港,台北),还有新加坡:Asia/Singapore,老的PRC也行。

问题3PDO连接MySQL数据库错误

Notice: Undefined index: pageindex in /home/homer/workspace/proxy_client/index.php on line 211

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'in /home/homer/workspace/proxy_client/index.php:223 Stack trace: #0 /home/homer/workspace/proxy_client/index.php(223): PDO->__construct('mysql:host=115....', 'user', 'pass') #1 {main} thrown in/home/homer/workspace/proxy_client/index.php on line 223

解决方案:

需要给PHP加PDO扩展,打开PHP.INI 把extension=php_pdo.dll 前面的分号去掉,如下图:

29d5b82ba595a24924e067e0eedc6ccf.png

重启APACHE

homer@homer-pc:~$sudo /etc/init.d/apache2 restart

* Restarting web server apache2                                               [ OK ]

如果没有 pdo_mysql 模块,则查看并安装

You need to have a module called pdo_mysql. Looking for following in phpinfo()

pdo_mysql

PDO Driver for MySQL, client library version => 5.1.44

----

Check that you have the mysql extension installed on your server.

In Ubuntu/Debian you check for the package with:

dpkg --get-selections | grep php5-mysql

Install the php5-mysql package if you do not have it.

In Ubuntu/Debian you can use:

sudo apt-get install php5-mysql

Lastly, to get it working with Apache, you will need to restart Apache.

sudo /etc/init.d/apache2 restart

通过 phpinfo.php 验证 pdo_mysql 安装成功

481497388a5ef6cc20aad057fb0828a9.png

添加网站路径

sudo vim /etc/apache2/apache2.conf

f603bf9551f9547c9afe4af982c7053c.png

更多相关 pdo_mysql 请参见米扑博客: PHP5中PDO的简单使用

PHP 线上的生产环境不显示警告(Warning)

Warning: sizeof(): Parameter must be an array or an object that implements Countable in lib/PayPal/Common/PayPalModel.php on line 179

Warning: sizeof(): Parameter must be an array or an object that implements Countable in lib/PayPal/Common/PayPalModel.php on line 179

解决办法:

1、修改 php.ini(发现没有效果)

vim /usr/local/php/lib/php.ini

; error_reporting

;error_reporting = E_ALL

;error_reporting = E_ALL & ~E_DEPRECATED

;error_reporting = E_ALL & ~E_ERROR

;error_reporting = E_ALL & ~E_NOTICE

;error_reporting = E_ALL & ~E_WARNING

;error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

error_reporting = E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT

说明:~E_WARNING 表示不显示警告,波浪线表示否的意思

在 php 文件最开头,可以添加一行:

// 关闭所有PHP错误报告

error_reporting(0);

// Report simple running errors

error_reporting(E_ERROR | E_WARNING | E_PARSE);

// 报告 E_NOTICE也挺好 (报告未初始化的变量或者捕获变量名的错误拼写)

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// 除了 E_NOTICE,报告其他所有错误

error_reporting(E_ALL ^ E_NOTICE);

// 报告所有 PHP 错误 (参见 changelog)

error_reporting(E_ALL);

// 报告所有 PHP 错误

error_reporting(-1);

// 和 error_reporting(E_ALL); 一样

ini_set('error_reporting', E_ALL);

?>

2、修改 php.ini 配置参数(发现没有效果)

编辑php.ini ,查找"display_errors =" ,将“=”后面的值改为"Off

vim /usr/local/php/lib/php.ini

display_errors = Off

3、PHP 文件开头添加函数 (有效,推荐)

ini_set("error_reporting","E_ALL & ~E_NOTICE");

例如:

namespace PayPal\Common;

ini_set("error_reporting","E_ALL & ~E_NOTICE");

use PayPal\Validation\JsonValidator;

use PayPal\Validation\ModelAccessorValidator;

注:实测这么写是不对的:

ini_set("error_reporting","E_ALL");

ini_set("error_reporting","E_ALL & ~E_NOTICE");

正确写法应该是:

error_reporting(E_ALL);

error_reporting(E_ALL & ~E_NOTICE);//(有效,推荐)

参考推荐:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值