5

In Magento when we run any command we use 'php bin/magento' and sometimes it runs also with 'bin/magento'

So can any one explain what is the actual difference in these commands.

3 Answers 3

13

There is no difference between these two command.

php bin/magento

php bin/magento command you are using php global variable to run command. for example if you are not set the global variable then you can give path of php like /opt/lampp/bin/php bin/magento to run the magento command.

bin/magento

bin/magento command will find the golbal php variable and use that,

Note: in both cases it will use the php variable

2

Its same things :)

But generaly adding PHP you can choose to add command line option see PHP features commandline options

php -c /custom/directory/custom-file.ini bin/magento [command]

By omitting it ... it is the default version of the system that is used

It is better to launch the magento binary with the same version as the one used with the WEB server, do not forget that in command line we are in CLI

you can see something like this on debian... depending of your compilation and version

#php -v
PHP 7.1.20-1+0~20180725103315.2+stretch~1.gbpd5b650 (cli) (built: Jul 25 2018 10:33:20) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.20-1+0~20180725103315.2+stretch~1.gbpd5b650, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans
0

The php bin/magento command is the recommended way to execute Magento CLI commands, as it allows you to specify the PHP version you want to use.

For example:

  • To run the command using PHP 7.4: php7.4 bin/magento c:f
  • To run the command using PHP 8.1: php8.1 bin/magento c:f

By prefixing the bin/magento command with php followed by the desired PHP version, you ensure that the command is executed using the specified PHP version. This is particularly useful when you have multiple PHP versions installed on your system and need to specify the one compatible with your Magento installation.

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.