How to Install Module or Run CLI Command Without SSH in Magento 2
Lots of Developer and Site Admin have a problem to run command and install module in Magento 2 when there hosting provider does’n provide SSH/CLI Access. In this post we give a custom solution for that. So, you just don’t worry about that. Follow this post and Install Module or Run CLI Command Without SSH/CLI in Magento 2.
We have a two solution for that.
First Solution
If you don’t have permission of CLI. Then we think system() function will help you on this.
To use this function , just simple create command.php file in your Magento root, then write below code in this file.
saveCopyzoom_out_map<?php echo "<pre>"; system('php bin/magento setup:upgrade'); // You can change command as you want. echo "</pre>";
And run this script with http://domain.com/command.php It will gives you resulted output.
Second Solution
If you want to run Magento 2 command without CLI then we have a another solution for that, but it doesn’t gives you any message (Success or Fail), but you can use this if you don’t have any option.
For that you have to create command.php file in your Magento root, and paste below code in command.php file.
saveCopyzoom_out_map<?php use Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $obj = $bootstrap->getObjectManager(); $state = $obj->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); $k[0]='bin/magento'; $k[1]='setup:upgrade'; // You can change command as you want like setup:static-content:deploy, cache:status etc. $_SERVER['argv']=$k; try { $handler = new \Magento\Framework\App\ErrorHandler(); set_error_handler([$handler, 'handler']); $application = new Magento\Framework\Console\Cli('Magento CLI'); $application->run(); } catch (\Exception $e) { while ($e) { echo $e->getMessage(); echo $e->getTraceAsString(); echo "\n\n"; $e = $e->getPrevious(); }
And run this script with http://domain.com/command.php it doesn’t gives you any message (Success or Fail), but you can use this as a second option.
That’s it, we hope this Magento post helped you to know How to Install Exetnsion or Run Command Without SSH/CLI in Magento 2.
Bookmark it for your future reference. Do comment below if you have any other questions or doubts.
P.S. Do share this post with your team.
AI-Powered Recommended Articles
How to Install Magento 2 Using Command Line
Learn how to install Magento 2 using the command line interface for a streamlined and flexible installation process.
Useful Commands list for Magento 2
Discover useful Magento 2 commands that can be run via SSH to optimize your development and server management tasks.
How to Create a Custom Console Command in Magento 2
Learn how to create custom console commands in Magento 2 to extend the command line interface for your specific needs.
Magento 2 Commands Shortcut
Discover useful command shortcuts in Magento 2 to enhance your development workflow and save time while managing your store.
How to Use Event in Magento 2
Learn how to use events in Magento 2 to trigger custom functionality and extend store operations.
Manage Git Repository in Magento 2
Learn how to manage a Git repository in Magento 2 for version control and proper source code management.