{"id":1548,"date":"2021-01-25T15:51:02","date_gmt":"2021-01-25T15:51:02","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/run-ssh-command-through-php-in-magento-2\/"},"modified":"2025-05-22T11:09:32","modified_gmt":"2025-05-22T05:39:32","slug":"run-ssh-command-through-php-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/run-ssh-command-through-php-in-magento-2\/","title":{"rendered":"How to Run SSH Command Through PHP in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2 offers SSH commands to perform actions like clean cache, reindex data, display status of indexer, etc. These commands can be run from the command prompt.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, if you do not want to use the command prompt, the other method is to run SSH command through PHP in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You may want to do so in case of creating a script and running it at regular interval of time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here, I\u2019ve taken the example to flush cache by the PHP script.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Run SSH Command Through PHP in Magento 2:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"&lt;pre&gt;\";\nprint_r(system('php72 bin\/magento cache:flush')); \/\/ You can change command as you want.\necho \"&lt;\/pre&gt;\";<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, do share the post with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 offers SSH commands to perform actions like clean cache, reindex data, display status of indexer, etc. These commands can be run from the&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1548","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1548"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1548\/revisions"}],"predecessor-version":[{"id":14534,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1548\/revisions\/14534"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}