Skip to content

Instantly share code, notes, and snippets.

@toolboc
Last active October 13, 2017 01:28
Show Gist options
  • Save toolboc/42fde3eac3775119b0955572d739a16f to your computer and use it in GitHub Desktop.
Save toolboc/42fde3eac3775119b0955572d739a16f to your computer and use it in GitHub Desktop.
WordPress_Migration_Azure.md

Migrating WordPress to Ubuntu VM in Azure

Deploy Ubuntu VM

Take note of the ip address given to the VM

DNS

If you wish to use a custom domain, obtain your VM ip address from the Azure Portal and create an A record that points @ to the ip of the VM

Install & Configure Web Server (apache + php + mysql)

  • apt-get update
  • apt-get install apache2
  • apt-get install mysql-server
  • sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

Open port 80 in the Network Security Group for your VM

Test by visiting the VM in a browser, you should see default Apache Config

Migrate Website & Data

SCP to obtain wordpress content form original server

Backup site contents:

  • mkdir [backupsitedirectory]
  • cp -R [originalsitedirectory] [backupsitedirectory]
  • tar -czvf [backupname].tar.gz -C [backupsitedirectory] .

THEN Copy to VM

  • scp [backupname].tar.gz [user]@[VirtualMachine]:~/[backupname].tar.gz

NEXT Extract to Proper Location and set Proper Permissions for Apache on VM

  • sudo mkdir /var/www/vhosts
  • tar -C /var/www/vhosts -xzvf ~/[backupname].tar.gz
  • sudo chown www-data:www-data -R /var/www/vhosts/

NEXT Configure Apache

Create a config for the new site

  • sudo vi /etc/apache2/sites-available/[sitename.TLD].conf

Paste in configuration details (this may be available in the original apache config file on the original machine)

<VirtualHost *:80>
    ServerAdmin webmaster@[sitename.TLD]
    DocumentRoot /var/www/vhosts/[sitename.TLD]
    ServerName [sitename.TLD]
    ServerAlias www.[sitename.TLD]
    ErrorLog /var/log/apache2/[sitename.TLD]-error_log
    CustomLog /var/log/apache2/[sitename.TLD]-access_log common
</VirtualHost>

Enable mod-rewrite

sudo a2enmod rewrite

Enable the site

sudo a2ensite [sitename.TLD].conf

Reload Apache

service apache2 reload

Revisit Site (Ctrl+F5 to ensure proper Refresh)

Note: Error establishing a database connection

Check wp-config.php to ensure you have a proper user / pass for database connection

Obtain MySQL Data from Original Machine & Import to VM

Dump the original Database & all Users

  • mysqldump -u root -p --flush-privileges --routines --all-databases > [dumpfilename.sql]

    OR for a specific Database:

  • mysqldump -u root -p --routines [database_name] > [dumpfilename.sql]

THEN Copy to VM

  • scp ~/[dumpfilename.sql] [user]@[VirtualMachine]:~/[dumpfilename.sql]

NEXT Import

  • mysql -u root -p < [dumpfilename.sql]

Revisit Site (Ctrl+F5 to ensure proper Refresh)

Everything should be working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment