Skip to content

Instantly share code, notes, and snippets.

@jdeathe
Last active April 27, 2018 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jdeathe/1c3f83cca26275232e8d816a69a36b7c to your computer and use it in GitHub Desktop.
Save jdeathe/1c3f83cca26275232e8d816a69a36b7c to your computer and use it in GitHub Desktop.
How to Configure the Time Zone on CentOS

CentOS - Configure Time Zone

System TimeZone

Setup a default ZONE environment variable.

Export the required local time zone value using the ZONE environment variable.

Skip this step if setting up a system with the default UTC time zone.

# export ZONE="Europe/London"

Set the system timezone

CentOS-6

# sed -i \
  -e "s~^\(ZONE=\).*$~\1${ZONE:-UTC}~" \
  /etc/sysconfig/clock \
&& ln -sf \
  /usr/share/zoneinfo/${ZONE:-UTC} \
  /etc/localtime

CentOS-7

# timedatectl set-timezone ${ZONE:-UTC}

PHP TimeZone

If PHP is installed it is necessary to set a valid default time zone.

# sed -r -i \
  -e "s~^;?(date.timezone[ ]+=).*$~\1 ${ZONE:-UTC}~" \
  /etc/php.ini

Restart services

Services will need reloading for the time zone changes to be picked up. Either restart the server or the applicable services - for example, if you have a running a MySQL or PHP Apache server you will need to reload the configuration to pick up the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment