How to set the timezone for PHP in the php.ini file
By default, Zalvis servers are configured to use the Coordinated Universal Time (UTC). You can change the time zone that PHP uses for your scripts by setting the date.timezone directive in your php.ini file.
PHP relies on the date.timezone value for some date/time functions executed by PHP-based applications. Sometimes an error message also appears in the web server logs, which clearly indicates this necessity. Fortunately, this can easily be resolved by adding a line of code in your php.ini in the cPanel of your hosting account. After adding the code the time will be displayed according to the time zone entered in the php.ini file.
You can easily set the time zone code in your php.ini file by following the steps below:
- Login to your cPanel.
- Scroll down to the Files section, then click on the File Manager menu.
- On the left side panel, a list of directories of your hosting account is displayed. Here you need to click on the public_html folder.
- In the public_html folder, you need to navigate to file public_html -> php.ini file. If you do not have the php.ini file yet, click the +File button at the top of the page, type php.ini and click Create New File to save.
- Right-click on the php.ini file, then click on the Edit button.
- Now you need to insert the line of code below at the top of your php.ini file:
date.timezone = “Place/Your_town”
Note: Change Place/Your_town with your own time zone as per your requirement.
date.timezone = “Europe/London”
- After entering the above line, click on the Save Changes button.
Now, you can check your phpinfo.php page to verify that the change has occurred.