I tried the system() ex.( system(php bin/magento setup:upgrade) ) function of PHP to execute the CLI command of Magento, but no luck. Is there any other way? It is very hassle to use Flush Static Files Cache in Admin Panel just to apply the CSS or JS I added. We are using shared server, that means there is no SSH Account provided to us.

3 Answers 3


Login through SSH to your server (using something like PUTTY)

Use the command

cd path/to/magento/install/

Obviously change the path above to your actual Magento install, maybe

cd public_html/magento/

From there to install a module

php bin/magento setup:upgrade

php bin/magento setup:di:compile

php bin/magento setup:static-content:deploy

NOTE: FTP into your server and check in public_html/magento/bin/ that the magento file has the permission to be executed i.e. 0744

  • We have no SSH account, since we are only using shared server. Is there other way to run the CLI commands through file and execute it browser?
    – larp
    Commented Sep 14, 2018 at 5:34
  • You would need to use the object manager class in a module as per below. I would STRONGLY suggest you ask your hosting provider to give you some kind of shell access
    – Anthony
    Commented Sep 14, 2018 at 5:49
  • I asked that before to the hosting provider, but they dont give us shell access/ssh account.
    – larp
    Commented Sep 14, 2018 at 5:54

Try this `

$modules = array('VENDORNAME_MODULENAME');
    /* Code to enable a module [ php bin/magento module:enable VENDORNAME_MODULENAME ] */
    $moduleStatus = $objectManager->create('Magento\Framework\Module\Status')->setIsEnabled(true,$modules);

    /* Code to run setup upgrade [ php bin/magento setup:upgrade ] */
    $installerFactory = $objectManager->create('Magento\Setup\Test\Unit\Console\Command\UpgradeCommandTest')->testExecute();

    /* Code to clean cache [ php bin/magento:cache:clean ] */
        $_cacheTypeList = $objectManager->create('Magento\Framework\App\Cache\TypeListInterface');
        $_cacheFrontendPool = $objectManager->create('Magento\Framework\App\Cache\Frontend\Pool');
        $types = array('config','layout','block_html','collections','reflection','db_ddl','eav','config_integration','config_integration_api','full_page','translate','config_webservice');
        foreach ($types as $type) {
        foreach ($_cacheFrontendPool as $cacheFrontend) {
    }catch(Exception $e){
        echo $msg = 'Error during cache clean: '.$e->getMessage();die();
}catch(Exception $e){
    echo $msg = 'Error during module enabling : '.$e->getMessage();die();
  • Where to upload and run this codes? @Rahul.
    – larp
    Commented Sep 14, 2018 at 5:32
  • create your simple plugin and add controller Commented Sep 20, 2018 at 2:42
  • Then how to run this codes after creating a plugin?
    – larp
    Commented Sep 20, 2018 at 3:22
  • opps sorry your module already not enable .. Commented Sep 20, 2018 at 4:15
  • work with exciting enabled module Commented Sep 20, 2018 at 4:16

Add your module name in app/etc/config.php like as


Then run below code from root like as create file custom.php in root

Then run url like as below

http://your domain url/custom.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');
$k[1]='setup:upgrade'; // write your proper command like setup:upgrade,cache:enable etc...
try {
    $handler = new \Magento\Framework\App\ErrorHandler();
    set_error_handler([$handler, 'handler']);
    $application = new Magento\Framework\Console\Cli('Magento CLI');
} catch (\Exception $e) {
    while ($e) {
        echo $e->getMessage();
        echo $e->getTraceAsString();
        echo "\n\n";
        $e = $e->getPrevious();
  • So the code above will also be named 'Vendor_Module.php' ?
    – larp
    Commented Sep 14, 2018 at 6:04
  • see my post i have write file name and way of code run Commented Sep 14, 2018 at 6:05
  • what is your module name check in regisration.php file inside module Commented Sep 14, 2018 at 6:07
  • \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Vendor_Module', DIR ); this is the code inside registration.php
    – larp
    Commented Sep 14, 2018 at 6:29
  • After I run this codes it returns blank. No notification/message.
    – larp
    Commented Sep 14, 2018 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.