How to run Shell Using PHP using the bash compiler

0

I would like to know how to run PHP in Shell using Bash . I tried this way but it made an error:

#/usr/bin/php
<?php
echo 'Olá Mundo';

?>
    
asked by anonymous 03.05.2018 / 04:44

1 answer

1

You must use #! (with exclamation). This way you will be defining the software that will interpret the written code, for example: #!/usr/bin/php

At run time you need to check the file permissions. For the code to run, the user must have execute permission. To check the permissions to use ls -l nome-do-arquivo.php

-rwxr-xr-x 1 root root 45 May  3 02:56 ./nome-do-arquivo.php*

You must have x . This informs you that the file can be executed. If x does not appear, just run the code below.

sudo chmod +x nome-do-arquivo.php

filename.php

#!/usr/bin/php
<?php
    echo 'Olá Mundo';
?>
  

/ usr / bin / php: bad interpreter: No such file or directory

If you get the above error, just run the following code which php in the terminal. This code will return the path of the PHP interpreter, hence just add in #!<caminho informado>

    
03.05.2018 / 05:00