Recently I'd been tasked to migrate a Joomla CMS from one hosting provider to another. As a Rails developer, I cried. A lot. Seriously, what the heck is Joomla??

Joomla is a CMS (content management system), much like WordPress. Apparently it's the 2nd most popular CMS out there? (I thought Drupal was? What do I know, I barely know what CMS even is.)

Anyway, first of all, I did the running away on your behalf. "Countless" hours pouring over tutorials and figuring out things. But...It really isn't that hard to migrate your Joomla stuff from one server to another.

Here is the general setup of the old server and new server. And the trials and tribulations I went thru. This was scary for me because it uses MySQL and PHP, 2 things I am rather unfamiliar with, but looking back, it wasn't so bad at all.

Old Server

  • CentOS 6.3
  • MySQL 5.5
  • httpd (and not Apache2)
  • Joomla version ??? (more on this later)

New Server

  • Ubuntu 14.04 LTS
  • MySQL 5.6
  • Apache2 (2.4.x)

The summary of steps

Here is what is going to happen and why.

Joomla pages are in their own folders. You can pretty much transfer the folders as is, with their known directory structure, from one server to the other. And then you do a database backup and shove it into the new server. There's some weird finicky settings that need to be changed, but that's all small stuff. So since I like bulletted lists...

  • Transfer Joomla pages from old server to new server
  • Export and then import database dump
  • Change about certain settings

The task seemed a lot larger at the beginning when I first was handed it. But at the end of the day, it wasn't so bad at all, only time consuming.

Transferring of Joomla files

The particular Joomla installation on the old server was at /var/www/vhosts/ with each site having their own directory. A lot of the tutorials I found had me FTPing the pages down to my local machine and then reFTP'ing it up. But...why put me in as middleman? That's what scp is for!

Save yourself a bit of time by adding in the ~/.ssh/id_rsa.pub key to your ~/.ssh/authorized_keys file so you don't have to put in root password.

# on old server as root
cat ~/.ssh/id_rsa.pub
# copy this

# on new server
sudo nano ~/.ssh/authorized_keys
# paste the id_rsa.pub key into here
# save and exit

Time to copy the files.

# on the new server
sudo mkdir /var/www/vhosts
# on the old server
cd /var/www/vhosts
scp -r . root@123.123.123.123:/var/www/vhosts/

Depending on how many Joomla sites you're moving and depending on your servers' connection speeds, this can take a very short time or a very very long time. I moved 5 sites and that took roughly 2 hours, which is surprising since it was going from one server to another and bypassing me. There was about 5 GB of data to be transferred though.

While we're at it, since the CentOS setup was using httpd (Apache), I got lazy and decided to transfer over the site.conf files for Apache. Why reinvent the wheel when you can just copy, after all?

# on the old server
cd /etc/httpd/vhost.d/
scp -r . root@123.123.123.123:/etc/apache2/sites-available/

At this point I feel like I should re-name the article "how to use SCP" hah...

Export and Import MySQL database

I'm so much more familiar with Postgres that when it came to using MySQL, I freaked out a bit, admittedly. Being unfamiliar with how things were setup, I took the easy route and created a dump directly on the older server then scp the dump to the new one. There were no show-stopping differences between 5.5 and 5.6 that I saw.

# on old server
mysqldump --all-databases > all_db.sql
scp -r all_db.sql root@123.123.123.123:/home/deploy/
# put it in any directory you want, really

# on new server
mysql -u root -p < all_db.sql

Fun fact, if you didn't know this about mysql.... If you set up mysql root with a password and don't have it locked down, any user can log into it, but they won't see your databases at all. e.g. if you hop into mysql as user deploy and show databases, nothing shows up. But if you log into mysql as root then you see your databases. This really threw me for a loop.

# as user deploy
mysql
# then in mysql, list the databases
show databases;
# you shouldn't see anything
exit
# now log in as root (with password)
mysql -u root -p
show databases;
# boom! all your databases are there
exit

But, I digress.

Changing Settings - Joomla

Now that the files you need have been moved over, it's time to adjust the settings. Again, I had about 5 Joomla sites, so I picked one to test things on.

First, let's focus on the Joomla settings.

At this point, I realize I should have imported the data into a different mysql user account vs the root one, but, what's done is done. Moving on.

cd /var/www/vhosts/site.com/public_html
sudo nano configuration.php

Scroll down to find the database section near the top and change the settings to reflect which user you put the data under. The dump file should have created the databases for you and should be the same.

public $dbtype = 'mysql';
public $host = 'localhost';
public $user = 'root';                       # possibly change this
public $password = 'your_awesome_password';  # change this
public $db = 'app_database';                 # change this

Save and exit. This should be all you need to do for your Joomla settings.

Changing Settings - Apache

There were some small differences between the httpd and Apache2 server settings so things needed to be updated/adjusted.

cd /etc/apache2/sites-available/
sudo nano site.conf

Adjust the ServerName and Directory block options. For instance, the + - symbols are no longer used in the Options, so I removed them accordingly. I also adjusted where my logs went. (I don't like them in /var/log/apache2/ and prefer them in /usr/share/apache2/logs/)

I changed the ServerName from the domain to my IP address to make sure the site worked. I recommend this as well for you.

If you have SSL certs that are needed, make sure to also transfer them over and adjust the apache settings.

Save and exit. Enable that site and reload Apache2.

sudo a2ensite site.conf
sudo service apache2 restart # or reload

If there are any errors and Apache won't restart, correct them.

Go to http://123.123.123.123 (whatever your IP is) and confirm that your site loads properly and things are looking super fly. Celebrate and then complete the crossover by switching the IPs for the domain.

Level up +5


Questions? Comments? Hit me up at risaonrails !