Migrate Joomla Websites on Ubuntu 17.04 | 17.10 with Apache2, MariaDB and PHP

Someday you may find yourself wanting to move or migrate your current Joomla website or blog to a new host. Maybe be your current service provider isn’t serving your needs and you think a new host might and cost you less.

There are many reasons webmasters migrate their websites and blogs. Moving your websites or blogs to a new host isn’t as bad as some might think. The primary challenge is getting your data over to the new server intact and without issues.

This brief tutorial shows students and new users how to migrate their Joomla websites or blogs to new a server without missing anything. Students and users will learn how to setup the new host, get the data over and restore the website easily.’

To get started with Joomla migration, continue below

For this tutorial, our new host server will be running the latest version of Ubuntu with Apache2, MariaDB and PHP. So, let’s get started.

Step 1: Logon to the new server and Set it Up

When you receive your new server, your first task will be to set it up. This means installing and configuring Apache2, MariaDB and PHP. Most host providers now allow SSH access. So, logon via SSH and run the commands below to update the Ubuntu server.

sudo apt update && sudo apt dist-upgrade && sudo apt autoremove

STEP 2: INSTALL APACHE2

On the new server, run the commands below to install Apache2… We’re assuming that Apache2 is being used on the old server.

sudo apt install apache2

After installing Apache2, run the commands below to disable directory listing.

sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/apache2/apache2.conf

Next, run the commands below to stop, start and enable Apache2 service to always start up with the server boots.

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

STEP 3: INSTALL MARIADB

On the new server, run the commands below to install MariaDB database server.

sudo apt-get install mariadb-server mariadb-client

After installing, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots.

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

After that, run the commands below to secure MariaDB server and create a new root password.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

Restart MariaDB server

sudo systemctl restart mariadb.service

STEP 4: INSTALL PHP AND RELATED MODULES

Now that Apache2 and MariaDB are installed, run the commands below to install PHP and related PHP modules on the new server. This is a good list of PHP modules to install.

sudo apt install php libapache2-mod-php php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysql php-cli php-mcrypt php-ldap php-zip php-curl

After install PHP, run the commands below to open Apache2 PHP default file.

sudo nano /etc/php/7.1/apache2/php.ini        # Ubuntu 17.10
sudo nano /etc/php/7.0/apache2/php.ini        # Ubuntu 17.04

Then change the following lines below in the file and save.

post_max_size = 20M
memory_limit = 256M
max_execution_time = 300
max_input_vars = 10000
upload_max_filesize = 64M

STEP 5: CREATE A BLANK Joomla DATABASE

At this point, all the required Joomla packages and and servers are installed. The new server  is now ready to host Joomla… On the new server, create a blank Joomla database. We’ll use this blank database to restore the database from the old server into.

Run the commands below to logon to the database server. When prompted for a password, type the root password you created above.

sudo mysql -u root -p

Then create a blank database called joomlaDB…  you can use the same database name from the old server.

CREATE DATABASE joomlaDB;

Create a database user called joomla_user with new password.  You can use the same username and password from the old server.

CREATE USER 'joomla_user'@'localhost' IDENTIFIED BY 'type_password_here';

Then grant the user full access to the database.

GRANT ALL ON joomlaDB.* TO 'joomla_user'@'localhost' IDENTIFIED BY 'type_password_here' WITH GRANT OPTION;

Finally, save your changes and exit.

FLUSH PRIVILEGES;
EXIT;

STEP 6: CONFIGURE THE NEW Joomla SITE

Next, configure the Joomla configuration file on the new server. Run the commands below to create a new configuration file called joomla.conf

sudo nano /etc/apache2/sites-available/joomla.conf

Then copy and paste the content below into the file and save it. Replace example.com with your domain name.

<VirtualHost *:80>
     ServerAdmin admin@example.com
     DocumentRoot /var/www/html/joomla/
     ServerName example.com
     ServerAlias www.example.com

     <Directory /var/www/html/joomla/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Save the file and exit.

STEP 7: ENABLE THE Joomla SITE AND REWRITE MODULE

After configuring the VirtualHost above, enable it by running the commands below

sudo a2ensite joomla.conf
sudo a2enmod rewrite

STEP 8: RESTART APACHE2

To load all the settings above, restart Apache2 by running the commands below.

sudo systemctl restart apache2.service

Step 9: Backup Your Database on the old Server

At this stage, the new server is ready for Joomla data… Logon to the OLD server and run the commands below to backup the database for the Joomla site to the /tmp directory.

sudo mysqldump -u root -p joomlaDB > /tmp/joomlaDB.sql

You should be prompted for the root password.. if the password you typed is correct, the database content will be dumped or stored in the /tmp directory.

Step 10: Restore Joomla Site and Database on the NEW Server

Logon to the NEW server and restore the content from the old server… there are many tools you can use to copy the data over securely… Rsync  and SCP are great tools to copy data securely. We’re going to be using rsync here.

The syntax for rsync is:

rsync option source-directory destination-directory

Run the commands below on the new server to copy the database content that was backed up on the old server to the /tmp directory..

rsync -avzP username@192.168.20.22:/tmp/joomlaDB.sql /tmp

Replace the 192.169.20.22 with the old server’s IP… the commands above will copy the joomlaDB database content via SSH over to the local /tmp directory on the new server.

Next, run the commands below to copy Joomla website content stored in the /var/www/html/joomla directory on the old server to the new server in the /var/www/html directory. Rsync will copy over the entire joomla folder to the /var/www/html on the new server.

sudo rsync -avzP username@192.168.20.22:/var/www/html/joomla /var/www/html

Wait for the files to transfer… if all the database and website content were transferred successfully, then you’re golden. Run the commands below to restore the database content into the blank database created above on the new server

sudo mysql -u root -p joomlaDB < /tmp/joomlaDB.sql

This should restore the database on the new server.

At this stage, the new server should have Joomla site content in the /var/www/html/joomla and the database restored on the new server… Hopefully everything is working without issues.

You might want to use the same database and username with the correct password on both servers… (old and new) so you don’t have to reconfigured Joomla database connection settings.

Run the commands below to configure allow Apache2 web server to own  the Joomla content.

sudo chown -R www-data:www-data /var/www/html/joomla/
sudo chmod -R 755 /var/www/html/joomla/

Restart Apache2 web server.

sudo systemctl reload apache2

Step 11: Switch the Domain Name to Point to the new server

Finally, go to your DNS provider and switch or flip the domain name to point to the new server IP address. If everything is copied over correct and the correct usernames and password were used… the new server should begin serving Joomla content.

Wait a few before shutting down the old server.

Congratulations! You have successfully migrated Joomla to a new host

You may also like the post below:

Install phpBB on Ubuntu 17.04 / 17.10 with Nginx, MariaDB and PHP Support

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.