Using PHP in the terminal, xampp

Asked

Viewed 744 times

2

I’m trying to use PHP through the terminal, but I can’t, when I type which php he returns /usr/bin/php so I can’t run PHP files, because it can’t find the files.

I am using XAMPP for MAC

1 answer

4


At the root of your user folder, ~, has a file called .bash_profile. Add the following at the end of it:

export PATH="/applications/XAMPP/xamppfiles/bin:$PATH"

Save the file and restart the terminal. Now the which php should indicate php-cli of XAMPP.


Alternative #1

To call an executable from a specific directory, just type in the full path to it. Instead of

php meuscript.php

wear like this:

/Applications/XAMPP/xamppfiles/bin/php meuscript.php

Alternative #2

Navigating to the folder where is the PHP of XAMPP, and running from there:

cd /Applications/XAMPP/xamppfiles/bin
php meuarquivo.php
  • how do I meet and add? I’m not familiar

  • which code editor you use?

  • I use the Brackets

  • 1

    In Brackets, type +O, navigate to your user folder (the one with your name in the left bar), and choose the file .bash_profile. If it doesn’t exist there, create one with that name.

  • An extra question, I include several files in my meuarquivo.php (require) when access it on the web runs normally but when it is through the terminal it does not find the files... this has logic?

  • 1

    You’d better ask a separate question about that, @Elaine. It might have to do with PHP configuration.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.