Skip to content

Setting the PHP time zone in an .htaccess file

The date.timezone directive in PHP defines the default time zone used by all date and time functions. By default, servers may use UTC or another system time zone. On ruachost.com, you can override this setting using a custom .htaccess file when you don’t have direct access to php.ini.

  • Ensure timestamps in logs, databases, and applications match your local region.

  • Prevent errors or warnings such as:

    Warning: It is not safe to rely on the system's timezone settings.
  • Provide consistent date/time handling across your applications.

Steps to Configure date.timezone in .htaccess

Section titled “Steps to Configure date.timezone in .htaccess”
  • Log in to cPanel or use FTP/File Manager.
  • Navigate to your site’s root directory (e.g., /public_html).
  1. If .htaccess already exists, open it for editing.
  2. If not, create a new file named .htaccess.

Insert the following line:

php_value date.timezone Africa/Lagos
  • Replace Africa/Lagos with your desired time zone.

  • Examples:

    • Europe/Paris
    • America/New_York
    • Asia/Tokyo
    • Africa/Nairobi
  1. Save the .htaccess file.

  2. Create a test file info.php with:

    <?php phpinfo(); ?>
  3. Load it in your browser and search for date.timezone.

  4. Confirm the new value is active.

  5. Delete the test file afterward for security.

  • Always set date.timezone explicitly to avoid relying on server defaults.
  • Use region‑based identifiers (e.g., Africa/Lagos) instead of generic ones (GMT, UTC).
  • Test applications after changing the time zone to ensure date/time functions behave correctly.