MySQL 4, Apache 1.3 and PHP 4.3 on Solaris x86

Yesterday I decided it was time to get a proper PHP 4 environment configured on my new machine running the x86 version of Solaris 9. I know going outside Windows or Linux with PHP sometimes can be tricky. I haven’t used PHP on Solaris since my time at AOL in Dublin three years ago, so I decided to write down exactly how, what and why I did things. I expected it to be a bit simpler then last time as I planned to use Apache rather than IPlanet (or whatever the name is today, it seems to change at least once a week). So my plan was to install a pretty standard LAMP environment. That is without the L ofcourse.

Preparations

The first thing I had to do was to download the different GNU packages needed to compile MySQL, PHP and many other open source projects on Solaris. These packages can all be found on Sunfreeware.com. The packages I installed, by default under /usr/local,  were:

  • gcc
  • gmake
  • flex
  • bison
  • m4
  • autoconf
  • automake
  • gzip
  • tar
  • GNU sed
  • libiconv

All packages are easy to install using pkgadd. Care needs to be taken to set the system paths correctly after the installation. I used the command crle -u -l /usr/local/lib to add the lib directory to the system defaults. Then I added /usr/local/bin first in my PATH to make sure GNU versions take precedence if there are any conflicts. For example the package m4 could be found on the system already. I also appended /usr/ccs/bin last to the PATH as there are programs there needed for compilation and linking.

MySQL

Having the environment setup as I wanted it I set my eyes on installing MySQL. I couldn’t find an official binary package for Solaris 9 x86 so I had to build it myself. I downloaded the source from mysql.com, quickly unpacked it and failed miserably at compiling it.

A quick research using Google gave me the answer. The command mkheaders refused due to paths not being found. So additionally I had to create a softlink as the paths for some reason differed. After creating the symlink I could generate the gcc header files. The exact commands issued are as below.

# ln -s /usr/local/lib/gcc /usr/local/lib/gcc-lib
# cd /usr/local/libexec/gcc/i386-pc-solaris2.9/\
  3.4.1/install-tools
# ./mkheaders

Then I tried compiling MySQL again. This time, everything could be done by the book. For sake of convenience – here’s a near copy from the MySQL manual.

# ./configure --prefix=/usr/local/mysql
# make && make install
# cp support-files/my-medium.cnf /etc/my.cnf
# cd /usr/local/mysql
# groupadd mysql
# useradd -g mysql mysql
# chown -R root .
# chown -R mysql var
# chgrp -R mysql .

The only thing left then is to start the MySQL daemon and set the root password.

# bin/mysqld_safe --user=mysql
# bin/mysqladmin -u root password XXXXXX
# bin/mysqladmin -u root -h myhost password XXXXXX

Installing gd

I need gd for, among other things, thumbnail generation. As I wanted to download and compile as little as possible a quick check revealed that freetype, libjpeg, libpng and libiconv already existed in my default Solaris 9 installation. The libraries can be found under the /usr/sfw directory.

I wanted the newest version of gd as GIF support is now added again after being removed for several years due to Unisys suddenly starting do demand licensing fees for their LZW patent a few years ago. So I could not use the slightly older gd available as a package at sunfreeware.

I downloaded version 2.0.28 and tried to compile it. However, I could not get it to compile using the libiconv already installed. Instead I had to download libiconv from sunfreeware and install it under /usr/local. The following configure command was what I ended up with to get gd to compile.

# ./configure \
  --prefix=/usr/local \
  --with-freetype=/usr/sfw \
  --with-png=/usr/sfw \
  --with-jpeg=/usr/sfw \
  --with-libiconv-prefix=/usr/local

After that compiling the package was a breeze.

# make && make install

On to apache

Apache must be the easiest application around to build on different platforms. I have never experienced any problems building a stable apache release on any unix platform. I did once have problems getting it to run on NT 4 when the windows version still was marked unstable. I guess that could be expected though. So creating a standard build of apache is very straight forward.

# ./configure --prefix=/usr/local/apache-1.3.31 \
  --enable-module=so
# make && make install

PHP – finally

Compiling PHP became, as it turned out, a bit tricky becaused of my decision to enable gd support. The reason was that the PHP configure script didn’t list libiconv when checking that all the gd functions were correct. The configure script just said “no” to all the gd functions and refused to create the makefiles. After awhile I looked through the generated config.log. This revealed that what really failed was not actually gd. When loading gd to check what functions were available it failed to find symbols from libiconv. This must either be a bug in the configure script or more probable a problem with my Solaris 9 environment and the library paths.

So prior to running the configure script I had to manually amend the configure script and add -liconv in all places where -lgd could be found. That did the trick and the script happily trotted along as it should.

# ./configure \
  --with-apxs=/usr/local/apache-1.3.31/bin/apxs \
  --with-mysql=/usr/local/mysql/ \
  --with-gd=/usr/local \
  --with-freetype-dir=/usr/sfw \
  --enable-gd-native-ttf \
  --with-png-dir=/usr/sfw \
  --with-zlib-dir=/usr/sfw \
  --with-jpeg-dir=/usr/sfw
# make && make install

After that I added the directives needed in httpd.conf to enable PHP4. Actually I only had to add the second line below as the LoadModule directive was already present.

LoadModule php4_module libexec/libphp4.so
AddType application/x-httpd-php .php

And finally, at 03:43 AM, I could verify the installation and configuration using the simple php script with a call to phpinfo(). Of course it worked like a charm.

All that remains now is to get Apache 2 and PHP 5 up and running alongside. I still haven’t figured out if the good PHP folks recommend Apache 2 for production yet. Anyways,
that’ll be a project for another night.

PHP

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Leave Comment

(required)

(required)