bash: php: command not found in VSC only - php

php -v works in individual terminals, but do not work in Visual Studio Code Terminal.
I tried php -v in Git Bash and Command Prompt in Windows, and all worked.
So I tried in VSC where I set default shell to Git Bash, but it shows error with bash: php: command not found
(I added php bin path to Path)
Terminal at VSC do not get PATH variable?

I got the same problem... My problem was in VSC FlatPack version available in the Software Manager in Mint 18.3. I uninstalled it and got the original version on https://code.visualstudio.com See more at: https://github.com/microsoft/vscode/issues/44646

Related

zsh: command not found: php. PHP is installed and working with MAMP

I am trying to use composer to install a google client library, but cannot install composer or use php on the command line.
I am using php 8.0.8 with MAMP and it is working fine, so I know it is installed.
If I type php in the terminal, I receive the command not found message. Thinking it could be an environment variable, I have tried navigating to the php folder /Applications/MAMP/bin/php/php8.0.8/lib/php and tried the php command again, but still get the same error
I am using a Mac running Monterey
Change default Mac OS X PHP to MAMP's PHP Installation and Install Composer Package Management
Instructions to Change PHP Installation
First, Lets find out what version of PHP we're running (To find out if it's the default version).
To do that, Within the terminal, Fire this command:
which php
This should output the path to the default PHP install which comes preinstalled by Mac OS X, by default it has to be (Assuming you've not changed it before):
/usr/bin/php
Now, We just need to swap this over to the PHP that is installed with MAMP, which is located at /Applications/MAMP/bin/php/php5.4.10/bin (MAMP 2.1.3)
To do this, We need to edit the .bash_profile and add the MAMP version of PHP to the PATH variable.
Follow these simple steps:
Within the Terminal, run vim ~/.bash_profile
Type i and then paste the following at the top of the file:
export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH
Hit ESC, Type :wq, and hit Enter
In Terminal, run source ~/.bash_profile
In Terminal, type in which php again and look for the updated string. If everything was successful, It should output the new path to MAMP PHP install.
In case it doesn't output the correct path, try closing the terminal window (exit fully) and open again, it should apply the changes (Restart in short).
Install Composer Package Management
Now you can fire the command to install the composer globally (So you can access it from anywhere):
$ curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
You can verify your installation worked by typing the following command within the Terminal:
composer
It'll show you the current version and a list of commands you can use if the installation was successful.
Original source

zsh: command not found: php with xampp

I installed xampp on Ubuntu 22.04.
Running .php files is ok.
Example directory like that.
/opt/lampp/htdocs//helloworld.php
That file worked and run in browser. But when I run php command on terminal, it gave me this error.
error image
I thought this error happened because zsh shell.So I add .zshrc file to this.
export PATH=<path-to-lampp>/bin/php/<php_version>/bin:$PATH
Still not working. Please help.
I got the solution. The problem is need to give symbol link i think.
My solution: run this command in terminal
$ sudo ln -s /opt/lampp/bin/php /usr/bin/php
Check if your PHP path is right, you should output PHP version by {PHP path} -v.
Do you source /.zshrc after changing the .zshrc file?

MAMP and PHP on Terminal

So I have installed MAMP and I am using PHP, however I also used Terminal with PHP as well. Now for some reason Terminal is not working with PHP anymore, for example:
Terminal / PHP command not found
So basically I can not work with anything at the moment. I have also simplified .bashrc and .bash_profile.
Terminal and PHP not found
Thanks. mac-machine
cd ~ && nano .zshrc
Add the path of php in .zshrc like:
export PATH=/Applications/MAMP/bin/php/php8.0.8/bin:$PATH
Then run source .zshrc and run php -v to confirm path setup
The problem is working with PHP command line is not found with ZSH, it gets a message: zsh: command not found: php.
So working with older BASH instead of ZSH it works fine.

$path in Netbeans does not contain /usr/local/bin when running/debugging php

I'm working with Netbeans 8.0.2 on Mac. I have problems with exec statements. Within netbeans it seems it can't find commands that are available in terminal.
For example I have this execute statement:
exec('mongorestore --host='.$this->host.' -d '.$this->db_name.' --dir '.$this->schemaPath);
If I run:php restore.php from terminal it runs without incident and imports the data. However if I run/debug/unittest from within netbeans output window shows:
sh: mongorestore: command not found
Other commands like mysqldump also have this issue. How can I make sure these command work from within Netbeans?
To be clear, I can run these commands in the terminal in netbeans, the problem only occurs if I run/debug/unittest a php file.
UPDATE:
Running some more test I find that the path variable is different for Netbeans.
terminal: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
netbeans: /usr/bin:/bin:/usr/sbin:/sbin

Phalcon devtools not working

I'm attempting to install Phalcon Dev Tools on OSX. I have Phalcon installed and it works fine.
I've followed the instructions from here: http://docs.phalconphp.com/en/latest/reference/mactools.html
When I run the command phalcon in the terminal I get the following output:
Phalcon Developer Tools Installer
Make sure phalcon.sh is in the same dir as phalcon.php and that you are running this with sudo or as root.
Installing Devtools...
Working dir is: /Users/me/phalcon-tools
Done. Devtools installed!
Now how do I use the devtools? When I enter phalcon commands the output is exactly the same as above, and continues to tell me that it's installed.
Am I missing something here?
I noticed in the phalcon.sh script, at the end it had:
if check_install; then
php "$PTOOLSPATH/phalcon.php" $*
fi
So, if check_install passes, run phalcon.php. I've tried to run this script manually and nothing happens at the terminal.
$PTOOLSPATH is defined. I confirmed this using echo $PTOOLSPATH.
My /usr/bin/env php is correct and points to MAMP's PHP. I have Phalcon installed using MAMP at the moment. My PHP is correct:
which php
/Applications/MAMP/bin/php/php5.5.23/bin/php
Inspecting the phalcon.php script, and using xdebug, I detected the issue to be lying here:
if (!extension_loaded('phalcon')) {
throw new Exception(
sprintf(
"Phalcon extension isn't installed, follow these instructions to install it: %s",
Script::DOC_INSTALL_URL
)
);
}
So the Phalcon extension isn't loaded. Not sure why it's not printing the output of the exception in the terminal. But, PHP's error log is showing:
[21-May-2015 22:37:48 Europe/Berlin] PHP Fatal error: Class 'Phalcon\Script' not found in /Users/me/phalcon-tools/phalcon.php on line 41
Now I'm stumped.
Edit:
Running php -m showed me Phalcon isn't installed. Which is odd, because I am using Phalcon in my web application, and it works fine. As you can see, I've loaded the extension in the php.ini.
The PHP version I'm using is:
PHP 5.5.23 (cli) (built: Apr 9 2015 19:29:27)
As you can see, Phalcon is in the correct directory:
ls /Applications/MAMP/bin/php/php5.5.23/lib/php/extensions/no-debug-non-zts-20121212
apcu.so
imagick.so
phalcon.so
...
And as you can see from phpinfo() it's installed ...
The following commands both give different results too:
Shows Phalcon as installed:
echo "<?php phpinfo(); ?>" | php > phpinfo.txt && cat phpinfo.txt | grep phalcon
Shows Phalcon not installed:
php -m
Any ideas?
After trying a lot, I found out that the code shown in the reference is wrong:
ln -s ~/phalcon-tools/phalcon.sh ~/phalcon-tools/phalcon
chmod +x ~/phalcon-tools/phalcon
The proper way can be found in the github repo:
ln -s ~/phalcon-devtools/phalcon.php /usr/bin/phalcon
chmod ugo+x /usr/bin/phalcon
Basically, the link shouldn't be the script but the php file. Fixing that, I could run the dev tool properly.
I have the same problem with you. and I solved it as long as I add this two line into my ~/.bash_profile file.
export PATH=$PATH:/Users/scott/phalcon-tools
export PTOOLSPATH=/Users/scott/phalcon-tools
At first, I only add the first line into .bash_profile, and I got the same information with you.
May be in command line ini file phalcon is not installed so it is throwing error.
just type this command in terminal .
php --ini
then check the output the interesting line is
Loaded Configuration File: /etc/php5/cli/php.ini
now try to check that
phalcon.so
is loaded there as well or not.
as for web and cli there are different phalcon.so file is provided so we need to inlcude "phalcon.so" in both files.
so phalcon.so is included in your web php.ini so its running smooth there and not it command line i guess.

Categories