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:
print_r(system('php72 bin/magento cache:flush')); // You can change command as you want.
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.
Related Post – List of Useful Magento 2 SSH/CLI Commands
Get Weekly Updates
Never miss Magento tips, tricks, tutorials, and news.
Thank you for subscribing.
Something went wrong.