Someday you may find yourself wanting to move or migrate your current Drupal website or blog to a new server. 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 Nginx, 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 Nginx, 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 Nginx
On the new server, run the commands below to install Nginx. We’re assuming that Nginx is being used on the old server.
sudo apt install nginx
Next, run the commands below to stop, start and enable Nginx service to always start up with the server boots.
sudo systemctl stop nginx.service sudo systemctl start nginx.service sudo systemctl enable nginx.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-FPM AND RELATED MODULES
Now that Nginx 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-fpm 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 Nginx PHP default file.
sudo nano /etc/php/7.1/fpm/php.ini # Ubuntu 17.10 sudo nano /etc/php/7.0/fpm/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 DRUPAL DATABASE
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 DATABASE drupalDB;
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.
FLUSH PRIVILEGES; EXIT;
STEP 6: CONFIGURE THE NEW DRUPAL SITE
Next, configure the Drupal configuration file on the new server. Run the commands below to create a new configuration file called drupal
sudo nano /etc/nginx/sites-available/drupal
Then copy and paste the content below into the file and save it. Replace example.com with your domain name.
server { listen 80; listen [::]:80; root /var/www/html/drupal; index index.php index.html index.htm; server_name example.com www.example.com; location / { try_files $uri /index.php?$query_string; } location @rewrite { rewrite ^/(.*)$ /index.php?q=$1; } location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(|/.*)$; fastcgi_index index.php; # fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; # for Ubuntu 17.04 fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; # for Ubuntu 17.10 include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7 try_files $uri @rewrite; } location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7 try_files $uri /index.php?$query_string; } }
Save the file and exit.
STEP 7: ENABLE THE DRUPAL SITE
After configuring the VirtualHost above, enable it by running the commands below
sudo ln -s /etc/nginx/sites-available/drupal /etc/nginx/sites-enabled/
STEP 8: RESTART Nginx
To load all the settings above, restart Nginx by running the commands below.
sudo systemctl restart nginx.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@192.168.20.22:/tmp/drupalDB.sql /tmp
Replace the 192.169.20.22 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@192.168.20.22:/var/www/html/drupal /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 Nginx 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 Nginx web server.
sudo systemctl reload nginx
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: