Magento 2 – Running Bin Commands Without Keeping in Terminal

consumersimage resizemagento2product-images

Is there a way to run these commands:

php -dmemory_limit=12G bin/magento catalog:images:resize -a

or

php -dmemory_limit=12G bin/magento queue:consumer:start media.storage.catalog.image.resize

without having to keep the terminal opened?

The process takes several days as we have 900k images in our store. This requires the terminal window to be opened this whole time. As soon as window is closed, the process stops.

This guide talks about running image resize in async mode, but it still requires the window to be opened on both the resize command and the consumer command.

Best Answer

Simple solution – append & to the command for it to detach from the terminal and run in the background. You'd have to monitor its completion using process monitoring tools like ps and may want to redirect its output to a file to watch the progress while it's still running.

php -dmemory_limit=12G bin/magento catalog:images:resize -a &

A more advanced approach is to use screens – the tool allowing to detach from and reattach to terminal sessions running in the background. You won't have to redirect the output to a file.