Tuesday, July 29, 2008

Redhat PHP/MySQL on top of mess

If a prior admin has installed php4/mysql4 on a rhel4 box and wanted to upgrade both to version 5 but didn't know about altering the channel subscription to Web Application Stack 1.0 Beta and instead installed them from source and simply had init start /usr/local/bin/mysqld and just edited /etc/httpd/conf.d/php.conf to include a module he dropped into /etc/httpd/modules/libphp5.so (yuck).... then you can do the following...

* Remove the old packages first
up2date doesn't have a remove option like yum (or better apt) so you'll have to dig around. rpm -ev everything that rpm -qa | grep -i php and rpm -qa | grep -i mysql return. Then up2date -u

* Subscribe to Web Application Stack 1.0 Beta
Install the newer versions: up2date -i mysql-server php php-mysql php-ldap php-gd php-xml. Your /etc/httpd/conf.d/php.conf should now just contain a reference RedHat's /etc/httpd/modules/libphp5.so.

* Fix MySQL
If the prior admin installed from source with the default options your data and binaries should be in different locations and can co-exist as you move them:

RedHat: /var/lib/mysql
local: /usr/local/mysql/data
Backup your databases with the old server running:
/usr/local/mysql/bin/mysqldump -u root -p --all-databases > backup.sql
Stop the old one and start the new one. Then drop in the new data. By default the root user shouldn't have a password:
/usr/bin/mysql -u root < backup.sql
Edit /etc/my.conf and update "old_passwords=1" with "old_passwords=0".

RHEL4/5's MySQL comes by default with the old_passwords flag in /etc/my.conf set to true from a default install (via up2date or yum). A new install doesn't have this value set and just uses the new password hash function. As a result the passwords that were created originally used the newer 41 byte hash and not the older 16 byte hash. Thus when you try to import those 41 byte passwords they will be stored but won't work since the system will expect 16 byte passwords until you update the flag and restart MySQL. For more information on MySQL's password hashing see: http://dev.mysql.com/doc/refman/6.0/en/password-hashing.html.

No comments: