Magento Server Migration: Migrate Magento Store to a New Server

Magento Server Migration: Migrate Magento Store to a New Server. In this guide, we introduce Magento, talk about server migration then explain how to migrate the Magento store to a new server.

Moving big volumes of data from one server to another might be scary since data is valuable. For reasons of safety, while upgrading or replacing hardware, or for other reasons, data may be transferred between servers. Read on for in depth information on Magento server migration and its many facets.

What is Magento?

Magento is an extensible open source eCommerce platform with various available extensions, including plugins, themes, and tools. It’s ideal for micro and medium sized enterprises.

It provides a comprehensive set of tools for building an online store. Since its first release in 2008, Magento has undergone several iterations and enhancements. Using a tool or sophisticated Server transferring software, data, programs, and even user data may be moved from one server to another. This procedure is known as Server Migration.

Server professionals frequently execute this operation. However, anybody with sufficient computer abilities may migrate their data across servers. Data accessibility may be interrupted during transfer.

What Does Migrating Hosts Mean?

Transferring your data from one host’s server to another host’s server is what is meant by the term “migrating hosts.” If you are switching servers, you are not doing so without a host. There may be one or two hosts engaged in this.

When moving to a different server from the same host, both hosts are considered “migrating hosts.” If, on the other hand, you want to transfer files to a new server with a new host, the host being migrated is the one to which the files are ultimately moved.

How Long Does a Server Migration Take?

Factors such as server and data sizes, network connections, site activity, and time of day all affect how long it takes to complete a server migration.

Depending on the amount of data being transferred and whether or not the migration is being performed during peak hours, relocating a server may take anywhere from 30 minutes to three hours.

The longer it takes for the server transfer to finish, the more data is being sent and received, which consumes more bandwidth.

Why Should I Consider a Server Migration?

There are several situations when it might be required to switch servers.

  • Older gear won’t be able to keep up with the speed of newer versions.
  • Costs may be cut by enhancing server availability with web hosting or by decreasing the number of servers needed to handle the same traffic.

Magento Server Migration: Migrate Magento Store to a New Server

In this section, we guide you how to migrate Magento to a new server.

Step 1: Create a Backup of the Magento Database

The database is an important aspect of the Magento store. The Magento Database contains your store information, such as store settings, orders, customers, products, etc. So you need to backup the Magento database first. Use the mysqldump command-line utility to backup the Magento database.

First, connect to your Magento server via SSH. Then, switch the directory to the Magento store.

				
					cd /var/www/html/magento
				
			

Next, verify all your Magento files using the following command.

				
					ls
				
			

You see all the files and directories on the following screen.

Now, run the mysqldump command to create a full backup of Magento.

				
					mysqldump -u magentouser -p magentodb > var/backups/magentobackup.sql
				
			

You will be asked to enter the Magento database user’s password to complete the backup process. 

After the successful backup, you can verify your backup using the following command.

				
					ls -l var/backups
				
			

Output.

				
					-rw-r--r-- 1 root root 1301 Aug 1 08:58 magentobackup.sql

				
			

Step 2: Create a Backup of the Magento FileSystem

The Magento filesystem contains your store product media, extension code, and the Magento codebase. So you will also need to backup a Magento filesystem to your system.

First, navigate to the Magento directory using the following command.

				
					cd /var/www/html/magento
				
			

Next, run the following command to create a Tar archive of your Magento filesystem.

				
					tar -czf ./magento-files.tar.gz --exclude=var/cache --exclude=var/full_page_cache --exclude=var/log --exclude=var/report --exclude=var/session .
				
			

Then, you will need to put your store in maintenance mode to prevent data inconsistencies during the file migration. You can run the following command to enable maintenance mode.

				
					php bin/magento maintenance:enable
				
			

Step 3 - Prepare the Destination Server

After backing up a Magento filesystem and database, you need to prepare a new server to migrate all data from the older server to the newer one.
Keep in mind the following when you prepare a new server.

  • Install a LAMP stack with all necessary PHP extensions.
  • Use the same database credentials on both the origin and the destination server.
  • The Magento filesystem owner should be the same on both servers.

After preparing a new server, it’s time to migrate a filesystem and database to a new server. First, create a Magento directory inside the web root directory of your destination server.

				
					mkdir /var/www/html/magento
				
			

Next, navigate to the Magento directory with the following command.

				
					cd /var/www/html/magento
				
			

Then, use the SCP command to copy the filesystem and database backup file from the origin to the destination server.

				
					scp root@origin-server-ip:/var/www/html/magento/magento-files.tar.gz .
scp root@origin-server-ip:/var/www/html/magento/var/backups/magentobackup.sql .
				
			

After copying both files, verify them with the following command.

				
					ls -l magento-files.tar.gz magentobackup.sql
				
			

Now, unpack the Magento filesystem backup to the Magento directory.

				
					tar -xzf magento-files.tar.gz .
				
			

Next, import the Magento database from the backup file using the following command.

				
					mysql -u magentouser -p magentodb < magentobackup.sql
				
			

Now, you should assign proper ownership and permissions to all Magento files and directories.

				
					chown -R www-data:www-data /var/www/html/magento
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
find ./var -type d -exec chmod 777 {} \;
find ./pub/media -type d -exec chmod 777 {} \;
find ./pub/static -type d -exec chmod 777 {} \;
chmod 644 ./app/etc/*.xml
chmod 777 ./app/etc
chmod 777 var/log
chmod 777 generated

				
			

Step 4 - Make Magento New Server Live

Before accessing the new Magento store do it via a web browser. Update the DNS records of your domain and point it to the new server IP address. Wait for some time to propagate the DNS record.

After the propagating the DNS changes, install cron to allow Magento to perform vital background tasks.

				
					php bin/magento cron:install
				
			

Finally, switch your Magento store into production mode using the following command.

				
					php bin/magento deploy:mode:set production
				
			

You can now access your newly migrated Magento store via a web browser using your domain name.

Magento Server Migration: Migrate Magento Store to a New Server Conclusion

In this post, we have created a database and filesystem backup on the origin Magento server. Then, we prepared a new Magento server and imported both backup files to the new server. We then changed the DNS setting pointing to the new server IP and verified the migration via a web browser.

Since data is so crucial in modern IT, no information must be lost during the server relocation. Prioritizing data based on its value is a crucial step toward a successful transfer.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x