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
For MAMP users on Mac OS X
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):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
Configure environment variables on Mac OSX stock apache
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 desiredPATH
):And then restart Apache to apply the change.
If you run into memory issues using drush migrate
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
Drush location
On Unix or OS X use
which drush
to know the location. On Windowswhere drush
from the command line.https://www.martin.postma.website/
Using SetEnv Directive in Apache Config
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:
Replace
/my/custom/path
with your path to PHP, e.g.usr/local/Cellar/php56/5.6.3/bin
.Restart Apache.
wamp on windows
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.
PHP-FPM/Nginx config (Mac)
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