As explained at Why you should run migrations in Drush rather than the UI, drush is a faster and more robust means of running large migration operations than the web-based UI is. As of Migrate 2.6, it is possible (with some advanced server-side configuration) to start migration operations from the UI that will run in the background via drush on the server.

Configuring background operations

To enable background imports and rollbacks requires some configuration on the server side. The key element is letting the Migrate module know where the drush command resides on the server, so it can be run. This is done by setting the Drupal migrate_drush_path variable to the full path of the drush command on the server, either in settings.php:

$conf['migrate_drush_path'] = '/usr/bin/drush';

or by setting the variable using drush:

$ drush vset migrate_drush_path /usr/bin/drush

If the path contains spaces, be sure to escape them:

$ drush vset migrate_drush_path '/Applications/Dev\ Desktop/drush/drush'

On a Windows server the path of the drush command has to include 'drush.bat', e.g. like C:\ProgramData\Drush\drush.bat.

Another element is to make sure that PHP is on the path for your web server. To verify this, go to http://example.com/admin/reports/status/php and look at the PATH value under Apache Environment. If the PATH does not include the directory containing PHP, you will need to set the PATH appropriately. On some systems, this may mean setting PATH in an envvars file - other system may vary.

On Mac OS X with MAMP, for example, you need to edit the file /Applications/MAMP/Library/bin/envvars and add some additional settings like the following (adjust for the version number of PHP that you're using) to the end of the envvars file and then restart MAMP for it to take effect:

PATH="/Applications/MAMP/bin/php/php5.3.20/bin:/Applications/MAMP/Library/bin:$PATH"
export PATH

Once you have set the migrate_drush_path variable, visit the Configuration page in the migrate UI. This page will validate that your server is properly configured to run drush (by running a drush status command and verifying its output), and if so it offers further options:

Import method - You can choose for the Import and Rollback operations in the UI to always run migrations through the UI or to always run them through drush. You may also choose to have the option at run time - the operations menu will include the selections Import immediately, Import in background, Rollback immediately, and Rollback in background. Thus, you can choose to use the UI for relatively quick operations, and only use drush for large import jobs.

Send email notification when a background operation completes - If checked, when a background import or rollback completes notification will be sent to the email address of the account running the operation. Whether or not you choose notification, you can always check the progress of an operation by refreshing the dashboard page. When notification is selected, you can enter the subject and body to be used for the email notification.

Comments

geerlingguy’s picture

If you're using MAMP on a Mac, and you need to add MAMP's PHP bin directory to the Apache environment PATH in envvars, you need to edit the file /Applications/MAMP/Library/bin/envvars and add the following (replacing the PHP version with whatever version you're using):

export PATH="$PATH:/Applications/MAMP/bin/php/php5.3.20/bin"

Additionally, if you're still not able to get drush working through the UI, you might need to comment out the DYLD_LIBRARY_PATH settings inside the same envvars file (for some reason, the settings can cause exec() to fail and exit with status code 5.

__________________
Personal site: www.jeffgeerling.com

garrettc’s picture

If you're using the stock Apache that comes with OSX but you have an alternate PHP (from Homebrew for example) then the environment variables are controlled by /System/Library/LaunchDaemons/org.apache.httpd.plist.

You'll need to add the following lines (replacing /usr/local/bin with your desired PATH):

<key>EnvironmentVariables</key>
<dict>
  <key>PATH</key>
  <string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
</dict>

And then restart Apache to apply the change.

StryKaizer’s picture

For those who run into memory issues using drush migrate, I wrote a blogpost about this issue. You can find it here http://www.jimmyhenderickx.be/drupal-migrate-memory-issues-using-drush

lolandese’s picture

On Unix or OS X use which drush to know the location. On Windows where drush from the command line.

featherbelly’s picture

N.B. I'm on Mac OSX Yosemite using default Apache (2.4.9) but this should be applicable everywhere...

Make sure mod_env is enabled in apache config, e.g. /private/etc/apache2/httpd.conf.

Check your existing Apache Environment PATH - check php status report (phpinfo) - http://mywebsite.local/admin/reports/status/php.

Add a SetEnv directive to your VirtualHost:

<VirtualHost *:80>
    DocumentRoot "/MyWebsiteRoot/docroot"
    ServerName mywebsite.local
    SetEnv PATH /usr/bin:/bin:/usr/sbin:/sbin:/my/custom/path
</VirtualHost>

Replace /my/custom/path with your path to PHP, e.g. usr/local/Cellar/php56/5.6.3/bin.

Restart Apache.

nanabrownee’s picture

update:

There isn't actually anything new appearing on the UI wordpress import wizard. On the other hand the migrate command works and the import is done on the background.

I know this is not the place to post this but I cant seem to get answers anywhere else and it's pretty urgent...

Let me sum up..

Drush also accepts the drush vset migrate_drush_path C:\FolderName\Dush\drush.bat
Youhou!!! But I am not really sure it's actually setting amything at all, because if I write the wrong path it still tells me it's successful?!

The next thing to do is to see if the PHP directory is in the path of my Drupal apache environment, this is what I get: "C:\wamp\bin\php\php5.5.12"
That's what am looking for in the path, right? if it is Then it's there!

if I follow the steps from here: https://www.drupal.org/node/1958170 It should be working and I should see further options in the UI wizard, butI don't?!

Can someone help me and my wamp server on win 8.1. solve this?

klokie’s picture

I'm running PHP-FPM with Nginx. To enable the migrate UI integration with drush, I had to to add the following line to my /etc/php-fpm.conf file:
env[PATH] = /usr/local/bin:/usr/bin:/bin