centos修改php时间的方法:1、修改硬件时区;2、修改系统时区;3、修改php.ini的时区设置;4、通过crontab将时间同步即可。

本文操作环境:centos6.5系统、PHP7.1版、DELL G3电脑
centos怎么修改php时间?
修改 linux 时区时间和 php 时区
问题:客户美国服务器时间不对
立即学习“PHP免费学习笔记(深入)”;
第一步,先修改硬件时区。
vim /etc/sysconfig/clock
将 ZONE="America/New_York" 注释,加多一行 ZONE="Asia/Shanghai"
第二步,修改系统时区
cp /etc/localtime /etc/localtime.bak rm -rf /etc/localtime ln -svf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime yum install ntpdate -y ntpdate 0.centos.pool.ntp.org date clock -w #将目前 Linux 的时间写到 BIOS 里面去! clock -r #检查 BIOS 里面的时间
第三步,修改 php.ini 的时区设置
date.timezone = PRC
第四步,写个 crontab 将时间同步(特殊情况下,加上这个)
#Ansible: Time synchronization 00 01 * * * /usr/sbin/ntpdate 0.centos.pool.ntp.org >/dev/null
怎样设置每次开机同步一次时间
vim /etc/rc.local usr/sbin/ntpdate 0.centos.pool.ntp.org >/dev/null
上面是设置 centos6.5 的时区和时间的,下面说的是 centos7的
yum -y install ntp systemctl enable ntpd ntpdate -u cn.pool.ntp.org systemctl start ntpd #设置时区 timedatectl set-timezone Asia/Shanghai
推荐学习:《PHP视频教程》
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号