Pages

Wednesday, October 13, 2010

Setting up a Web Server on AIX 6.1

There have been several occasions when I have needed to set up web servers on either Windows or Linux.  Pretty much every time it has been a simple process of installing binaries through a GUI and making sure everything plays nice together.  Well, for the first time I needed to set up Apache, PHP and MySQL on an AIX machine that is completely GUI-less (Note: the GUI-less portion isn't the hard part).  In going through this process I learned a few things, so I thought that I would share them here.

Step One: Trying to find binaries for AIX
This step in itself is a little difficult.  Previously I have used Bull Freeware (http://www.bullfreeware.com/) for AIX binaries.  However, in this case, most of the binaries available are fairly outdated and I really wanted to put something together that was a little more recent.  This drove me to the discovery of PmWiki (http://www.perzl.org/aix/index.php) maintained by Michael Perzl.  This repository of RPMs built for AIX is very thorough, and very recent!  I highly recommend this site for anyone looking for binaries for AIX in general.  I quickly snatched up binaries for Apache and PHP, but no MySQL binaries were available.  Have no fear, MySQL actually maintains their own, so I was able to download them from their website (http://dev.mysql.com/downloads/mysql/).

Step Two: Trying to install the binaries
This quickly turned into a dependency hunt for both Apache and PHP, but the PmWiki site had every package that I needed, so although tiring, it was simple work.... especially since each RPM install tells you exactly which packages it's missing.  Installing MySQL was as simple as unzipping the directory to /usr/local/mysql and following a few quick steps found in the install readme included with the binaries.  At this point, Apache was up and running, PHP was configured and MySQL was up and running.  In order to get MySQL to run at system startup I copied the mysql.server script to /etc/rc.d/init.d and then created symbolic links to it under rc2.d, rc3.d and rc5.d.  (Note: If for some reason, you are following this like a tutorial, do not install the PHP binaries just yet.... you'll see why).

Step Three: Trying to get PHP to connect to a MySQL database
This is when things started going downhill a little bit.  In a quick test, I got an error in my PHP script noting that the mysqli_connect (and mysql_connect) functions were undefined... this is not a good sign.  In going through the PHP info, I discovered that the PHP binary I downloaded was not compiled with MySQL support.  Bummer -- this meant that I now needed to compile PHP on my own on AIX.  Fun stuff!

Step Four: Compiling and Installing PHP on AIX
This part was the most painful of this entire process.  I don't have too much experience building and compiling from source (especially on AIX), so it probably took a little bit longer than it should have.  I did discover a few interesting things though:

  • You must use the 32-bit version of MySQL if you want PHP to compile using it
  • You must use gmake/GNU make instead of the AIX make command for compilation to complete
  • I had to install the apxs (from the httpd-devel package) to reference in my configure command.  The AIX one (under /opt/pware64) made a libphp5.so library that caused Apache to fail to start up.
  • The --enable-maintainer-zts configure option is required to make php thread safe.  Without it, Apache complains and won't load the library.
  • I also came across a very odd problem when I did the "make install".  The first part of the script deletes libphp5.so and then subsequently tries to call chmod on it, at which point it bombs out since it can't find the file.  Nice.  I came across a hack that also worked for me: Have two windows open, one ready to do the make install, and one ready to copy libphp5.so to the directory the script is expecting it to be in.  Start the make install, and then as soon as it has tried to delete libphp5.so, copy it where the script expects it to be.  By doing this, the file will be there when it's looking for it.  It requires a little bit of timing, so it may take a few tries to get it right.
For anyone interested, this is the configure line I used: 
configure '--cache-file=../config.cache' '--prefix=/opt/freeware' '--with-config-file-path=/opt/freeware/etc' '--enable-shared' '--enable-static' '--without-pear' '--with-gd=/opt/freeware' '--with-openssl=/opt/freeware' '--with-zlib' '--with-bz2' '--with-curl=/opt/freeware' '--with-t1lib=/opt/freeware' '--with-freetype-dir=/opt/freeware' '--with-jpeg-dir=/opt/freeware' '--with-png-dir=/opt/freeware' '--with-xpm-dir=/opt/freeware' '--with-zlib-dir=/opt/freeware' '--enable-soap' '--enable-bcmath' '--enable-ftp' '--with-iconv' '--enable-dom' '--enable-json' '--with-pcre-regex=/opt/freeware' '--with-apxs2=/opt/freeware/sbin/apxs' '--with-mysql=/usr/local/mysql' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--enable-maintainer-zts'

Step 5: Testing and Completion
At this point, I now had Apache running with PHP with support for MySQL.  I happily connected to the database and then handed the server over to another developer who would actually be using it.  This was definitely a learning experience, so I hope someone finds this information useful.

UPDATE: I also discovered that by default, cgi scripts were not executing.  This was due to the file permissions set on the httpd log file directory.  So, if you also run into this problem, just run a chmod 775 on your httpd log file directory (mine was located at /var/log/httpd).

3 comments:

Anonymous said...

I am installing PHP on AIX 6.1 also. I am good until I try, 'make install'. libphp5.so gets deleted from the webservers 'modules' directory, then 'make install' fails becuse the file is gone.

Matt Augustine said...

Hi,
Did you try the trick using two windows at the same time to copy and immediately execute? If not, it's mentioned in the post, so you could give that a try.

Ram Kishan said...

Hi,

We are getting following error while installing configuring the http 2.4.2 on AIX 6.1 :-

util_pcre.c:48:18: error: pcre.h: No such file or directory
util_pcre.c: In function 'ap_regfree':
util_pcre.c:103: error: 'pcre_free' undeclared (first use in this function)
util_pcre.c:103: error: (Each undeclared identifier is reported only once
util_pcre.c:103: error: for each function it appears in.)
util_pcre.c: In function 'ap_regcomp':
util_pcre.c:129: error: 'PCRE_CASELESS' undeclared (first use in this function)
util_pcre.c:131: error: 'PCRE_MULTILINE' undeclared (first use in this function)
util_pcre.c:133: error: 'PCRE_DOTALL' undeclared (first use in this function)
util_pcre.c:136: warning: implicit declaration of function 'pcre_compile'
util_pcre.c:136: warning: assignment makes pointer from integer without a cast
util_pcre.c:142: warning: implicit declaration of function 'pcre_fullinfo'
util_pcre.c:142: error: expected ')' before 'pcre'
util_pcre.c:142: warning: type defaults to 'int' in declaration of 'type name'
util_pcre.c:143: error: 'PCRE_INFO_CAPTURECOUNT' undeclared (first use in this function)
util_pcre.c: In function 'ap_regexec_len':
util_pcre.c:180: error: 'PCRE_NOTBOL' undeclared (first use in this function)
util_pcre.c:182: error: 'PCRE_NOTEOL' undeclared (first use in this function)
util_pcre.c:198: warning: implicit declaration of function 'pcre_exec'
util_pcre.c:198: error: expected ')' before 'pcre'
util_pcre.c:198: warning: type defaults to 'int' in declaration of 'type name'
util_pcre.c:221: error: 'PCRE_ERROR_NOMATCH' undeclared (first use in this function)
util_pcre.c:223: error: 'PCRE_ERROR_NULL' undeclared (first use in this function)
util_pcre.c:225: error: 'PCRE_ERROR_BADOPTION' undeclared (first use in this function)
util_pcre.c:227: error: 'PCRE_ERROR_BADMAGIC' undeclared (first use in this function)
util_pcre.c:229: error: 'PCRE_ERROR_UNKNOWN_NODE' undeclared (first use in this function)
util_pcre.c:231: error: 'PCRE_ERROR_NOMEMORY' undeclared (first use in this function)
make: 1254-004 The error code from the last command is 1.


Stop.
make: 1254-004 The error code from the last command is 1.


Stop.
make: 1254-004 The error code from the last command is 1.

Please suggest.