I am using MAMP for development. I have never been able to get PEAR to work. The MAMP documentation and forums seem not to have the answers. Everybody who asked on the MAMP forum seems to have no replies.
Previously I have developed the systems on MAMP and only used PEAR for mail so I got it working once on the server rather than in MAMP. I want to use more of PEAR now.
Can anybody give me an idiots guide to getting it going. I can access terminal and type command lines, however, I don't really understand what's going on so when things stop or throw errors I have to ask more questions. I have had a go with various things found on the internet but failed so far.
MAMP is version 1.9.5 Mac OS 10.6.7
#Marcelo Rodrigo's answer is great! And I'm glad he included his sources. By following sources of his sources I was able to find the information below.
Install PEAR on MAMP
In order to get PEAR working with MAMP run the following commands. Notice there are commands for MAMP v1.x.x and for newer versions. Find out what version you are running. Also, notice that the PHP versions differ. Make sure the version in the commands below is the one you are actually using. MAMP allows you to change versions. You can check by opening MAMP > Server > PHP.
NOTE:
This may be obvious to some, but you should stop MAMP first. Otherwise you might get some strange errors.
1) Change the directory permissions so you can execute files within them:
MAMP v2.x.x
chmod 774 /Applications/MAMP/bin/php/php5.4.4/bin/pear
chmod 774 /Applications/MAMP/bin/php/php5.4.4/bin/php
MAMP v1.x.x
chmod 774 /Applications/MAMP/bin/php5.3/bin/pear
chmod 774 /Applications/MAMP/bin/php5.3/bin/php
2) Setup an alias to avoid typing the whole path.
Every time you want to access pear you have to type "/Applications/MAMP/bin/php5.3/bin/pear". Typing "pear" referes to what is installed on your mac already and not MAMP's install. (This only apply for the current session. For a permanent alias, place the command below in your ~/.bash_profile file. Here is a tutorial on how to do that.)
MAMP v2.x.x
alias mpear="/Applications/MAMP/bin/php/php5.4.4/bin/pear"
MAMP v1.x.x
alias mpear="/Applications/MAMP/bin/php5.3/bin/pear"
3) Make a link between php5 and php5.3 folders (Not Needed for MAMP v2.x.x):
Pear gets confused about its version because it installs in both php5.3 and php5 directory
When you upgrade pear it will create a new /Application/MAMP/bin/php5 directory and spread files between php5.3 and php5 folders. Use the code below to make a link between the two file so they act as one. More info about "ln" command. Source: #Marcelo Rodrigo's post
ln -s php5.3 php5
4) Check to make sure pear is working:
mpear -V
5) Now upgrade pear:
mpear channel-update pear.php.net
mpear upgrade pear
6) And check again to see if it upgraded pear correctly
mpear -V
Install PHPUnit
You do not need to install PHPUnit. If mpear -V worked for you, then you are done installing PEAR on MAMP. For my development environment I needed PHPUnit for unit testing, so I figured I would include a tutorial to install PHPUnit now that we have PEAR working. Only do this if you need PHPUnit. If you don't know what it is, you don't need it.
Run the following commands:
1) Install PHPUnit:
NOTE: Below I am using "mpear" which is actually an alias I setup in step 2 above. You could simply use "/Applications/MAMP/bin/php5.3/bin/pear" in its place.
mpear config-set auto_discover 1
mpear install pear.phpunit.de/PHPUnit
Source: http://www.phpunit.de/manual/current/en/installation.html
2) Allow MAMP to use PHPUnit
Link your MAMP's install of phpunit with the default phpunit location. (Doesn't work with Mountain Lion, instead see step 2a)
sudo ln -s /Applications/MAMP/bin/php5/bin/phpunit /usr/local/bin/phpunit
**2a) For Mountain Lion Only - Create a symobolic link between MAMP's php.ini and the php.ini in /etc
sudo ln -s /Applications/MAMP/bin/php/php5.4.4/conf/php.ini /etc/php.ini
If it says files exists, make a backup of /etc/php.ini and delete it.
3) Make sure it works
phpunit --version
For details about installing phpunit check out:
http://jeffreybarke.net/2010/08/how-to-install-phpunit-with-mamp/
http://www.phpunit.de/manual/current/en/installation.html
http://d.hatena.ne.jp/Kenji_s/20120117/1326763908
Sources:
http://jeffreybarke.net/2010/08/how-to-install-phpunit-with-mamp/
http://forum.mamp.info/viewtopic.php?f=2&t=8465#p20375
#Marcelo Rodrigo's Answer
If you just want phpunit to work, use the following commands on a fresh copy of MAMP 1.9.5:
cd /Applications/MAMP/bin
ln -s php5.3 php5
php5/bin/pear channel-discover pear.phpunit.de
php5/bin/pear channel-discover components.ez.no
php5/bin/pear channel-discover pear.symfony-project.com
php5/bin/pear channel-update pear.php.net
php5/bin/pear upgrade pear
php5/bin/pear install phpunit/PHPUnit
ln -s /Applications/MAMP/bin/php5/bin/phpunit /usr/local/bin/phpunit
phpunit --version
Done.
The above code fixes the following issues:
Bug 1:
pear gets confused about its version because it installs in both php5.3 and php5 directory
Pear updates upgrades and installs from /Applications/MAMP/bin/php5.3/pear, but it will create a new /Application/MAMP/bin/php5 directory and spread files between the php5.3 direct and the new php5 directory and get very confused about what version it is.
Fix:
ln -s php5.3 php5
I think that if you are using PHP 5.2 then using ln -s php5.2 php5 should work equally well but I haven't tested this
Issue 2:
pear is out of date
this is understandable of the MAMP team, the problem really was that it was difficult to do a upgrade because of Bug 1
Source: http://forum.mamp.info/viewtopic.php?f=6&t=11102
I recently found the following link correctly setup my MAMP 2.1.1 running:
PEAR Version: 1.9.4
PHP Version: 5.4.4
Zend Engine Version: 2.4.0
Try:
sudo /Applications/MAMP/bin/php/php5.4.4/bin/pear config-set auto_discover 1
sudo /Applications/MAMP/bin/php/php5.4.4/bin/pear install pear.phpunit.de/PHPUnit
To make it available on the command line everywhere you need to create a soft-line to phpunit in your local bin.
sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/phpunit /usr/local/bin/phpunit
Now try:
phpunit --version
Confirm it works try it from here: /Applications/MAMP/bin/php/php5.4.4/bin/
Confirm the symlink worked. Try it somewhere else like ~/ or /.
If they both worked you are ready to code.
SOURCE/CREDIT: Enej Bajgoric Web Developer, CTLT UBC Vancouver Canada at http://blogs.ubc.ca/enej/2012/10/01/installing-phpunit-on-mamps/
Related
sudo php -d detect_unicode=0 go-pear.phar
Unable to create PHP code directory ($php_dir) /usr/share/pear.
Do I need to change permissions on /usr/share? Current permissions are drwxr-xr-x
The /usr folder is protected.
You can disable SIP, but this is not the best option.
You can select 1 for the "Installation base" and change the directory to
/usr/local
Then it will apply to all other addresses.
Take a look on this other question
https://apple.stackexchange.com/questions/237778/cant-write-to-usr-even-with-sudo
From this link: http://jason.pureconcepts.net/2012/10/install-pear-pecl-mac-os-x/
With this instructions, you don't need to disable 'System Integrity Protection'
The following instructions install PEAR and PECL on Mac OS X under /usr/local/. PECL is bundled with PEAR. So this is as simple as installing PEAR on Mac OS X.
PEAR is PHP’s Package Repository and makes it easy to download and install PHP tools like PHPUnit and XDebug. I specifically recommend these two for every PHP developer.
Download PEAR
curl -O http://pear.php.net/go-pear.phar
sudo php -d detect_unicode=0 go-pear.phar
Configure and Install PEAR
You should now be at a prompt to configure PEAR.
Type 1 and press return.
Enter: /usr/local/pear
Type 4 and press return.
Enter: /usr/local/bin
Press return
Verify PEAR. You should be able to type:
pear version
Eventually, if you use any extensions or applications from PEAR, you may need to update PHP’s include path.
I've upgraded to Mountain Lion and installed php5.4 which took a bit of tweaking Mountain Lion change php location
My next issue is if I run pear -v or pecl -v these return
Could not open input file: /usr/lib/php/pear/pearcmd.php
Could not open input file: /usr/lib/php/pear/peclcmd.php
Do I need to change pear and pecl to point to my new php which is installed in /usr/local/php5/bin/
If so how do I do this and will I lose all of my previously installed extensions such as phpunit?
Thanks
I sorted this by installing pear again. After downloading go-pear.phar then running
sudo php -d detect_unicode=0 go-pear.phar
In the install there are options to change directories pear is using. They were already set to the correct locations for my new php such as /usr/local/php5/bin
I then had to add that path to my bash_profile for the pear command to be recognised.
export PATH=$PATH:/usr/local/php5/bin
To get pecl working again I removed pecl from /usr/bin then symlinked to the pecl in /usr/local/php5/bin
sudo ln -s /usr/local/php5/bin/pecl /usr/bin/pecl
The first package I tried to install was APC and I got the error
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
ERROR: `phpize' failed
This was sorted by following instructions from phpize won't work on Mac OS X Lion I used the homebrew solution
UPDATE: I installed PHPUnit fine then ran phpunit --version
This gave an error of
PHP Warning: require(/usr/lib/php/pear/PHPUnit/Autoload.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 43
Running which phpunit returned /usr/bin/phpunit
Solved by more symlinking
sudo ln -s /usr/local/php5/bin/phpunit phpunit
On Mavericks there's a file in /usr/lib/php called install-pear-nozlib.phar
Everything worked by just running
sudo php install-pear-nozlib.phar from that directory. And then adding /usr/lib/php/pear to the include path in php.ini
Hope that helps someone
I have this issue with one of my users on my Mac. It works fine with the other. So I guess it could have something to do with installing pear using the other user (as that's what I did).
I have no solution to this, but you could try to install pear again and try to select to install it to system instead of local and see if that works.
Edit: I tried to do this, however pear started to work, but not pecl.
I am using a Debian squeeze server. I have installed PEAR using aptitude install php-pear. This created a directory /usr/share/php/PEAR.
I installed some PEAR packages including Phing. I installed the Phing files using pear install --alldeps phing/phing and the files showed up in /usr/share/php/phing.
But shouldn't PEAR packages (under normal circumstances) be put in /usr/share/php/PEAR? When I run
pear config-get php_dir
I get "/usr/share/php". Have I got something configured wrong?
/usr/share/php/
is correct for Debian.
/usr/share/php/PEAR
itself contains classes for PEAR itself.
The reason for using /usr/share/php is that the pear CLI tool is an installer that installs libraries (or applications) for PHP - choosing php is thus correct.
Yes, that is the correct directory on Debian, and Ubuntu.
Regardless of which O/S you are using, you can find the correct install directory by running: pear config-get php_dir via a console. And you get full directory path.
For example, with XAMPP application on Microsoft Window you have to go to XAMPP installation directory path <<XAMPP Installation folder path>>/bin and use ./pear config-get php_dir which lead to execute the binary file using current location and do the same job.
in case php is installed in /usr/local/php
pear is here:
/usr/local/php/lib/php
I am using Mac OSX Lion.
I installed pear in /usr/lib/php/pear
So the data also be installed there.
On my installation of Debian PEAR is located here:
/usr/local/lib/php
Just throwing this out there, in case you have pear installed in a round-about way:
cd /
find . -type d -name pear
For example, I was using MAMP on one of my local machines and it was in a really weird place.
On my 64-bit Ubuntu system, the pear packages are installed to /usr/share/php/PEAR/,
but I do not know how to change the pear install path. Maybe you can configure this somewhere.
If you're using CPanel to install them they're much likely to be located in
./opt/cpanel/ea-php{VERSION}/root/usr/share/pear
I've been trying to do some PHP work on my snow leopard machine.. but I've found issues when I need to use PEAR packages (as symfony handles its php plugins with PEAR).
I've found some references that state that snow leopard includes PEAR.. but how come I cant find it?!
Could someone confirm this.. if if so, where is my pear?
In OSX Snow Leopard and later pear isn't installed by default. The installer is already available to you though.
sudo php /usr/lib/php/install-pear-nozlib.phar
pear config-set php_ini /private/etc/php.ini
pecl config-set php_ini /private/etc/php.ini
sudo pear upgrade-all
/usr/bin/pear
I ran which pear from the command line.
which pear
/usr/local/bin/pear
if which doesn't work try locate pear which will search your machine, if a result is returned you need to update you .bash_profile (in your home directory) to include pear (normally the parent directory) eg.
export PATH="/usr/local/bin:$PATH"
If you can't locate pear on your system, use terminal to get it :
curl http://pear.php.net/go-pear > go-pear.php
sudo php -q go-pear.php
All the options can be left at default except install directory which you need to set. Mine is /usr/local but other locations such as /opt/local will be fine (as long as the path is in your bash profile...
All,
I have installed xampp for linux on ubuntu 9.10. The installation directory is /opt/lampp. The xampp website says PEAR comes with the installation.. I am relatively new to PEAR and want to know the answers for following:
Is PEAR installed with xampp or need to be installed separately using synaptic package manager? I browse to /opt/lampp/bin directory and see "pear" there, but when i type it in the command line, it says
"The program 'pear' is currently not installed. You can install it by typing:
sudo apt-get install php-pear
pear: command not found
"
I want to use PEAR:SOAP package in my PHP code. How to use that? Do I need to set any paths to the pear in my php.ini?
Thanks
I figured it out.. xampp comes with pear... So, what I did was..
cd /opt/lampp/bin
sudo ./pear install soap
In PHP code, "require_once("SOAP/Client.php");
That's all !! :)
from what I was able to ascertain from my coleagues, you would need to populate pear to be able to use it.
It does come with the installation, but requires the population to be used.
source for code
First, go to your xampp installation
directory/folder and navigate to the
php directory. For me it’s
x:\xamplite\php
x:
cd \xampplite\php
pear install <package-name>
once this is done pear should be available to be used. And as for the second question. XAMPP should have taken care of any settings that were needed. You should not require any additions into the .ini for it to work.
However remember that there are no secuiritis when programming in this fashion, as stated by the XAMPP website.
EDIT**
also you have Pear Ubuntu install guide link that may help.
The error message you got back should be enough. Apparently the pear program isn't in your path. How did you install XAMPP? Did you use the package manager, or did you install it yourself?
If you used the package manager, then this is the correct next step:
sudo apt-get install php-pear
As you were given in the command help. Ubuntu doesn't install a lot of things by default, but it does install a database of stuff you might type, and what package you need to install to get that command to work.
If you installed it yourself, then you need to figure out how to get PEAR to register as being installed.