Make `php` recognized as a command in terminal
12,113
You can create a symlink in /usr/bin
to the PHP binary/executable file.
sudo ln -s /opt/lampp/bin/php-5.3.8 /usr/bin/php
should create a symlink to the executable that exists within /usr/bin, and should allow you to call 'php' from the command line without making an /etc/init.d/ entry.
Related videos on Youtube
Author by
Thomas Ward
Updated on September 18, 2022Comments
-
Thomas Ward over 1 year
I have
XAMPP
installed and my PHP is:/opt/lampp/bin/php-5.3.8
Every time I need to execute a PHP file I need to do this:
/opt/lampp/bin/php-5.3.8 testando.php
Is there another way to execute it besides using symbolic link?
I did this on
/etc/init.d/
:sudo ln -s /opt/lampp/bin/php-5.3.8 php
Why when I need to run PHP I have to do this
./php
instead of justphp
?And is there a way to do this without the
./
? Like it was installed viaapt-get
?-
Thomas Ward almost 12 yearsinclude the output of
echo $PATH
please -
Eliah Kagan over 11 yearsQuestions that are about Linux Mint (as you said is what you're running, in a comment to Lord of Time's answer) and not about Ubuntu are off-topic. You should instead ask this somewhere Linux Mint is supported, like the Linux Mint Forums or Unix.SE.
-
-
Admin almost 12 yearsThat worked but can you explain what is the difference between creating symlink on each folder?
-
Thomas Ward almost 12 yearsThe way that executable names get run in Bash (or ZSH, or others) is based upon there being either a link or an executable in a folder that is specified in
$PATH
(btw, please add that to your question's content, see comment to the question). When such executables do not exist in a folder specified in$PATH
, you have to use the entire path to the executable to work. By adding that sym link to /usr/bin, the system then recognizesphp
alone as a command/program. When in the program's folder, though,./progname
:./
= currentdir,progname
= program/executable; Run progname from here. -
Admin almost 12 yearshow do I
echo $PATH
tried it on terminal and creating a file but it gave me this:Notice: Undefined variable: PATH
-
Thomas Ward almost 12 yearshmm, that's odd. is this Ubuntu or some other distro?
-
Admin almost 12 yearsI'm using Mint.
-
Thomas Ward almost 12 yearsah, well that's different. Let me (for future reference) point you to the FAQ:
This is not the right place for: Linux Mint, Backtrack, and other Linux distributions (try our friends at Unix & Linux Stack Exchange).
Ask on U&L in future given that Mint isnt supported here. MODS: Do not move this from Ask Ubuntu please, it does have relevance here even though the OS being used is Mint (this is common in non-apt installed software in all debian distros, so it does have relevence to Ubuntu). -
Thomas Ward almost 12 years$PATH points to where executables are, so the lack of a $PATH doesn't really mean much (since /bin and /usr/bin are both defaults for binaries).
-
Csabi Vidó almost 12 yearsThis is because of the file system hierarchy standard which describes where resources and executables have to be placed in the file system. Instead of
/usr/bin
recommended locations are/usr/local/bin
or~/bin
. -
Thomas Ward almost 12 years@LiveWireBT true, but without
$PATH
it won't be identified in those locations. in ubuntu, the php package installs to /bin, but they're using Mint (Ubuntu 12.04 ships with PHP 5.3.8) -
Čamo over 2 yearsI can not find the bin directory in etc/php/php7.4 nor others. Dont understand where to find the binaries.