Saturday, 19 May 2012

Updating PHP and MySQL

Well, I was right that installing the latest versions of PHP and MySQL would take ages. I spent most of today working on this, and that was just installing them on my local system, not on the actual web server.

The main problem was with MySQL. I first downloaded a binary (not realising it was a binary), but then realised that I would probably need to build from source. After downloading the source, it said that you should use the binary as it has been extensively tested and optimised for best efficiency, unless you have some special reason for building from source.

So I went back to the binary, and found out how to install it. It seemed that actually all you do is unzip the tarball, and then that's it. No installing needed to be done. But then, it didn't work as it requires libaio.

So now I had to find a libaio download, and also build mysql from source (as I couldn't see how to tell the pre-built binary where the libaio libraries are installed to). Thankfully I found this really good guide on how to install MySQL and all the dependencies it requires: Download, configure, compile, and install MySQL 5.5 from source code on Linux

Now, for installing libaio, that guide just says to download and extract it. I didn't think this could be correct, so I tried to install libaio. Libaio requires some programs from the same developer called configure and 9unix. And these require a program called bmake (BSD compatible make).

When installing bmake I had an error, but after googling I found out the fix. I had to edit line 835 of bmake/libnbcompat/__glob13.c and add the following:

 #ifndef ARG_MAX
 #define ARG_MAX (sysconf(_SC_ARG_MAX))
 #endif

That made bmake install okay. But when it came to installing 9unix, I got a different error. Doing some googling, the info I read said was about some value in glib.c being 8, which should be 4 for a 32 bit system. So I opened the file, but the variable already was set to 4. So that obviously wasn't causing the problem. And I couldn't find any other info as to what the error could be caused by.

So I decided to just try following the installing MySQL from source guide I linked to above, without actually compiling libaio. And it actually seems to have worked okay. I'm sure I didn't need to install any dependencies last time I built MySQL though.

My problems installing MySQL weren't over though. First problem was that I tried copying the data folder from the old MySQL installation to the new one. But I couldn't do this as the ibdata1 file was 6GB! Googling about this, it seems this has been a problem with MySQL for a long time, and it seems they won't fix it.

So instead I had to restore the old installation and then dump the SQL:

$PATHMYSQL/bin/mysqldump -S $PATHMYSQL/mysql.sock -u root -p --all-databases > ~/dump.sql

But I had some trouble getting the data back into the new version of MySQL. Most info I found using Google was based on just restoring a single database. The info given for restoring multiple databases generally was to use:

mysql --socket=$PATHMYSQL/mysql.sock -u root -p <~/dump.sql

But this didn't work for me. It looked like it was working (took a few seconds to process), but when I checked none of the databases had actually been imported. Instead I had to login to mysql and then source the dump file:

mysql --socket=$PATHMYSQL/mysql.sock -u root -p
source $HOME/dump.sql

Anyway, I did eventually get MySQL up and running okay. I was surprised that my (local) website still worked okay since PHP was compiled against an earlier version of mysql. I then installed the latest version of PHP as well, and my local websites seem to be working okay. Now I just need to do the same on the web server, and hope there aren't any different problems there (Web Server is Cent OS, my local dev environment is Ubuntu).

No comments: