Did you know that the default timezone for PHP is UTC, irrespective of your server’s timezone? This default setting is used by all PHP date and time functions in all your scripts. If you notice that the time in your PHP scripts is incorrect, it is because your hosting server is in a different timezone. You can rectify this situation by changing the PHP India timezone for an app by creating a user.ini file in the app’s public directory with the following contents:
Date.timezone = Asia/India
You can check the PHP’s list of supported timezones to find the names of all possible options.
Steps to change Timezone in PHP
To change the set timezone option in PHP, you need to insert a line of code into your php.ini.file. The location that you set in the code will determine the time displayed in your PHP scripts.
- Log in to your Bluehost account
- Go to the cPanel
If you have a Bluerock account:
- Go to the Advanced tab, click on the Files section and select Files Manager
- Open the public_html folder
- Go to the folder that contains the .htaccess file and click on the Edit button Or you can right click on the selected files and click on Edit from the drop-down menu
- Press Ctrl+F to find the section and enter the <IfModule lsapi_module>
- Add this line php-value date.timezone. “America/Denver”
Replace the timezone with the one that corresponds to the one you wish to display. Do not forget to save the changes made.
If you have a Legacy account,
- Log into your Bluehost cPanel
- Locate the File Manager under the Files category
- Choose to open Web Root and Show hidden files, then click the submit button
- Go to the folder containing the PHP.INI file
- Press Ctrl+F (Shortcut to find section easily) and enter the <IfModule lsapi_module>
- Add this line php_value date.timezone “America/Denver”
- Change the location as per the timezone you wish to use
- Once done, click the Save Changes button towards the top right side of your screen
Now that you have changed the timezone in PHP, you can check the same by going to the phpinfo.php page.