Change Apache/PHP timezone

When creating websites, you may need to modify the timezone for Apache/PHP. There are two ways – you can set the timezone in the .hatccess file or in a PHP file (index.php or another file that will be loaded first).

In the .htaccess file use SetEnv TZ <timezone> to set the enviromental value TZ

//examples
SetEnv TZ Asia/Manila
SetEnv TZ America/Fort_Nelson

You can also set here the date.timezone PHP value with php_value date.timezone “<timezone>”

php_value date.timezone "America/Cayenne"

To set the default timezone in a PHP file use the code:

<?php
date_default_timezone_set('America/Denver');

//
?>

You can also set in PHP the enviromental variable TZ

<?php
putenv("TZ=Africa/Accra");
?>

If your host allow the use of .ini file you can set the timezone in such a file

date.timezone = "Africa/Cairo"
Country codeTZ database nameUTC offset ±hh:mmUTC DST offset ±hh:mm
CIAfrica/Abidjan+00:00+00:00
GHAfrica/Accra+00:00+00:00
ETAfrica/Addis_Ababa+03:00+03:00
DZAfrica/Algiers+01:00+01:00
ERAfrica/Asmara+03:00+03:00
MLAfrica/Bamako+00:00+00:00
CFAfrica/Bangui+01:00+01:00
GMAfrica/Banjul+00:00+00:00
GWAfrica/Bissau+00:00+00:00
MWAfrica/Blantyre+02:00+02:00
CGAfrica/Brazzaville+01:00+01:00
BIAfrica/Bujumbura+02:00+02:00
EGAfrica/Cairo+02:00+02:00
MAAfrica/Casablanca+01:00+01:00
ESAfrica/Ceuta+01:00+02:00
GNAfrica/Conakry+00:00+00:00
SNAfrica/Dakar+00:00+00:00
TZAfrica/Dar_es_Salaam+03:00+03:00
DJAfrica/Djibouti+03:00+03:00
CMAfrica/Douala+01:00+01:00
EHAfrica/El_Aaiun+00:00+01:00
SLAfrica/Freetown+00:00+00:00
BWAfrica/Gaborone+02:00+02:00
ZWAfrica/Harare+02:00+02:00
ZAAfrica/Johannesburg+02:00+02:00
SSAfrica/Juba+03:00+03:00
UGAfrica/Kampala+03:00+03:00
SDAfrica/Khartoum+02:00+02:00
RWAfrica/Kigali+02:00+02:00
CDAfrica/Kinshasa+01:00+01:00
NGAfrica/Lagos+01:00+01:00
GAAfrica/Libreville+01:00+01:00
TGAfrica/Lome+00:00+00:00
AOAfrica/Luanda+01:00+01:00
CDAfrica/Lubumbashi+02:00+02:00
ZMAfrica/Lusaka+02:00+02:00
GQAfrica/Malabo+01:00+01:00
MZAfrica/Maputo+02:00+02:00
LSAfrica/Maseru+02:00+02:00
SZAfrica/Mbabane+02:00+02:00
SOAfrica/Mogadishu+03:00+03:00
LRAfrica/Monrovia+00:00+00:00
KEAfrica/Nairobi+03:00+03:00
TDAfrica/Ndjamena+01:00+01:00
NEAfrica/Niamey+01:00+01:00
MRAfrica/Nouakchott+00:00+00:00
BFAfrica/Ouagadougou+00:00+00:00
BJAfrica/Porto-Novo+01:00+01:00
STAfrica/Sao_Tome+00:00+00:00
Africa/Timbuktu+00:00+00:00
LYAfrica/Tripoli+02:00+02:00
TNAfrica/Tunis+01:00+01:00
NAAfrica/Windhoek+02:00+02:00
USAmerica/Adak-10:00-09:00
USAmerica/Anchorage-09:00-08:00
AIAmerica/Anguilla-04:00-04:00
AGAmerica/Antigua-04:00-04:00
BRAmerica/Araguaina-03:00-03:00
ARAmerica/Argentina/Buenos_Aires-03:00-03:00
ARAmerica/Argentina/Catamarca-03:00-03:00
America/Argentina/ComodRivadavia-03:00-03:00
ARAmerica/Argentina/Cordoba-03:00-03:00
ARAmerica/Argentina/Jujuy-03:00-03:00
ARAmerica/Argentina/La_Rioja-03:00-03:00
ARAmerica/Argentina/Mendoza-03:00-03:00
ARAmerica/Argentina/Rio_Gallegos-03:00-03:00
ARAmerica/Argentina/Salta-03:00-03:00
ARAmerica/Argentina/San_Juan-03:00-03:00
ARAmerica/Argentina/San_Luis-03:00-03:00
ARAmerica/Argentina/Tucuman-03:00-03:00
ARAmerica/Argentina/Ushuaia-03:00-03:00
AWAmerica/Aruba-04:00-04:00
PYAmerica/Asuncion-04:00-03:00
CAAmerica/Atikokan-05:00-05:00
America/Atka-10:00-09:00
BRAmerica/Bahia-03:00-03:00
MXAmerica/Bahia_Banderas-06:00-05:00
BBAmerica/Barbados-04:00-04:00
BRAmerica/Belem-03:00-03:00
BZAmerica/Belize-06:00-06:00
CAAmerica/Blanc-Sablon-04:00-04:00
BRAmerica/Boa_Vista-04:00-04:00
COAmerica/Bogota-05:00-05:00
USAmerica/Boise-07:00-06:00
America/Buenos_Aires-03:00-03:00
CAAmerica/Cambridge_Bay-07:00-06:00
BRAmerica/Campo_Grande-04:00-03:00
MXAmerica/Cancun-05:00-05:00
VEAmerica/Caracas-04:00-04:00
America/Catamarca-03:00-03:00
GFAmerica/Cayenne-03:00-03:00
KYAmerica/Cayman-05:00-05:00
USAmerica/Chicago-06:00-05:00
MXAmerica/Chihuahua-07:00-06:00
America/Coral_Harbour-05:00-05:00
America/Cordoba-03:00-03:00
CRAmerica/Costa_Rica-06:00-06:00
CAAmerica/Creston-07:00-07:00
BRAmerica/Cuiaba-04:00-03:00
CWAmerica/Curacao-04:00-04:00
GLAmerica/Danmarkshavn+00:00+00:00
CAAmerica/Dawson-08:00-07:00
CAAmerica/Dawson_Creek-07:00-07:00
USAmerica/Denver-07:00-06:00
USAmerica/Detroit-05:00-04:00
DMAmerica/Dominica-04:00-04:00
CAAmerica/Edmonton-07:00-06:00
BRAmerica/Eirunepe-05:00-05:00
SVAmerica/El_Salvador-06:00-06:00
America/Ensenada-08:00-07:00
CAAmerica/Fort_Nelson-07:00-07:00
America/Fort_Wayne-05:00-04:00
BRAmerica/Fortaleza-03:00-03:00
CAAmerica/Glace_Bay-04:00-03:00
GLAmerica/Godthab-03:00-02:00
CAAmerica/Goose_Bay-04:00-03:00
TCAmerica/Grand_Turk-05:00-04:00
GDAmerica/Grenada-04:00-04:00
GPAmerica/Guadeloupe-04:00-04:00
GTAmerica/Guatemala-06:00-06:00
ECAmerica/Guayaquil-05:00-05:00
GYAmerica/Guyana-04:00-04:00
CAAmerica/Halifax-04:00-03:00
CUAmerica/Havana-05:00-04:00
MXAmerica/Hermosillo-07:00-07:00
USAmerica/Indiana/Indianapolis-05:00-04:00
USAmerica/Indiana/Knox-06:00-05:00
USAmerica/Indiana/Marengo-05:00-04:00
USAmerica/Indiana/Petersburg-05:00-04:00
USAmerica/Indiana/Tell_City-06:00-05:00
USAmerica/Indiana/Vevay-05:00-04:00
USAmerica/Indiana/Vincennes-05:00-04:00
USAmerica/Indiana/Winamac-05:00-04:00
America/Indianapolis-05:00-04:00
CAAmerica/Inuvik-07:00-06:00
CAAmerica/Iqaluit-05:00-04:00
JMAmerica/Jamaica-05:00-05:00
America/Jujuy-03:00-03:00
USAmerica/Juneau-09:00-08:00
USAmerica/Kentucky/Louisville-05:00-04:00
USAmerica/Kentucky/Monticello-05:00-04:00
America/Knox_IN-06:00-05:00
BQAmerica/Kralendijk-04:00-04:00
BOAmerica/La_Paz-04:00-04:00
PEAmerica/Lima-05:00-05:00
USAmerica/Los_Angeles-08:00-07:00
America/Louisville-05:00-04:00
SXAmerica/Lower_Princes-04:00-04:00
BRAmerica/Maceio-03:00-03:00
NIAmerica/Managua-06:00-06:00
BRAmerica/Manaus-04:00-04:00
MFAmerica/Marigot-04:00-04:00
MQAmerica/Martinique-04:00-04:00
MXAmerica/Matamoros-06:00-05:00
MXAmerica/Mazatlan-07:00-06:00
America/Mendoza-03:00-03:00
USAmerica/Menominee-06:00-05:00
MXAmerica/Merida-06:00-05:00
USAmerica/Metlakatla-09:00-08:00
MXAmerica/Mexico_City-06:00-05:00
PMAmerica/Miquelon-03:00-02:00
CAAmerica/Moncton-04:00-03:00
MXAmerica/Monterrey-06:00-05:00
UYAmerica/Montevideo-03:00-03:00
America/Montreal-05:00-04:00
MSAmerica/Montserrat-04:00-04:00
BSAmerica/Nassau-05:00-04:00
USAmerica/New_York-05:00-04:00
CAAmerica/Nipigon-05:00-04:00
USAmerica/Nome-09:00-08:00
BRAmerica/Noronha-02:00-02:00
USAmerica/North_Dakota/Beulah-06:00-05:00
USAmerica/North_Dakota/Center-06:00-05:00
USAmerica/North_Dakota/New_Salem-06:00-05:00
MXAmerica/Ojinaga-07:00-06:00
PAAmerica/Panama-05:00-05:00
CAAmerica/Pangnirtung-05:00-04:00
SRAmerica/Paramaribo-03:00-03:00
USAmerica/Phoenix-07:00-07:00
TTAmerica/Port_of_Spain-04:00-04:00
HTAmerica/Port-au-Prince-05:00-04:00
America/Porto_Acre-05:00-05:00
BRAmerica/Porto_Velho-04:00-04:00
PRAmerica/Puerto_Rico-04:00-04:00
CLAmerica/Punta_Arenas-03:00-03:00
CAAmerica/Rainy_River-06:00-05:00
CAAmerica/Rankin_Inlet-06:00-05:00
BRAmerica/Recife-03:00-03:00
CAAmerica/Regina-06:00-06:00
CAAmerica/Resolute-06:00-05:00
BRAmerica/Rio_Branco-05:00-05:00
America/Rosario-03:00-03:00
America/Santa_Isabel-08:00-07:00
BRAmerica/Santarem-03:00-03:00
CLAmerica/Santiago-04:00-03:00
DOAmerica/Santo_Domingo-04:00-04:00
BRAmerica/Sao_Paulo-03:00-03:00
GLAmerica/Scoresbysund-01:00+00:00
America/Shiprock-07:00-06:00
USAmerica/Sitka-09:00-08:00
BLAmerica/St_Barthelemy-04:00-04:00
CAAmerica/St_Johns-03:30-02:30
KNAmerica/St_Kitts-04:00-04:00
LCAmerica/St_Lucia-04:00-04:00
VIAmerica/St_Thomas-04:00-04:00
VCAmerica/St_Vincent-04:00-04:00
CAAmerica/Swift_Current-06:00-06:00
HNAmerica/Tegucigalpa-06:00-06:00
GLAmerica/Thule-04:00-03:00
CAAmerica/Thunder_Bay-05:00-04:00
MXAmerica/Tijuana-08:00-07:00
CAAmerica/Toronto-05:00-04:00
VGAmerica/Tortola-04:00-04:00
CAAmerica/Vancouver-08:00-07:00
America/Virgin-04:00-04:00
CAAmerica/Whitehorse-08:00-07:00
CAAmerica/Winnipeg-06:00-05:00
USAmerica/Yakutat-09:00-08:00
CAAmerica/Yellowknife-07:00-06:00
AQAntarctica/Casey+11:00+11:00
AQAntarctica/Davis+07:00+07:00
AQAntarctica/DumontDUrville+10:00+10:00
AUAntarctica/Macquarie+11:00+11:00
AQAntarctica/Mawson+05:00+05:00
AQAntarctica/McMurdo+12:00+13:00
AQAntarctica/Palmer-03:00-03:00
AQAntarctica/Rothera-03:00-03:00
Antarctica/South_Pole+12:00+13:00
AQAntarctica/Syowa+03:00+03:00
AQAntarctica/Troll+00:00+02:00
AQAntarctica/Vostok+06:00+06:00
SJArctic/Longyearbyen+01:00+02:00
YEAsia/Aden+03:00+03:00
KZAsia/Almaty+06:00+06:00
JOAsia/Amman+02:00+03:00
RUAsia/Anadyr+12:00+12:00
KZAsia/Aqtau+05:00+05:00
KZAsia/Aqtobe+05:00+05:00
TMAsia/Ashgabat+05:00+05:00
Asia/Ashkhabad+05:00+05:00
KZAsia/Atyrau+05:00+05:00
IQAsia/Baghdad+03:00+03:00
BHAsia/Bahrain+03:00+03:00
AZAsia/Baku+04:00+04:00
THAsia/Bangkok+07:00+07:00
RUAsia/Barnaul+07:00+07:00
LBAsia/Beirut+02:00+03:00
KGAsia/Bishkek+06:00+06:00
BNAsia/Brunei+08:00+08:00
Asia/Calcutta+05:30+05:30
RUAsia/Chita+09:00+09:00
MNAsia/Choibalsan+08:00+08:00
Asia/Chongqing+08:00+08:00
Asia/Chungking+08:00+08:00
LKAsia/Colombo+05:30+05:30
Asia/Dacca+06:00+06:00
SYAsia/Damascus+02:00+03:00
BDAsia/Dhaka+06:00+06:00
TLAsia/Dili+09:00+09:00
AEAsia/Dubai+04:00+04:00
TJAsia/Dushanbe+05:00+05:00
CYAsia/Famagusta+02:00+02:00
PSAsia/Gaza+02:00+03:00
Asia/Harbin+08:00+08:00
PSAsia/Hebron+02:00+03:00
VNAsia/Ho_Chi_Minh+07:00+07:00
HKAsia/Hong_Kong+08:00+08:00
MNAsia/Hovd+07:00+07:00
RUAsia/Irkutsk+08:00+08:00
Asia/Istanbul+03:00+03:00
IDAsia/Jakarta+07:00+07:00
IDAsia/Jayapura+09:00+09:00
ILAsia/Jerusalem+02:00+03:00
AFAsia/Kabul+04:30+04:30
RUAsia/Kamchatka+12:00+12:00
PKAsia/Karachi+05:00+05:00
Asia/Kashgar+06:00+06:00
NPAsia/Kathmandu+05:45+05:45
Asia/Katmandu+05:45+05:45
RUAsia/Khandyga+09:00+09:00
INAsia/Kolkata+05:30+05:30
RUAsia/Krasnoyarsk+07:00+07:00
MYAsia/Kuala_Lumpur+08:00+08:00
MYAsia/Kuching+08:00+08:00
KWAsia/Kuwait+03:00+03:00
Asia/Macao+08:00+08:00
MOAsia/Macau+08:00+08:00
RUAsia/Magadan+11:00+11:00
IDAsia/Makassar+08:00+08:00
PHAsia/Manila+08:00+08:00
OMAsia/Muscat+04:00+04:00
RUAsia/Novokuznetsk+07:00+07:00
RUAsia/Novosibirsk+07:00+07:00
RUAsia/Omsk+06:00+06:00
KZAsia/Oral+05:00+05:00
KHAsia/Phnom_Penh+07:00+07:00
IDAsia/Pontianak+07:00+07:00
KPAsia/Pyongyang+09:00+09:00
QAAsia/Qatar+03:00+03:00
KZAsia/Qyzylorda+05:00+05:00
MMAsia/Rangoon+06:30+06:30
SAAsia/Riyadh+03:00+03:00
Asia/Saigon+07:00+07:00
RUAsia/Sakhalin+11:00+11:00
UZAsia/Samarkand+05:00+05:00
KRAsia/Seoul+09:00+09:00
CNAsia/Shanghai+08:00+08:00
SGAsia/Singapore+08:00+08:00
RUAsia/Srednekolymsk+11:00+11:00
TWAsia/Taipei+08:00+08:00
UZAsia/Tashkent+05:00+05:00
GEAsia/Tbilisi+04:00+04:00
IRAsia/Tehran+03:30+04:30
Asia/Tel_Aviv+02:00+03:00
Asia/Thimbu+06:00+06:00
BTAsia/Thimphu+06:00+06:00
JPAsia/Tokyo+09:00+09:00
RUAsia/Tomsk+07:00+07:00
Asia/Ujung_Pandang+08:00+08:00
MNAsia/Ulaanbaatar+08:00+08:00
Asia/Ulan_Bator+08:00+08:00
CNAsia/Urumqi+06:00+06:00
RUAsia/Ust-Nera+10:00+10:00
LAAsia/Vientiane+07:00+07:00
RUAsia/Vladivostok+10:00+10:00
RUAsia/Yakutsk+09:00+09:00
MMAsia/Yangon+06:30+06:30
RUAsia/Yekaterinburg+05:00+05:00
AMAsia/Yerevan+04:00+04:00
PTAtlantic/Azores-01:00+00:00
BMAtlantic/Bermuda-04:00-03:00
ESAtlantic/Canary+00:00+01:00
CVAtlantic/Cape_Verde-01:00-01:00
Atlantic/Faeroe+00:00+01:00
FOAtlantic/Faroe+00:00+01:00
Atlantic/Jan_Mayen+01:00+02:00
PTAtlantic/Madeira+00:00+01:00
ISAtlantic/Reykjavik+00:00+00:00
GSAtlantic/South_Georgia-02:00-02:00
SHAtlantic/St_Helena+00:00+00:00
FKAtlantic/Stanley-03:00-03:00
AUAustralia/Adelaide+09:30+10:30
AUAustralia/Brisbane+10:00+10:00
AUAustralia/Broken_Hill+09:30+10:30
Australia/Canberra+10:00+11:00
AUAustralia/Currie+10:00+11:00
AUAustralia/Darwin+09:30+09:30
AUAustralia/Eucla+08:45+08:45
AUAustralia/Hobart+10:00+11:00
AUAustralia/Lindeman+10:00+10:00
AUAustralia/Lord_Howe+10:30+11:00
AUAustralia/Melbourne+10:00+11:00
AUAustralia/Perth+08:00+08:00
AUAustralia/Sydney+10:00+11:00
apache logo
Apache Web Server Logo

Resources:
putenv function
date_default_timezone_set function

Leave a Reply