When you update the packages on a badly outdated server, the challenge is to do the upgrades without breaking anything. When dealing with a CentOS installation that's two or three versions behind the current release, a direct upgrade simply isn't the safest option.
CentOS uses the yum utility for its package management. For the most part yum is a great tool for software management and updating existing software titles, but it's not your best choice for a distribution upgrade tool. If you attempt to run the yum upgrade command on a CentOS install that is too old, you're likely to experience numerous software dependency errors from yum trying to access dead repositories, and that will inhibit your ability to update or install software.
Instead of running yum upgrade in scenarios like this, you're better off performing a clean install of the latest CentOS version. With this approach you start with a clean, vanilla installation instead of one that has likely been tweaked heavily over time, and likely do so in less time that it would take to upgrade the old server through multiple CentOS version upgrade paths.
I also advocate using a separate hardware server for the clean installation, rather than relying on the existing server hardware. Doing so minimizes downtime – once the new hardware is running, you can simply swap it with the old hardware to complete the transition. Backing up the old server, wiping its hard drives, installing a fresh operating system, and then hoping the backup files are intact isn't a prudent way to upgrade any server. Because if something goes wrong, you're looking at the potential for additional downtime while you begin troubleshooting the problem. So by keeping the original server intact, you have a fallback plan should the restore files end up being corrupted or you run into other problems.
Before you install the new CentOS release on your new server, however, you need to take a few additional steps.
First, back up important settings and data from the old CentOS installation. I recommend using the following tools for the task.
mysqldbcopy is one of the best methods for backing up and restoring a MySQL database. Use mysqldbcopy to back up your server's MySQL databases by following the guide provided in this article on MySQL utilities.
cPanel is both a solid control panel and a reliable way to back up your web server's settings. Install it on the server you wish to upgrade. To start a backup, browse to your server's IP address and log in. Start cPanel, and in the Files section, click on Backup Wizard.
Select the Backup button in the middle of the page. I suggest you choose the partial backup option in order to back up your home directory structure and email separately so that you can restore them separately. You can use cPanel to back up MySQL too, but I've found that mysqldbcopy provides a more reliable database backup.
Using cPanel to back up your home directory will back up most of your application settings for you. However if you have additional applications that don't store settings within your home directory structure, you will need to use browse to that specific application's settings directory, then use the tar command to back up those specific settings. Once the application is installed on the new server, use tar's extract option to restore the settings.
Once all of the critical server data is backed up from the old machine, it's time to prepare the new server.
To get the current version of CentOS, visit the CentOS download page and download the minimal CD to your installation media. Run the install from the text installer. When it asks to install or upgrade an existing system, press the tab key, browse to the end of the line that contains "vmlinuz," and enter in the word text. This will give you the option of running the installer from a command prompt. I recommend sticking to the minimal ISO install, without a GUI, for a server environment.
Once your server is running a clean new copy of CentOS, log in, open a terminal, and install Apache and MySQL with the command yum install httpd mysql-server mysql. Start both services with the commands:
yum install httpd mysql-server mysql
service httpd start
service mysqld start
Also make sure both services start up automatically when the server is restarted in the future with the commands:
chkconfig –levels 235 mysqld on
chkconfig httpd on
You can then log in to MySQL and set up passwords:
mysql -u root
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new-password');
SET PASSWORD FOR 'root'@'localhost.localdomain' = PASSWORD('new-password');
SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('new-password');
With MySQL installed and running, use the instructions in the MySQL Utilities article mentioned previously to restore your database onto the new server.
After Linux, Apache, and MySQL, the fourth pillar of the LAMP stack is PHP. Install it with yum install php php-mysql, then restart Apache with the command service httpd restart.
yum install php php-mysql
service httpd restart
To verify that PHP is running properly, create a PHP test file in /var/www/html/info.php with the following code:
Browse to the URL of the info.php file and, if everything is working correctly, you should see a page with all of your PHP info.
Now you can install all the apps that were on the old server and then restore your server configuration. Mount the media containing your installed-software.log file to reinstall your legacy applications from the old server:
yum -y install $(cat /mounted-backup-location/installed-software.log)
Next, visit the cPanel Backup Wizard on the new server, but this time click on Restore and repeat the steps you took to back up your home and mail data. You will be prompted to browse for the files on your local workstation, then asked to click on the upload button in the middle of the page.
While taking so many steps to update an old CentOS installation may seem unnecessary at first, this approach can save you days of frustration, as it avoids the yum upgrade method, which is prone to problems. A clean installation with restored applications and settings wins over a messy upgrade path every time.
Allowed tags: <a> link, <b> bold, <i> italics