160820服务器问题解决备忘

查看apache的错误日志

假如php不记录错误的时候,可以尝试看apache的日志,日志一般存放位置是: /etc/httpd/logs/error_log ,可以通过

tail -f /etc/httpd/logs/error_log

实时监听错误信息

php 时区没有设置

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.

需要在php.ini中设置时区

date.timezone = "Asia/Hong_Kong"

时区列表有:
一些常用的时区标识符说明:

Asia/Shanghai – 上海

Asia/Chongqing – 重庆

Asia/Urumqi – 乌鲁木齐

Asia/Hong_Kong – 香港

Asia/Macao – 澳门

Asia/Taipei – 台北

Asia/Singapore – 新加坡

PHP中设置时区方法小结

PHP 的session 丢失

PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0

可以通过设定

sudo chmod 777 /var/lib/php/session

给这个目录777权限,也尝试给/tmp 777权限

参考连接:

  1. PHP session handling errors
  2. Failed to write session data (files). Please verify that the current setting of session.save_path is correct

php ini_set display_errors

在服务器中,遇到500错误,总是看不到错误信息,代码中可以通过ini_set()方法,覆盖一些php.ini中的配置。

ini_set("display_errors","On");
error_reporting(E_ALL);

详细的说明请看参考连接:

  1. ini_set("display_errors","On");和error_reporting(E_ALL);

mysql 启动失败

MySQL Daemon failed to start.
Starting mysqld:    [FAILED]

参考

  1. 昨天在服務器搬遷時遇到問題, 就是搬遷後, Mysql Start Fail – MySQL 資料庫不能開始. 找了很久都沒有答案, 檢查程序如下

我尝试参考第1点的,在我的服务器的效果是:

  1. 由于我看了/var/log/mysqld.log和/var/log/syslog文件都是为空的
  2. 删除了最后一个mysql-bin.xxx档案,好像导致一些表不可用,需要修复

在运行了:

sudo ls -n /var/lib/mysql/

配置文件位置是: /etc/my.cnf

由于错误日志都为空,在/var/lib/mysql中有一个hostname.err文件,同事提醒我可以看看这个文件,通过

tail -f hostname.err

获取到:

Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0 thread_stack 0x40000
/usr/libexec/mysqld(my_print_stacktrace+0x2e)[0x78d00e]
/usr/libexec/mysqld(handle_fatal_signal+0x493)[0x675a93]
/lib64/libpthread.so.0(+0xf710)[0x7fed68776710]
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
160820 11:19:01 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

当我发送这个错误消息在QQ中时,老板说是磁盘满了,需要删除一个些文件,我是删除了服务器中的数据库备份。
删除文件之后

[vagrant@localhost mysql]# sudo service mysqld start
Starting mysqld:    [  OK  ]
[vagrant@localhost mysql]# sudo service httpd start
Starting httpd:     [  OK  ]

apache和mysql都启动成功。

修复mysql表

[vagrant@localhost ~]$ tail -f hostname.err
160820 11:38:03 [ERROR] /usr/libexec/mysqld: Table './yii2/user' is marked as crashed and should be repaired

大概意思是:这个数据库的表需要修复,我是使用参考连接1的SQL语句方法

REPAIR TABLE tablename

参考连接:

  1. 解決Table './dbname/tablename' is marked as crashed and should be repaired when using LOCK TABLES
  2. MySQL said: #1194 - Table 'tablename' is marked as crashed and should be repaired

参考连接2,应该是在phpmyadmin中的命令,未尝试。

原文地址:https://www.cnblogs.com/fsong/p/5790311.html