What's the status of PHP PATH now?

Asked 2 years ago, Updated 2 years ago, 84 views

If you follow the instructions on the Internet to get through the PHP PATH,

$whichphp
/Applications/MAMP/bin/php/php 5.4.10/bin/php
$ php-v
PHP 5.4.10(cli)(build:...tec.

I succeeded, but when I checked it again,

$whichphp...no response
$ php-v...command not found

said he.
How is it now?
How should I modify it?

cat to /.bash_profile

No response

cat to /.bashrc
cat:/Users/youtenyu/.bashrc: No such file or directory

appears.

export PATH=$PATH:/Applications/MAMP/bin/php/php5.4.10/bin 
exec $SHELL-l 
which php 
php-v 
bash:php:command not found

After putting them in this order, bash:php:command not found appeared at the end.

php macos bash command-line mamp

2022-09-30 17:55

2 Answers

PATH is called an environment variable, and the shell program bash looks for commands in the directory you set for the environment variable PATH.

How is it now?

export is the command for setting environment variables, but when you exit the shell program, any changes made in export are discarded.
Therefore, even if you run php-v, the shell program cannot find the php command and displays the error command not found.

How should I modify it?

The export command is executed every time you log in (or open a terminal) by describing the export PATH=... command in the through /.bash_profile file.

~/.bash_profile examples

$cat~/.bash_profile← File is empty and nothing is displayed
$ echo "export PATH=\$PATH:/Applications/MAMP/bin/php/php5.4.10/bin">~/.bash_profile
$ cat to /.bash_profile
Verify that export PATH=$PATH:/Applications/MAMP/bin/php/php5.4.10/bin← file has been added.

Load through /.bash_profile for verification.

$echo$PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin←View the value of the environment variable PATH before loading
$ .~/.bash_profile
$ echo$PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/MAMP/bin/php/php5.4.10/bin ← directory added to environment variable PATH

If :/Applications/MAMP/bin/php/php5.4.10/bin is added at the end, it is successful.

When you open a new terminal, ~/.bash_profile is automatically loaded, so you should be able to confirm that the contents of the PATH have changed.

Last login:Thu Dec 10 13:48:24 on ttys002
mymac:~take88$echo$PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/MAMP/bin/php/php5.4.10/bin ← Verify PATH changed automatically


2022-09-30 17:55

http://webkaru.net/php/mamp-php-bin-path/

Review the instructions in the .

~/.bash_profile must include:

export PATH=$PATH:/Applications/MAMP/bin/php/php5.4.10/bin

By the way, the URL above says source~/.bash_profile, but I think exec$SHELL-l is better.


2022-09-30 17:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.