How to Run SSH Command Through PHP in Magento 2
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.
However, if you do not want to use the command prompt, the other method is to run SSH command through PHP in Magento 2.
You may want to do so in case of creating a script and running it at regular interval of time.
Here, I’ve taken the example to flush cache by the PHP script.
Method to Run SSH Command Through PHP in Magento 2:
echo "<pre>";
print_r(system('php72 bin/magento cache:flush')); // You can change command as you want.
echo "</pre>";
That’s it.
Any doubts in this post can be mentioned in the Comments section below.
I’d be happy to help.
Also, do share the post with Magento Community via social media.
Thank you.
Related Post – List of Useful Magento 2 SSH/CLI Commands
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How to Show Address Fields in Registration Form in Magento 2
Solved: Array and String Offset Access Syntax With Curly Braces is Deprecated in Magento 2
Next