sudo: pear: command not found - php

I have snow leopard which apparently has php with pear pre-installed. I enabled php but could not find any signs of PEAR. So I have installed it and now phpinfo() shows its installation
include_path .:/usr/lib/php/share/pear
Still when I type in any pear command
$ sudo pear
I get an error: sudo: pear: command not found
What am I missing?

Many ways to skin this cat, but I would type this if you have locate installed (which you probably do):
$ locate bin/pear
That should list one or more things, one of which will look like the path to pear. Let's say it says something like /usr/local/bin/pear. Then your next command is:
$ sudo /usr/local/bin/pear
Two caveats come to mind:
It's possible that locate will list multiple executable pear files. If that's the case, it may be important to pick the right one based on which PHP you're using.
You may want to add the directory where pear is located to your PATH environment variable.

You need to update your system $PATH variable in order for the pear command to work. Edit the bash profile file using the following(if you have textmate):
mate ~/.bash_profile
and add in this line:
export PATH=/usr/local/pear/bin:$PATH
reload your terminal after that and it should work now
Edited:
Thanks for highlighting my mistake trott. I have changed the path to locate where the bin should roughly be(depending on where one chooses to install it)

If you have installed pear directly on PHP (MAMP, for example) you should copy pear to /usr/local/bin:
cp /php5.3.2/pear /usr/local/bin/pear
then export var PATH, and test with "pear" in the shell.

I had a similar issue and required updating secure_path in sudoers as it overrides user's $PATH.
Check for secure_path on sudo
[root#host ~]# sudo -V | grep 'Value to override'
Value to override user's $PATH with: /sbin:/bin:/usr/sbin:/usr/bin
If $PATH is being overriden us visudo and edit /etc/sudoers
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

Related

Composer missing after upgrading to OS X 10.11 El Captian

So simply put. I did an in-place update from 10.10.5 to 10.11.1 recently and just discovered that my composer package manager is no longer working.
I've tried a number of solutions and have it installed into the correct directory, but my alias 'composer' which was set globally is now not able to find the composer file.
Following the steps as always
First, Download
curl -sS https://getcomposer.org/installer | php
Then move
sudo mv composer.phar /usr/local/bin/
Then update bash_profile
vim ~/.bash_profile
Finally add alias
alias composer="php /usr/local/bin/composer.phar"
And my end result, when calling composer is this
Could not open input file: /usr/local/bin/composer/
Any ideas why this might happen?
Found the answer by talking to someone on reddit.
///
First off, try going to the composer file in /usr/local/bin and double-click it. It should open up in a new Terminal window. This should at least confirm that the file can be executed.
Second, you shouldn't need to have an alias to use composer. You merely point your path to it like this:
export PATH="~/.composer/vendor/bin:$PATH"
If you have any other path variables you'll just attach a colon to the end of it like so:
export PATH="/usr/local/php5/bin:~/.composer/vendor/bin:$PATH"
Hope this helps.

How to install PHPUnit with WAMP?

I'm a newbie programmer and I have tried for an embarrassingly long time to get PHPUnit set up and working with WAMP. I have read the documentation and went through various sites to see what I'm doing wrong, but I give up! I need someone to explain this to me in simple terms.
I've probably seen all the guides on how to set it up, but feel free to link me to something you believe is foolproof!
Try this blog : http://nishutayaltech.blogspot.com/2011/04/installing-phpunit-on-windows.html
This setup is for Windows. Hope this will help you.
Also check this out, may be useful http://www.mark-leong.com/installing-php-and-phpunit-on-windows-7/
// adding required pear channels
pear channel-update pear.php.net
pear upgrade-all
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear update-channels
// performing install
pear install --alldeps --force phpunit/PHPUnit
If everything ok, check whether phpunit have been installed by putting in command line
phpunit -v
If you encountered any errors or interrupted installing
pear clear-cache
may be usefull in that case.
1) download https://phar.phpunit.de/phpunit.phar
2) run it via php phpunit.phar
Btw if that file ever goes away you can look at the original directions here: https://github.com/sebastianbergmann/phpunit
I recommend using composer. It can be used per project, but also 'globally'.
Make a folder on your C drive called 'globalpackages', then cd into it from the command line.
run 'composer require phpunit/phpunit'
once that finishes run 'composer install'
once that finishes you can check the contents of C:\globalpackages\vendor\phpunit' and should see two phpunit files, one of them a bat.
Add C:\globalpackages\vendor\phpunit to your system path and then you will be able to run phpuni from anywhere on your system.
For me this is the fastests and easiest way.
Make sure you have wamp with WAMP with PHP 7 installed as phpunit requires PHP7 to work! or at least 6.2
Go to folder
wamp64\bin\php\php7.0.10
(wherever you installed your wamp - BEWARE last folder is name of PHP version you have so it might be different then above )
We will be working in this folder during entire installation. So if I say edit file etc it means in this folder.
Download newest version of phpunit from https://phpunit.de/
At the time of writing this I get version phpunit 6.2 and php7.0.10
4. Copy downloaded file to wamp64\bin\php\php7.0.10 folder
For me it's: phpunit-6.2.2.phar
for you it might be different version.
Now change name of the phpunit-6.2.2.phar to phpunit.phar
Now make sure you have added your php to PATH in Environment Variables
To do this on Windows 10 and Windows 8
6a. In Search, search for and then select: System (Control Panel)
6b. Click the Advanced system settings link.
6c. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
6d. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Paste location of your PHP. For me it would be: D:\AnyFolderYouInsalledWampTo\wamp64\bin\php\php7.0.10
(if in PATH there was other command or path just add ";" at the end. For exmaple:
%someOtherCommand%; D:\AnyFolderYouInsalledWampTo\wamp64\bin\php\php7.0.10)
6e. Click OK. Close all remaining windows by clicking OK.
In cmd (to run cmd go to search in Windows and type cmd.exe and click Enter)
go to folder wamp64\bin\php\php7.0.10
(to go to folder type for example cd D:\AnyFolderYouInsalledWampTo\wamp64\bin\php\php7.0.10)
now once you are in this folder run this command in cmd:
echo #php "%~dp0phpunit.phar" %* > phpunit.cmd
now run this command:
phpunit
you should get list of all commands available in phpunit
now run this:
phpunit --check-version
you will get info what phpunit version you have and if you are using the newest version.
if this doesn't work go to wamp64\bin\php\php7.0.10
Edit file phpunit.bat
Add this line:
""%PHPBIN%" "D:\AnyFolderYouInsalledWampTo\wamp64\bin\php\php7.0.10\phpunit.phar" %*
Repeat point 9.
if it still doesn't work let me know.
Very well done, Emil! You're a star! Perfect answer to install PHPUnit with WAMP on Windows. Look no further than Emil.
https://stackoverflow.com/users/5753967/emil

cannot get phing to run at all

Max OS X 10.7.. when i run phing -v i get the following errors:
Warning: require_once(phing/Project.php): failed to open stream: No such file or directory in /usr/lib/php/pear/phing/Phing.php on line 22
Fatal error: require_once(): Failed opening required 'phing/Project.php' (include_path='.:') in /usr/lib/php/pear/phing/Phing.php on line 22
Here are the commands i used:
pear config-set auto_discover 1
pear install phing/phing
Here is my php.ini:
include_path = ".:/Applications/MAMP/bin/php/php5.3.6/lib/php"
running whereis for php, pear, and phing returns:
bash-3.2$ whereis php
/usr/bin/php
bash-3.2$ whereis pear
/usr/bin/pear
bash-3.2$ whereis phing
/usr/bin/phing
running config-get for pear returns:
→ pear config-get php_dir
/usr/lib/php/pear
checking this folder, system.php and phing.php both exist in this path.
Seems like include_path is somehow broken.
Check PEAR's directory:
pear config-get php_dir
/usr/lib/php
Whatever directory is returned, it should contain PEAR files (System.php and phing files in particular)
Check that correct php.ini is used:
Run php --ini and see what INI file is being loaded. Then make sure this INI files contains PEAR directory in it's include_path
Check include_path:
Run php -c /path/to/php.ini -r 'echo get_include_path() . "\n";'.
Update
The problem is indeed with include_path since the error message reports (include_path='.:') which clearly shows that PEAR is NOT in your include path. This means that wrong php.ini is being loaded for CLI PHP. To fix it, find correct php.ini file (step 2) and add
include_path = ".:/usr/lib/php/pear"
to it.
I solve it simple ...
i'm configuring my /etc/paths to include propel generator on my path ambient.
then i add /Application/XAMPP/bin and /Application/XAMPP/Propel/generator/bin
i was getting that include error. Mac system comes with php preinstalled ... so, propel generator was getting wrong php installation.
I solve it simple ... i just changed the order of /etc/paths folders ...
as you see my /etc/paths file:
/Applications/XAMPP/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
/Applications/XAMPP/Propel/generator/bin
Just Want to add one more easier solution for mac LION users (those who install stuff via macport ) , might work for leopard too
download this script anywhere, doesn't matter where it is
curl http://pear.php.net/go-pear.phar > go-pear.phar
run this command
sudo php -q go-pear.phar
it will ask you the paths, you shouldn't need to change it, but just check these paths contains any pear related files.
it will ask you if you want to update php.ini for you with these includes path [Y]
you are done! type phing and you should ask for your build.xml
Or if you don't have access to the server, you can do this:
$root = $SERVER['DOCUMENT_ROOT'];
It'll always reference the root of your project, and you can then reference the folder/file from that.
You don't have to touch the server if done that way.

Wamp 2.2 install PEAR

My operating system is Windows 7.
I got my WAMP2.2 install in my computer.
Then I try to install PEAR.
However, I can not find my go-pear.bat file in my wamp directory.
Fine. I download in here: http://pear.php.net/go-pear.phar
and install using this file.
I put the file in
C:/wamp/bin/php/php5.3.8/pear/go-pear.phar
Run the command: php -d phar.require_hash=0 PEAR/go-pear.phar
After the installation, I include the path of pear in php.ini in php and apache folder.
I also include C:/wamp/bin/php/php5.3.8/ in windows $PATH variable.
But when I run pear command. It said it can not find the pear command.
I check the folder and just find a file called pear.bat and pear.ini.
I tried to run pear.bat again in command line. It still does not work.
Experts, please help on this issue.
Ok since many people may be asking the same thing. Let's suppose the following.
I'm currently running 2.2 E which includes Apache 2.2.22 – Mysql 5.5.24 – PHP 5.3.13 XDebug 2.1.2 XDC 1.5 PhpMyadmin 3.4.10.1 SQLBuddy 1.3.3 webGrind 1.0
Now, to install PEAR do the following:
Download this file:
http://pear.php.net/go-pear.phar
And put it on your WAMP server directory under the PHP version on the bin folder.
Run the command to install PEAR and you're over it.
Example (defaults, no change has been done)
Get the file on the link ->http://pear.php.net/go-pear.phar
Go to this directory C:\wamp\bin\php\php5.3.13
Open command prompt (cmd.exe). Supposing you're using Windows Vista and higher, press Start, type "cmd.exe" and right click on it and select run as administrator/CTRL+SHIFT+Enter (Haven't tested on non-priviliges rights)
Use Window's cd command to change the directory to the go-pear.phar file you've just downloaded. In my case I'll be pin pointing it to my own directory, so I did it like follows:
cd "C:\wamp\bin\php\php5.3.13"
Press Enter. You should note that instead of saying "C:\system\32" is now displaying C:\wamp\bin\php\php5.3.13
Write the following command and press Enter:
php -d phar.require_hash=0 go-pear.phar
Select whether you like or not a local copy or a system one. By typing system:local and pressing enter you'll install a local copy. By typing system and pressing enter you'll install a system-wide copy.
Type yes to confirm the option chosen.
The next list of directories, will be the referring directories that PEAR will install its components. If you select from 1 - 12 you can change the directory you'd like to install. By typing all and pressing Enter you'll be able to change them all in a queued manner. In my case, I just pressed Enter and left all defaults
DO THE FOLLOWING IN CASE YOU CONTINUE TO HAVE SOME LISTINGS
11. It is very probable that afterwards you'll receive a message like:
WARNING! The include+path defined in the currently used php.ini does not contain the PEAR PHP directory you just specified: If the specified directory is also not in the include_path used by your scripts, you will have problems getting any PEAR packages working.
Below it will also appear:
Would you like to alter php.ini ? [Y/n]:
Type y and press enter
This should put you running with PEAR on WAMP server :)
pear.bat is the executable on windows. You have to put that directory in your system's PATH variable for the command to be recognized.
All the steps mentioned to below link for GUI based - easy understanding review and setup:
Click here
For anyone looking for a more current answer. On Windows 10 I had to edit .bash_profile to add the following:
function __pear {
pear.bat $#
}
alias pear=__pear

How to use MAMP's version of PHP instead of the default on OSX

I would like to use MAMP's version of PHP instead of the default installed on my mac. I tried using
ln -s /Applications/MAMP/bin/php5.3/bin/php php
but I get a "File exists" error. What's the best way to work around this so I can just type php instead of the full path?
I have created a symlink at the original php location.
1. Locate your osx php version with:
which php
The result should be:
/opt/local/bin/php
2. Backup (move) your original php binary:
sudo mv /opt/local/bin/php /opt/local/bin/php.bak
3. Create the symlink:
sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /opt/local/bin/php
4. Run your new php version:
php -v
PS:
In order for this to work on El-Capitan
Reboot your Mac to RecoveryMode (hold Cmd+R on boot)
Open Terminal and enter: csrutil disable
Reboot
either : sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /opt/local/bin/php
or sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /usr/bin/php
Reboot again to RecoveryMode and re-enable security: csrutil enable
I would not recommend trying to modify the default version of PHP that is called on the command line. Doing so may break other parts of your system as well as provide you with problems in the future, should you decide to upgrade your OS.
There is an alternative that may meet your needs. You can create an alias to your copy of MAMP's php 5.3. In my case I named the alias phpmamp. Open your terminal and type:
alias phpmamp='/Applications/MAMP/bin/php5.3/bin/php'
Now, typing phpmamp at the command line will launch the MAMP php interperter. Verify this by typing:
phpmamp --help
You will most likely want to store this, and any other alias, in a ~/.bash_profile This will allow the aliases to persist across reboots. Otherwise, the alias should only last for the particular terminal session you are in. More information about creating a .bash_profile file can be found here:
http://www.redfinsolutions.com/redfin-blog/creating-bashprofile-your-mac
I prefer not to tamper with the current files, so I just prepend the MAMP PHP bin folder to the $PATH env variable.
You can edit ~/.bash_profile and add the the following line to the top
export PATH="/Applications/MAMP/bin/php/php5.6.1/bin:$PATH"
Just change the PHP version to the current version you are using.
Don't forget to do source ~/.bash_profile after you edit the file.
I wasn't pleased with the results / solutions I've found on the net so far, because the php.ini configs weren't loaded properly in all cases and on all systems, espacially when you need modules like ioncube and others (it's even more confusing on MAMP Pro). That's why I've created my own php version aliases (with configs), so I've come up with the following solution, as example (based on MAMP Pro, remember to adjust the php.ini paths to your needs):
Edit your .bash_profile
vim ~/.bash_profile
And add the following entries:
alias php55="/Applications/MAMP/bin/php/php5.5.26/bin/php -c '/Library/Application Support/appsolute/MAMP PRO/conf/php5.5.26.ini'"
alias php56="/Applications/MAMP/bin/php/php5.6.10/bin/php -c '/Library/Application Support/appsolute/MAMP PRO/conf/php5.6.10.ini'"
alias php56cgi="/Applications/MAMP/bin/php/php5.6.10/bin/php-cgi -c '/Library/Application Support/appsolute/MAMP PRO/conf/php5.6.10.ini'"
Re-Initialize the .bash_profile in the current terminal session (otherwise you won't see any changes, unless you restart the terminal):
source ~/.bash_profile
If you have some additional modules installed, then you can test it with php56 -v and you should get a output of the ioncube, etc. modules. Otherwise test it with php56 -i | grep "yourModuleNameOrSomethingElse"
Now you are able to easily use one of the php versions like "php56" in your terminal with all configs loaded. So it's perfect for testing and building your applications through all iterations of versions including the right php.ini configs through the terminal.
For normal MAMP Users, the configs should be located in /Applications/MAMP/conf/ I think. Happy programming.
2021 - For those using ohmyzsh, the file to edit is:
/Users/your_user/.zshrc
so, you can edit this file and add the path:
export PATH=/Applications/MAMP/bin/php/php8.0.0/bin:$PATH
Works Perfectly with Big Sur
The latest version of MAMP (Version 5+) offers an easy way to make the MAMP PHP version available to the command line. Just select "PHP" in the the side bar menu and check "Make this version available on the command line". Easy peasy! :)
screenshot
If your terminal is using zsh (oh-my-zosh) as shown in the attachment.
check image
Do the following.
Mac Big Sur uses "zsh" Oh-my-zosh for the terminal. so, I did the following.
open terminal.
check if you have .zshrc file in your profile path (/Users/yourProfileName)
if you don't have .zshrc file, create one using (~ touch .zshrc) command.
add these lines:
export MAMP_PHP=/Applications/MAMP/bin/php/php7.4.12/bin
export PATH="$MAMP_PHP:$PATH"
save the file. close the terminal and reopen it. Now run "which php".
let me know if you need help.
For Mac OS Catalina. Find directory /Users/<user_name>/.zprofile
and add (for example)
# MAMP PRO PHP
export PATH="/Applications/MAMP/bin/php/php7.4.2/bin:$PATH"
after reboot, in terminal
which php
new php version /Applications/MAMP/bin/php/php7.4.2/bin/php
Well, the 'file exists' error is probably because you attempted to create a sym-link with the name of a file that was already there. I assume you were in the directory containing the php version you were trying to replace or that this was a second attempt and you did not first remove the existing sym-link. I agree with the others with regard to not "replacing/modifying" the default version of php.
Based on the second part of the question, the best way to get around having to type the full path, the answers suggesting an alias are right on point with that. When multiple versions are involved though, that means having to call something other than php to run the version you want to run.
I have a script that lets me "select" the version of php that I would like to work with which then creates a sym-link to that version and lets me simply enter 'php' as my command when I want to use it. I wrote a blog about it here where you can get the script. Based on the answer given by #ioCron I may need to revisit my script to account for the different config folders associated with each version.
Well none of this was working for me with OSX10.12.5
i have mac ports php70 installed at /opt/local/bin
which php showed:
/usr/bin/php
I set up the aliases and local paths etc, which mostly worked for me, but other programs were failing (like composer) so the solution for me was to prepend:
/opt/local/bin
/opt/local/sbin
to the file /etc/paths
then it all worked a charm!

Categories