Magento – Magento 2 : How to run bin/magento setup:static-content:deploy command programatically

magento-2.1magento2

Is there a way to run bin/magento setup:static-content:deploy in a M2 script? or programatically? I have a scenario where in the CSS file is replaced within the admin panel. So I was thinking to automate the running of bin/magento setup:static-content:deploy without going to the terminal and manually running this command. Is there a way to achieve this? It's not only the bin/magento setup:static-content:deploy but also the bin/magento cache:clean

Best Answer

exec('bin/magento setup:di:compile');
exec('bin/magento cache:clean');

should get you what you need