skip to Main Content

I am running a web server in amazon aws and its running centos and has cpanel and whm installed (latest). The php scripts are running okay. However when I display date and time in php code I see incorrect time. The timezone for the server is correctly set (incl. date & time) but its incorrect in php ini setting.

PHP info shows loaded configuration file as /opt/cpanel/ea-php56/root/etc/php.ini. However when I edit this from whm the comment says “cPanel-generated php ini directives, do not edit” & “To make changes to this file, use the cPanel MultiPHP INI Editor”.

In cpanel multi php ini editor the system says “ini content does not exist. You may add new content.” So what to do ? If I set time zone setting in there then will system just read that setting from here or entire setting from here or what. Please help me as I am not familiar with linux environment.

2

Answers


  1. Use date_default_timezone_set function like so:

    <code>
    <?php 
    $tz = "Europe/Warsaw";
    date_default_timezone_set($tz);
    </code>
    

    you can use for time zone any valid tz, such as:
    $tz = “Europe/London”;
    $tz = “Europe/Prague”;
    $tz = “Asia/Jerusalem”;
    etc.

    Login or Signup to reply.
  2. You can add this code to the begining of php.ini.

    date.timezone = "US/Central"
    

    After adding the above code. You can check if the change happened using the
    phpinfo(). If you set the server time then all the projects under that server will have that time zone unless you change it inside the project.

    If you don’t have access to the php.ini in server you can do the edit by using the php function.

    date_default_timezone_set('US/Central');
    

    This will change the time zone to US/Central.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search