08-22-2019, 08:47 AM
Hello Friends, I am new in the linux world. I don’t know much about Linux packages and other applications. I have a blog hosted on my VPS. A few days ago I wanted to migrate to a new VPS. I searched google about the transfer web from one host to a new one. I found some but failed to transfer with those methods. In searching, I found information that we need to export our database and directory and transfer it to a new host. I transferred my website successfully to a new host. I am going to share the method I used to transfer.
First of all, you need to export your website database. You can export it via Phpmyadmin. Actually, I don’t use Phpmyadmin so I export/import database via Terminal.
If you have Phpmyadmin export it. If you don’t, use the following method to export the database.
Database Export via Terminal
The exported file can be downloaded from the root folder or the user folder you are logged in.
First of all, go check if the database is exported or not. After confirmation download it to your PC.
The database backup is completed now. Lets back up the website directory. The directory has a high file size. Downloading it via SFTP client is very difficult so I use a different method. I use Google Drive. I will zip the directory and upload it to google drive.
We need to install google drive.
First of go to the root directory with the following command
Now download the google drive
After the download is completed we will rename the downloaded file. Use the following command to rename the downloaded file.
The downloaded file will have the name “ uc\?id\=0B3X9GlR6EmbnWksyTEtCM0VfaFE “
We have renamed the file. Let's give the execution permission
Now we have to install this to our usr directory. Use the following command to install.
During this installation, we will have to provide our google email. It will also require email confirmation. The terminal will give us a link, we will have to allow the application to access our google drive account.
We are done, the installation of google drive is completed.
Let's compress the website directory.
If you don’t have already installed zip install it first.
The compressed file is stored in the same directory or the user directory you are logged in. Now we will upload this zip file to our google drive.
Use the command gdrive upload to upload the file.
The file will be uploaded to your google drive account. Now let's restore it to our new host.
Logout of your terminal and login to your new host.
First of all, we will restore our database. I use the terminal to restore but you can also restore it with Phpmyadmin.
I use the terminal to restore the database.
First of all login to your MySQL and create a new database with the following command.
After creating log out of your MySQL with the simple exit command. Now upload the downloaded .sql database file to the root directory using a SFTP client.
Use the following command to restore the database
Database restore is completed now let's restore our website directory.
Download the file we uploaded on google drive and unzip it.
There are two methods to download the file from google drive, you can not directly download from google drive. If you want to download you need to install gdrive on your new host. There is an alternate method, I uses.
The method I use is to move zip file from google drive to MediaFire is MultCloud. It is very easy to move your files to mediafire from google drive.But it may be risky.So do it on your own risk. Register at MuliCloud and add your google drive and mediafire account to share files. I simply share my .zip file to mediafire account and download it with the simple command
After downloading move your file to /var/www/ and unzip using the command
We have successfully transferred our website files and database to the new host. Now you just have to edit your website configuration and set its DocumentRoot and enable your site.
Most of the webmaster's know about the Apache site configuration but here is simple information for those who are a newbie.
The website configuration file is stored in " /etc/apache2/sites-available "
So you will have to be in the directory, use
Here you will have to create a new configuration file. Simply use the nano command to create a new .conf file.
and paste the following code, save and exit.
Now we have to enable our website use
If you have any question feel free to ask.
Thanks
regards
Rehan
First of all, you need to export your website database. You can export it via Phpmyadmin. Actually, I don’t use Phpmyadmin so I export/import database via Terminal.
If you have Phpmyadmin export it. If you don’t, use the following method to export the database.
Database Export via Terminal
Code: (Select All)
mysqldump -u [username] -p [database name] > [database name].sql
The exported file can be downloaded from the root folder or the user folder you are logged in.
First of all, go check if the database is exported or not. After confirmation download it to your PC.
The database backup is completed now. Lets back up the website directory. The directory has a high file size. Downloading it via SFTP client is very difficult so I use a different method. I use Google Drive. I will zip the directory and upload it to google drive.
We need to install google drive.
First of go to the root directory with the following command
Code: (Select All)
cd ~
Now download the google drive
Code: (Select All)
wget https://docs.google.com/uc?id=0B3X9GlR6EmbnWksyTEtCM0VfaFE&export=download
After the download is completed we will rename the downloaded file. Use the following command to rename the downloaded file.
The downloaded file will have the name “ uc\?id\=0B3X9GlR6EmbnWksyTEtCM0VfaFE “
Code: (Select All)
mv uc\?id\=0B3X9GlR6EmbnWksyTEtCM0VfaFE gdrive
We have renamed the file. Let's give the execution permission
Code: (Select All)
chmod +x gdrive
Now we have to install this to our usr directory. Use the following command to install.
Code: (Select All)
sudo install gdrive /usr/local/bin/gdrive
During this installation, we will have to provide our google email. It will also require email confirmation. The terminal will give us a link, we will have to allow the application to access our google drive account.
We are done, the installation of google drive is completed.
Let's compress the website directory.
If you don’t have already installed zip install it first.
Code: (Select All)
zip -r filename.zip /path/folder
The compressed file is stored in the same directory or the user directory you are logged in. Now we will upload this zip file to our google drive.
Use the command gdrive upload to upload the file.
Code: (Select All)
gdrive upload filename.zip
The file will be uploaded to your google drive account. Now let's restore it to our new host.
Logout of your terminal and login to your new host.
First of all, we will restore our database. I use the terminal to restore but you can also restore it with Phpmyadmin.
I use the terminal to restore the database.
First of all login to your MySQL and create a new database with the following command.
Code: (Select All)
CREATE DATABASE newdb;
After creating log out of your MySQL with the simple exit command. Now upload the downloaded .sql database file to the root directory using a SFTP client.
Use the following command to restore the database
Code: (Select All)
mysqldump -u [username] -p [database name] < [database name].sql
Database restore is completed now let's restore our website directory.
Download the file we uploaded on google drive and unzip it.
There are two methods to download the file from google drive, you can not directly download from google drive. If you want to download you need to install gdrive on your new host. There is an alternate method, I uses.
The method I use is to move zip file from google drive to MediaFire is MultCloud. It is very easy to move your files to mediafire from google drive.But it may be risky.So do it on your own risk. Register at MuliCloud and add your google drive and mediafire account to share files. I simply share my .zip file to mediafire account and download it with the simple command
Code: (Select All)
wget https://mediafire.com/example.zip
Code: (Select All)
unzip example.zip
We have successfully transferred our website files and database to the new host. Now you just have to edit your website configuration and set its DocumentRoot and enable your site.
Most of the webmaster's know about the Apache site configuration but here is simple information for those who are a newbie.
The website configuration file is stored in " /etc/apache2/sites-available "
So you will have to be in the directory, use
Code: (Select All)
cd /etc/apache2/sites-available
Here you will have to create a new configuration file. Simply use the nano command to create a new .conf file.
Code: (Select All)
nano mysite.conf
and paste the following code, save and exit.
Code: (Select All)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName yourdomain.ext
ServerAlias www.yourdomain.ext
DocumentRoot /var/www/example ( Update this to the directory we have downloaded )
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now we have to enable our website use
Code: (Select All)
a2ensite mysite
If you have any question feel free to ask.
Thanks
regards
Rehan