3

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

asked Feb 21, 2019 at 12:32
4
  • setup:di:compile generates php classes and doesn't relate to css. Probably you need setup:static-content:deploy. For setup:di:compile you can call \Magento\Setup\Console\Command\DiCompileCommand::run Commented Feb 21, 2019 at 14:11
  • @jonijones updated my question Commented Feb 21, 2019 at 15:00
  • In that case, you can use \Magento\Setup\Console\Command\DeployStaticContentCommand and \Magento\Backend\Console\Command\CacheCleanCommand as dependencies in your code and call run method to regenerate static files and clear the cache Commented Feb 21, 2019 at 15:56
  • @jonijones I know it's too much can you perhaps add this as answer and show a sample code for this? Commented Feb 21, 2019 at 15:59

2 Answers 2

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

should get you what you need

answered Feb 21, 2019 at 12:38
0

Create Shell script.
Add bin/magento setup:di:compile ... command into shell script.

Then you can run this shell script using php file on any specific event on which you want run.

I hope this will help you.

fmsthird
4,6224 gold badges18 silver badges42 bronze badges
answered Feb 21, 2019 at 12:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.