{"id":584,"date":"2017-03-15T00:00:00","date_gmt":"2017-03-15T00:00:00","guid":{"rendered":"http:\/\/blog.hostinger.io\/hostinger-tutorials\/uncategorized\/htaccesshow-to-change-timezone-using-htaccess\/"},"modified":"2026-03-09T19:20:09","modified_gmt":"2026-03-09T19:20:09","slug":"php-set-timezone","status":"publish","type":"post","link":"\/ng\/tutorials\/php-set-timezone","title":{"rendered":"How to set PHP timezone using PHP function, .htaccess, and php.ini files"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>PHP defaults to Coordinated Universal Time (UTC) regardless of your server&rsquo;s timezone. Configuring the PHP timezone accurately is crucial for precise data management and time-sensitive operations like logging and scheduling.<\/p><p>This practice is especially vital for web applications with global audiences outside the UTC timezone. For instance, it makes handling daylight saving time easier.<\/p><p>You can change your website&rsquo;s PHP timezone settings using the <strong>PHP function<\/strong> or by modifying the <strong>.htaccess<\/strong> or <strong>php.ini files<\/strong>. This article will explore each method so that you can choose the most suitable one for your needs.<\/p><figure class=\"wp-block-image size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/How-to-Speed-Up-Your-Website-EN.pdf\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/public\" alt=\"\" class=\"wp-image-69260\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=2048,fit=scale-down 2048w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure><p>\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-set-php-timezone-using-a-php-function\">How to Set PHP Timezone Using a PHP Function<\/h2><p>The <strong>date_default_timezone_set()<\/strong> function sets a script&rsquo;s default timezone for all date and time functions. It ensures accurate handling of time-related data in PHP web applications, even if your web hosting server is in a different timezone than you or your target audience.<\/p><p>The <a href=\"https:\/\/www.php.net\/manual\/en\/timezones.php\">list of supported timezones<\/a> is available on PHP&rsquo;s official website. Double-check using the <a href=\"https:\/\/www.timeanddate.com\/time\/zones\/\">timezone abbreviation list<\/a> to ensure you select the correct timezone.<\/p><p>Here&rsquo;s an example of how to use the <strong>date_default_timezone_set()<\/strong> function:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\ndate_default_timezone_set('America\/New_York');\n?&gt;<\/pre><p>If you&rsquo;re working on a standalone PHP script or a simple project, place the function at the top of your file before any timezone-related PHP functions are called. However, setting the timezone in the configuration or <a href=\"\/ng\/tutorials\/what-is-bootstrap\/\">bootstrap<\/a> file is best for larger projects.<\/p><p>You can <a href=\"https:\/\/support.hostinger.com\/en\/articles\/3313359-where-to-find-your-website-s-configuration-file\">find your website&rsquo;s configuration file<\/a> in the root directory called <strong>public_html<\/strong>. While the file name varies depending on the CMS used, it&rsquo;s usually named <strong>config.php<\/strong>.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-change-php-date-timezone-with-the-htaccess-file\">How to Change PHP date.timezone With the .htaccess File<\/h2><p>Changing the PHP <strong>date.timezone<\/strong> setting using the <strong>.htaccess<\/strong> file is often done in shared hosting environments where the <strong>php.ini<\/strong> file is inaccessible. The <strong>.htaccess<\/strong> file lets you override server configurations for specific directories, including the timezone setting.<\/p><p>The <strong>.htaccess<\/strong> file is accessible using a file manager, an FTP client, and SSH. Using the hosting account&rsquo;s file manager should be the easiest method for beginners.<\/p><h3 class=\"wp-block-heading\">How to Change PHP date.timezone Using File Manager<\/h3><p>Here&rsquo;s how to change your website&rsquo;s default timezone in the <strong>.htaccess<\/strong> file using <a href=\"\/ng\/tutorials\/how-to-use-hostinger-file-manager\/\">Hostinger&rsquo;s File Manager<\/a>:<\/p><ol class=\"wp-block-list\">\n<li>Navigate to <strong>Files<\/strong> &rarr; <strong>File Manager<\/strong> from <a href=\"\/ng\/support\/1583483-comprehensive-guide-to-hpanel-at-hostinger\/\">hPanel<\/a>.<\/li>\n\n\n\n<li>Select <strong>Access files of [your website]<\/strong> to browse directories on that specific site.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1428\" height=\"250\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager.png\/public\" alt=\"Accessing files of a specific website in hPanel using File Manager\" class=\"wp-image-100498\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager.png\/w=1428,fit=scale-down 1428w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1428px) 100vw, 1428px\" \/><\/a><\/figure><\/div><ol start=\"3\" class=\"wp-block-list\">\n<li>Access the <strong>public_html<\/strong> directory and double-click the <strong>.htaccess<\/strong> file to edit. <a href=\"\/ng\/tutorials\/locate-and-create-htaccess\">Create a new .htaccess file<\/a> if it&rsquo;s not already present.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager-htaccess.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"340\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager-htaccess.png\/public\" alt=\"Hostinger File Manager highlighting the .htaccess file in the public_html folder\" class=\"wp-image-100499\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager-htaccess.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager-htaccess.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager-htaccess.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager-htaccess.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><ol start=\"4\" class=\"wp-block-list\">\n<li>Enter the following script at the very top of the file. In this example, we&rsquo;re setting the timezone to Central Standard Time (CST) using <strong>America\/Chicago<\/strong> as the parameter. Browse the timezone list to verify whether PHP supports your desired timezone.<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">php_value date.timezone 'country\/state'<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager-htaccess-syntax.png\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"191\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager-htaccess-syntax.png\/public\" alt=\"Adding the PHP set timezone code in the .htaccess file\" class=\"wp-image-100500\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager-htaccess-syntax.png\/w=533,fit=scale-down 533w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager-htaccess-syntax.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-file-manager-htaccess-syntax.png\/w=150,fit=scale-down 150w\" sizes=\"auto, (max-width: 533px) 100vw, 533px\" \/><\/a><\/figure><\/div><ol start=\"5\" class=\"wp-block-list\">\n<li>Hit <strong>Save <\/strong>once you&rsquo;re done.<\/li>\n<\/ol><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-full\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-web-hosting\" href=\"\/ng\/web-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/public\" alt=\"Hostinger web hosting banner\" class=\"wp-image-98604\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h3 class=\"wp-block-heading\">How to Change PHP date.timezone Using an FTP Client<\/h3><p>You can also modify the PHP timezone setting by editing the <strong>.htaccess<\/strong> file with an FTP client, such as FileZilla. Hostinger users can find their FTP details in <strong>Files <\/strong>&rarr; <strong>FTP Accounts<\/strong> on hPanel.<\/p><p>Here&rsquo;s how to modify the PHP default timezone in the <strong>.htaccess<\/strong> file using the FileZilla FTP client:<\/p><ol class=\"wp-block-list\">\n<li><a href=\"\/ng\/tutorials\/ftp\/filezilla-ftp-configuration\">Configure FileZilla<\/a> and connect to the FTP web server.<\/li>\n\n\n\n<li>Locate the <strong>.htaccess<\/strong> file in the <strong>public_html<\/strong> directory. Right-click on it and select <strong>View\/Edit<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/12\/ftp-htaccess-edit.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1166\" height=\"651\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/ftp-htaccess-edit.png\/public\" alt=\"Editing the .htaccess file in FileZilla\" class=\"wp-image-100501\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/ftp-htaccess-edit.png\/w=1166,fit=scale-down 1166w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/ftp-htaccess-edit.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/ftp-htaccess-edit.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/ftp-htaccess-edit.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/ftp-htaccess-edit.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1166px) 100vw, 1166px\" \/><\/a><\/figure><\/div><ol start=\"3\" class=\"wp-block-list\">\n<li>Set the timezone by entering the following script at the very top of the scripts. Don&rsquo;t forget to change the <strong>date.timezone<\/strong> value with your preferred location.<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">php_value date.timezone 'country\/state'<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Check the <strong>Finish editing and delete local file <\/strong>option before saving the changes.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/12\/ftp-htaccess-save-changes.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1172\" height=\"522\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/ftp-htaccess-save-changes.png\/public\" alt=\"Saving changes after modifying the .htaccess file, with the option to delete local file highlighted\" class=\"wp-image-100502\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/ftp-htaccess-save-changes.png\/w=1172,fit=scale-down 1172w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/ftp-htaccess-save-changes.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/ftp-htaccess-save-changes.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/ftp-htaccess-save-changes.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/ftp-htaccess-save-changes.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1172px) 100vw, 1172px\" \/><\/a><\/figure><\/div><h3 class=\"wp-block-heading\">How to Change PHP date.timezone Using SSH<\/h3><p><a href=\"\/ng\/tutorials\/ssh-tutorial-how-does-ssh-work\">Secure Shell Protocol (SSH)<\/a> is a remote administration protocol that provides direct access and control over server files. It ensures secure data transmission across remote servers from the terminal window, making it a popular choice for experienced command-line users.<\/p><p>In this tutorial, we&rsquo;re using <a href=\"https:\/\/www.putty.org\/\">PuTTY<\/a>, a popular SSH client. Check out our article on <a href=\"\/ng\/tutorials\/how-to-use-putty-ssh\">how to use the PuTTY SSH client<\/a> to access your server.<\/p><p>Follow these steps to change the <strong>date.timezone<\/strong> value with the PuTTY SSH client:<\/p><ol class=\"wp-block-list\">\n<li>Establish an SSH connection. Hostinger users can find their SSH details in <strong>Advanced <\/strong>&rarr; <strong>SSH Access<\/strong> on hPanel.<\/li>\n\n\n\n<li>Enter the following command to check your server&rsquo;s timezone.<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">php -i | grep \"date.timezone\"<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Use this command to see all the available time zones. Take note of the one you want to use.<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">timedatectl list-timezones<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Input this command to set the timezone. Replace the timezone identifier based on your preference in Step 3.<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">timedatectl set-timezone [region\/location]<\/pre><p>If you encounter an error during the configuration process, try these solutions:<\/p><ul class=\"wp-block-list\">\n<li><strong>Gain root privileges<\/strong> &#8210; as modifying system settings requires root permissions, try adding <strong>sudo <\/strong>before the <strong>timedatectl <\/strong>command. <strong>sudo <\/strong>grants temporary root permissions for executing the command.<\/li>\n\n\n\n<li><strong>Check the PATH environment variable<\/strong> &#8210; PATH lets you run a command without specifying a path. Verify yours with <strong>echo $PATH<\/strong> and locate <strong>timedatectl <\/strong>with <strong>find \/ -name timedatectl 2&gt;\/dev\/null<\/strong>.<\/li>\n\n\n\n<li><strong>Check user permissions<\/strong> &#8210; some <a href=\"\/ng\/tutorials\/ssh\/basic-ssh-commands\">SSH commands<\/a> are restricted for non-root users, causing an access error.<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-how-to-set-php-timezone-using-the-php-ini-file\">How to Set PHP Timezone Using the php.ini File<\/h2><p>Setting the desired timezone in PHP scripts using the <a href=\"\/ng\/tutorials\/what-is-php-ini\/\">php.ini<\/a> file is best for a global implementation across the site. This method ensures server-level consistency, which is crucial for server-side operations like <a href=\"\/ng\/tutorials\/cron-job\">cron jobs<\/a>.<\/p><p>Eliminating repeated timezone settings in scripts also streamlines your PHP configuration, making your code cleaner and more efficient.<\/p><p>Follow these steps to set a new timezone in PHP using the <strong>php.ini<\/strong> file. We&rsquo;re using Hostinger&rsquo;s File Manager, but feel free to use an FTP client if that&rsquo;s your preference.<\/p><ol class=\"wp-block-list\">\n<li>Access the <strong>public_html<\/strong> directory and locate the <strong>php.ini<\/strong> file. If you don&rsquo;t have it yet, click <strong>New File<\/strong> and name it <strong>php.ini<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-php-ini-new.png\"><img loading=\"lazy\" decoding=\"async\" width=\"359\" height=\"217\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-php-ini-new.png\/public\" alt=\"Creating a new php.ini file in the root directory using a file manager\" class=\"wp-image-100504\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-php-ini-new.png\/w=359,fit=scale-down 359w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-php-ini-new.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-php-ini-new.png\/w=150,fit=scale-down 150w\" sizes=\"auto, (max-width: 359px) 100vw, 359px\" \/><\/a><\/figure><\/div><ol start=\"2\" class=\"wp-block-list\">\n<li>Add the following script to the newly created file. Remember to change the timezone identifier with your preferred location.<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">date.timezone = \"country\/state\"<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-php-ini-code.png\"><img loading=\"lazy\" decoding=\"async\" width=\"313\" height=\"148\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-php-ini-code.png\/public\" alt=\"Adding the code snippet to override the default timezone in php.ini\" class=\"wp-image-100505\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-php-ini-code.png\/w=313,fit=scale-down 313w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-php-ini-code.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/12\/hpanel-php-ini-code.png\/w=150,fit=scale-down 150w\" sizes=\"auto, (max-width: 313px) 100vw, 313px\" \/><\/a><\/figure><\/div><ol start=\"3\" class=\"wp-block-list\">\n<li>Click <strong>Save <\/strong>once you&rsquo;re done.<\/li>\n\n\n\n<li>Log in to your server with an SSH client and execute this command to restart the <a href=\"\/ng\/tutorials\/what-is-apache\">Apache web server<\/a>:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">service apache2 restart<\/pre><p><div class=\"protip\">\n                    <h4 class=\"title\">Did You Know?<\/h4>\n                    <p>A <a href=\"\/ng\/tutorials\/what-is-cdn\">content delivery network<\/a> is great for websites with a global audience. It stores your website in different data centers globally and sends data from the nearest location to the visitors. This network of servers speeds up your website and keeps your main server from getting overloaded. Get Hostinger CDN for free when buying Business or any of the Cloud hosting plans.<\/p>\n                <\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Setting the correct timezone in PHP is crucial for ensuring accurate and consistent date and time handling across your web applications. It helps you maintain a seamless user experience for a global audience, meet legal standards for time-sensitive data, and ensure reliable scheduling and logging.<\/p><p>Let&rsquo;s recap three effective ways to change the timezone configuration in PHP:<\/p><ul class=\"wp-block-list\">\n<li><strong>Using a PHP function<\/strong> &#8210; ideal for applications requiring dynamic timezone changes or those working on shared servers without access to global settings.<\/li>\n\n\n\n<li><strong>Editing the .htaccess file<\/strong> &#8210; allows for directory-specific configuration in shared hosting environments.<\/li>\n\n\n\n<li><strong>Editing the php.ini file<\/strong> &#8210; lets you modify timezone settings globally across all PHP scripts, ensuring server-level consistency.<\/li>\n<\/ul><p>We hope this article helped you understand the benefits and proper implementation of setting timezones in PHP scripts. Leave a comment if you have any questions. Good luck!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP defaults to Coordinated Universal Time (UTC) regardless of your server&rsquo;s timezone. Configuring the PHP timezone accurately is crucial for precise data management and time-sensitive operations like logging and scheduling. This practice is especially vital for web applications with global audiences outside the UTC timezone. For instance, it makes handling daylight saving time easier. You [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ng\/tutorials\/php-set-timezone\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":115,"featured_media":145388,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Set PHP Timezone in 2024","rank_math_description":"Want to change the timezone of your site? Learn how to do it using a PHP function, .htaccess file, and php.ini file.","rank_math_focus_keyword":"php set timezone","footnotes":""},"categories":[22644],"tags":[],"class_list":["post-584","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/php-set-timezone","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/changer-heure-serveur-htaccess","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/como-ajustar-zona-horaria-php","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-mengganti-timezone-dengan-htaccess","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/php-set-timezone","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/php-set-timezone","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/php-set-timezone","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/como-ajustar-zona-horaria-php","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/como-ajustar-zona-horaria-php","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/como-ajustar-zona-horaria-php","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/php-set-timezone","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/php-set-timezone","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/php-set-timezone","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/php-set-timezone","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/users\/115"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/comments?post=584"}],"version-history":[{"count":29,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/584\/revisions"}],"predecessor-version":[{"id":145387,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/584\/revisions\/145387"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media\/145388"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media?parent=584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/categories?post=584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/tags?post=584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}