0

I am trying to get ldap_connect to work properly. It will work fine via CLI, but not when I open my php file via browser.

Here is what I believe are the relevant details:

  • Error message: Fatal error: Call to undefined function ldap_connect() in F:\Websites\ldap.php on line 4
  • OS: Windows Server 2008 R2 x64
  • PHP Directory: C:\Program Files (x86)\PHP
  • libeay32.dll and ssleay32.dll have been added to both C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin and C:\Windows\System32. They were copied from C:\Program Files (x86)\PHP.

Lines added to httpd.conf:

  • LoadModule php5_module "C:/Program Files (x86)/PHP/php5apache2_2.dll"
  • AddType application/x-httpd-php .php
  • PHPIniDir "C:/Program Files (x86)/PHP"

Things changed in php.ini:

  • extension_dir = "C:/Program Files (x86)/PHP/ext" (path set)
  • extension=php_ldap.dll (uncommented this line)

I'm pulling my hair out, so I am more than happy to try anything people suggest.

  • Have you tried restarting the server to reload the php.ini? Also is your apache server using the same php as the the cli? – Tim Withers Jan 04 '12 at 00:30
  • I have restarted the server. Is there a way to check? I only have one install of PHP on here. –  Jan 04 '12 at 00:32
  • It appears as though when I run php_info in a file via CLI (and output that to a file), it's different than when I pull it up in a browser. –  Jan 04 '12 at 00:34
  • I don't have a clue then. You running XAMPP? – Tim Withers Jan 04 '12 at 00:37
  • I am not. This is a clean install of PHP and Apache on a fresh load of Windows. –  Jan 04 '12 at 16:47

2 Answers2

1

Your PHP installation uses two different ini files - one when running from the command line, and a different one when running through Apache. This is evidenced by the fact that it works from the CLI, but not in a browser.

You can find the paths to the two files using phpinfo() (in a browser) and by passing the -i flag to php from the command line. Near the top of both sets of output you will find the path to the ini file in use, and I would be mighty surprised if they were identical. From the command line you can get more detailed information by passing the --ini flag.

The fact that you are getting Call to undefined function ldap_connect() can only mean that the LDAP extension was not loaded, and this can only be true through Apache but not through the CLI if they use two different ini files.

DaveRandom
  • 87,921
  • 11
  • 154
  • 174
  • Sorry for the delay. I posted this late in the day at work and forgot to check it when I got home. Output from running php via cli with the -i flag shows this as the path: Loaded Configuration File => C:\Program Files (x86)\PHP\php.ini php_info() shows this as the path: Loaded Configuration File C:\Program Files (x86)\PHP\php.ini Am I crazy or are those the same thing? –  Jan 04 '12 at 16:45
0

I feel silly now. The problem was with adding my PHP directory to the PATH environment variable. I'm not 100% sure why it fixed the problem, but that was what ended up doing it. Thanks for the help, guys!