How to run magento 2 commands through php scripts or browser

We can run the command by making a file(e.g. commands.php) in the root or pub directory and add a command like as below:

$command1 = 'php -dmemory_limit=1G bin/magento setup:upgrade';

$command2 = 'php -dmemory_limit=1G bin/magento setup:di:compile';

$command3 = 'php bin/magento setup:static-content:deploy en_US -f';

$command4 = 'php -dmemory_limit=1G bin/magento cache:clean';

 

echo shell_exec($command1);

echo shell_exec($command2);

echo shell_exec($command3);

echo shell_exec($command4);

?>

Upload this file to the root of your website and run  http:example.com/commands.php

You can also remove or comment the commands which you do not need to run.

If you cache clean command you will get output on the browser as below:

Cleaned cache types:

config

layout

block_html

collections

reflection

db_ddl

compiled_config

eav

customer_notification

config_integration

config_integration_api

google_product

full_page

config_webservice

translate

vertex

0   0
Eecrets Magento

Related Post

7th October 2020

Create a custom log file in Magento 2

Create a custom log file in Magento 2....

read more reply

7th October 2020

Magento 2 Direct SQL Queries in Zend Format

Sometimes due to some project requirments, we need to directly communicate with Magento2 Database and we have to write SQL queries for that.....

read more reply

11th June 2020

Issues in upgrading magento 2 to latest versions

Share your issues/suggestions for upgrade Magento 2 to the latest versions.....

read more reply

List Your Business

Improve Your Business Visibility

Please rotate your device

We don't support landscape mode on your device. Please rotate to portrait mode for the best view of our site