Hello @hanaffekamis
If you want to install Module or Run CLI Command Without SSH/CLI in Magento 2 then there are 2 methods:
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.
<?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.
<?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.
Problem solved? Click Kudos & Accept as Solution!
Magento Developer
Ankita Biswas