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

Someday you may find yourself wanting to move or migrate your current Drupal 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 Drupal 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 Drupal 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


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


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


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


At this point, all the required Drupal packages and and servers are installed. The new server  is now ready to host Drupal. On the new server, create a blank Drupal 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 drupalDB  you can use the same database name from the old server.


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

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

Then grant the user full access to the database.

GRANT ALL ON drupalDB.* TO 'drupal_user'@'localhost' IDENTIFIED BY 'type_password_here' WITH GRANT OPTION;

Finally, save your changes and exit.



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

sudo nano /etc/apache2/sites-available/drupal.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/drupal/
     ServerName example.com
     ServerAlias www.example.com

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

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


Save the file and exit.


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

sudo a2ensite drupal.conf
sudo a2enmod rewrite


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 Drupal data. Logon to the OLD server and run the commands below to backup the database for the Drupal site to the /tmp directory.

sudo mysqldump -u root -p drupalDB > /tmp/drupalDB.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 Drupal 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@ /tmp

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

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

sudo rsync -avzP username@ /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 drupalDB < /tmp/drupalDB.sql

This should restore the database on the new server.

At this stage, the new server should have Drupal site content in the /var/www/html/drupal 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 Drupal database connection settings.

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

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

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 Drupal content.

Wait a few before shutting down the old server.

Congratulations! You have successfully migrated Drupal to a new host

You may also like the post below:

Leave a Comment

Your email address will not be published.