DaveWentzel.com            All Things Data

December 2014

Move a Drupal site from WAMP to LAMP

There's a dearth of information on google regarding how to migrate your Drupal site from WAMP to LAMP (Windows to Linux).  There's nothing particularly wrong with Windows for running Drupal, but let's face it, there is far more documention available for Linux.  Really useful articles just assume you are using Linux and therefore direct the user to place files in certain /etc/this/that directories and those don't exist on Windows.  Even enabling Apache modules is radically different in Windows from Linux.  Further, my WAMP server runs Windows 2003 which is soon end-of-life and I'm NOT shelling out more money to M$ for another license.  I can't stand the new UIs.  

I created what I believe is a novel approach for migrating a Drupal website from one server to another (especially when changing OSs) that uses git.  Using git allows everything between the WAMP and LAMP site to stay in sync because the migration will likely take quite a few days/weeks as you find every place where you reference "c:\documents and settings" and need to change it to "/home/drupal" or whatever.  This allows ample time to test the upgrade and refresh your test server often.  This method requires only a cursory knowledge of Linux (or any other piece of the LAMP stack, really).  You don't even need to know much about git.  You can keep your LAMP site running on a git branch and merge into that as needed.  

Get your Existing WAMP server ready

  1. Get git installed with a remote repo for your website.  
  2. Create a folder under your DocumentRoot for your mysql dumps.  I suggest DocumentRoot\<mysqldump>.  This should not be readable by your Apache user if your security settings are correct.   
  3. Create the initial mysql dump into this folder:   mysqldump --host=localhost --user=root --add-drop-table <sitedbname> > <sitedbname>.sql
  4. git add all of your files (make sure you get the hidden .htaccess, settings.php, etc files) and push them to your remote rep.  

Build your New LAMP server

Build your LAMP server and give it a static IP.  I always use Ubuntu because it is easiest.  VM or physical, it doesn't matter.  If you are using a hosting provider then you can largely skip this section.  Also, if you are installing on an existing LAMP server, you can also skip this.  

  1. sudo apt-get install lamp-server^ (yes you need that final ^)
  2. sudo nano /etc/apache2/sites-available/00-defaultblah :  change this as necessary.  
  3. sudo nano /etc/apache2/apache2.conf :  find every occurrence of "AllowOverride None" and replace with "AllowOverride All".  This is needed for mod_rewrite.  Also add ServerName localhost somewhere as well.  
  4. sudo apt-get install git
  5. cd /var/www
  6. sudo mkdir <yoursitefoldername>

Install a new Drupal Site with git

In theory this section is not needed.  You could git clone directly from YOUR git repo that you created above.  I prefer to get a clean, working Drupal installation first, then I git pull my site into it.  The benefit is we can ensure all pieces of the Drupal stack are functioning properly with a vanilla Drupal site before we get nuts and migrate our custom site.  This process only has to be done once.  

  1. sudo git clone --branch 7.x git://git.drupal.org/project/drupal.git ./<yoursitenamefolder>
  2. sudo nano /etc/apache2/sites-enabled/000-default.conf and change the DocumentRoot to <yoursitenamefolder>
  3. sudo service apache2 restart
  4. sudo mkdir /var/www/<yoursitename>/sites/default/files :  need to create this manually
  5. sudo chown www-data:www-data /var.../files :  provide necessary permissions
  6. sudo cp /var/www/.../default/default.settings.php /var/www/.../settings.php :  create the initial php settings file from the default
  7. sudo chown www-data:www-data /var/.../settings.php :  provide necessary permissions
  8. sudo apt-get install libssh2-php : this makes module updates easier later
  9. sudo apt-get install php5-gd : required php connector
  10. sudo service apache2 restart
  11. Create your mysql database.  Use the steps below.  
  12. now start the browser install (http://<yourwebsite_ipaddress>).  if you get a "white screen of death" then change your php error logging settings.  

I like to test a vanilla install just to make sure php, mysql, and permissions are correct.  Fix anything as needed to get a clean install.  

One last thing to install is drush, so you can script out upgrades and module updates easily in the future:

  1. sudo apt-get install drush
  2. the repository version may not be the latest version.  Let's fix that: which drush
  3. sudo drush update drush --destination= '<folder from which command>'

Once everything is working you can remove this site and database, or keep it around for the future, or you can git pull your WAMP site/db into it.  However you want to do it.  

The First MIgration

Follow these steps to get your site working on your LAMP server the first time.  

  1. cd /var/www/<website folder> (mkdir if needed)
  2. sudo git init
  3. sudo git remote add origin/master http://path/to/your/repo
  4. sudo git fetch origin/master 
  5. sudo git merge origin/master/master
  6. sudo mysql -u drupal -p <db name> < /path/to/dump/file
  7. See Things That Tend to Break below for more items to check.  

"Refreshing" LAMP 

These steps can be used for subsequent LAMP refreshes

  1. mysqldump --host=localhost --user=root --add-drop-table <sitedbname> > <sitedbname>.sql
  2. git push your WAMP code to your repository 
  3. sudo git pull on LAMP
  4. sudo mysql -u drupal -p <db name> < /path/to/dump/file
  5. Doublecheck that your site still works and your data was refreshed.  

Things That Tend to Break

  1. Fix up any issues in the site status report (admin/reports/status).  For instance, you'll likely see permissions issues since the permissions will NOT copy using git and windows permissions are different than Ubuntu.
    1.  "sites/default/files is not writable".  Simple fix:  sudo chown -R www-data:www-data /var/www/<site>/sites/*

  2. Your site email is probably broken.  Check and fix it as needed.  
  3. Cleanurls...do they still work?  
  4. Do your captchas still work?  

Database Creation Steps

These steps will create the Drupal databases for you, referenced throughout this post. You'll need at least one db for the initial "test" Drupal site and then one db for each site you are going to migrate.  

  1. create the mysql db :  mysqladmin -u root -p create <sitename> :  Your database name and dbuser/password should be the same on your server, otherwise you'll need to change your settings.php file to reflect any changes.  
  2. mysql -u root -p  :need to create user and give permissions
  3. GRANT ALL PRIVILEGES on <sitename>.* to 'your_user'@'localhost' IDENTIFIED BY 'password';

  4. flush privileges;
  5. \q

You have just read "Move a Drupal site from WAMP to LAMP" on davewentzel.com. If you found this useful please feel free to subscribe to the RSS feed.  


Fun With Transactions

Demo files can be found here

This is a short presentation on some of the confusing aspects of transaction handling in SQL Server.  We start with transaction naming:  

Transaction Names

Even on a case-insensitive database this will fail:  

But this will not fail:  

And even this will work because transaction names are totally ignored when issuing a COMMIT:

Autonomous Transactions

A sorely missed feature of SQL Server is native "autonomous transactions."  This is where you "pause" the current transaction and spin up a new transaction.  When the new transaction "completes" (commits or rolls back) then we continue the paused transaction.  Some use cases:

  • out-of-band logging/auditing
  • custom sequence generators

.NET and Java developers have the concept of .REQUIRES_NEW to "pause" an existing transaction and start a new, autonomous transaction.  Under the covers this is implemented as a new spid with potentially different transaction semantics.  I give some demos on how to use Linked Servers in SQL Server to generate your own autonomous transactions. 

Implicit Transactions

Implicit Transactions (IT) cause inordinate confusion.  At their worst they can cause what appears to be massive blocking events on your server.  Most developers and data access technologies do not use IT, the notable exception being the Java world (Spring JDBC, WebSphere, etc).  When SET IMPLICIT_TRANSACTIONS ON is set a transaction is started for you...if it is needed.  That "if" statement is what causes problems because the "if" assumptions are not properly documented by Microsoft.  If your driver forces you to use IT then ensure that whenever a connection is pulled from the pool that sp_reset_connection is being called.  This will reset the IT setting.  If this isn't done then you can "leak" connections where a developer might have turned OFF IT to get finer-grain control.  That's a big problem.  

I have lots of demos on the confusing aspects of implicit transactions as well as how to monitor your server for IT anomalies that may cause blocking or "abandoned spid" problems for you.  

Demo files can be found here



You have just read "Fun With Transactions" on davewentzel.com. If you found this useful please feel free to subscribe to the RSS feed.