PHP 5.3, iconv, OSX, Symbols Missing _libiconv

14/07/2009

I'm not sure how many people will have this problem, but I did so this will remind me.

PHP 5.3 release, for some reason, does not like my default install of iconv. Firstly, I made the grave mistake of failing to point PHP properly at an install in /usr/local/, so replaced my OS installation of iconv with a new one. This was all well and good until I started opening apps that needed specific parts of OSX's default iconv. So, an OSX restore later, we're at square one. PHP keeps telling me various crap when I'm trying to compile that it didn't work with iconv because it's the wrong version, but would fail during make because it couldn't find the correct symbols. <!--more--> I had compiled and installed iconv (./configure --prefix=/usr/local/iconv --enable-static) then pointed PHP at that (--with-iconv=/usr/local/iconv) and it was failing during make with Undefined Symbols: "_libiconv" then some stack trace of php string functions. Great. After much Googling and cobbling together my own way to do this with trial and error and a mixture of other people's part-baked solutions, I have come up with the following method:

  1. install iconv: ./configure --prefix=/usr/local/iconv --enable-static && make && sudo make install
  2. configure PHP with the following prefix: env LIBS="-lresolv -liconv" ./configure ......

    Mine is:

    env LIBS="-lresolv -liconv" ./configure \ --enable-pdo \ --with-apxs2=/usr/local/apache2/bin/apxs \ --with-mysql=/usr/local/mysql \ --with-pdo-mysql=/usr/local/mysql \ --prefix=/usr/local/php \ --enable-mbstring \ --with-mysql=/usr/local/mysql \ --enable-cli \ --with-curl \ --with-gd \ --with-png-dir=/usr/local/png \ --with-jpeg-dir=/usr/local/jpg \ --with-freetype-dir=/usr/local/freetype \ --with-zlib-dir=/usr/local/zlib \ --with-mcrypt=/usr/local/mcrypt \ --with-iconv=/usr/local/iconv

  3. After configure has finished running, hopefully there has been no problem. If there has I have no idea how to fix it. Normally this runs smooth as hell for me, this has taken me about 6 solid hours to fix and I can't be remotely fixing everyone else's, sorry.

    You'll need to be modifying the Makefile generated from your ./configure. Search for the following string (without quotes) "libs/libphp$" and replace that and the next line with the following:

    libs/libphp$(PHP_MAJOR_VERSION).bundle: $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS) $(CC) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) $(PHP_GLOBAL_OBJS:.lo=.o) $(PHP_SAPI_OBJS:.lo=.o) $(PHP_FRAMEWORKS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) $(MH_BUNDLE_FLAGS) -o $@ && cp $@ libs/libphp$(PHP_MAJOR_VERSION).so

  4. make
  5. You can run make test if you want, but it'll fail everything it doesn't skip
  6. sudo make install
  7. Restart apache
  8. Everything should work fine now. If it didn't, I'm sorry - I don't know why. If it does, hoorah! You just saved yourself 6 hours. You owe me a beer!

Again, I must reiterate, if this doesn't work for you I probably won't be able to fix this or even help you slightly. This is just what worked for me. There are plenty of things you can try with a bit of Google-fu, though.