Check php.ini for syntax errors

In the middle of setting-up a new webserver on a Windows Server 2008 machine using IIS7 and PHP 5.4 I ran into a problem that had me stumped for a short time. Though not something that is done frequently setting-up PHP on a Windows server is something that I am well-versed in doing. I know of the most common stumbling blocks and how to get around them – especially on Windows machines.

A common issue for those new to PHP is the php.ini file. Most problems can be attributed to editing the wrong one (albeit a more common problem years ago). This morning I was editing the php.ini on my new server using my normal routine: copy the supplied production version, open the php.ini file on my existing server, and making the new version match as close as possible. The only problem was it appeared the PHP was ignoring the timezone setting in the PHP.

Warning: phpinfo(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone ‘UTC’ for now, but please set date.timezone to select your timezone. in C:\Websites\AP-WWW\pinfo.php on line 2

I was willing to ignore this warning for the time being but, I was also experiencing a problem with MySQL. I was getting the following error: Fatal error: Call to undefined function mysql_connect(). I checked the usual cause – the location of the php.ini file and made sure I was editing the correct file:

I checked the file permissions, folder permissions, rebooted the server, etc. No matter what I did I kept getting the warning that PHP was assuming UTC for the timezone and displayed the lack of a setting for date.timezone in the php.ini file:

The most common cause I could find was to a misspelling of the timezone or using quotes on the line in the php.ini file. This seemed unlikely since I had copied-and-pasted the value from’s website and from the php.ini file from my current PHP server.

Fortunately, the source of my frustration was easily identified when I went to compare the information by phpinfo() in a browser to the information displayed in the PHP CLI. From a DOS command window I ran the command php -i which displayed the following error:

When I looked at line 810 of the php.ini file I immediately saw the problem on line 809:

Fixing the error on line 809 and restarting IIS allowed PHP to recognize the timezone setting and eliminated the error connecting to MySQL:


2 Responses to Check php.ini for syntax errors

  1. eugensechel says:

    You just saved me a lot of frustration and time. Thank you!

  2. imboduet says:

    i had my php.ini checked using: php -v

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: