Can't install PEAR - php

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.

Related

Mac OS: Intl extension is not loaded

macOS Mojave 10.14.3
PHP 7.1.23
Prestashop 1.7.5.1
I tried to install PHP intl extension on my local server in order to use Prestashop.
I added extension=php_intl.so to etc/php.ini
When I try to install Prestashop I get Intl extension is not loaded.
$ php -m | grep intl
When I do $ php -m | grep intl, I get:
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/pecl/20160303/php_intl.so' - d
lopen(/usr/local/lib/php/pecl/20160303/php_intl.so, 9): image not found in Unknown on line 0
Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/pecl/20160303/php_intl.so' - dlopen
(/usr/local/lib/php/pecl/20160303/php_intl.so, 9): image not found in Unknown on line 0
intl
It seems that the file php_intl.so doesn't exist.
$ sudo pecl install intl
I also tried $ sudo pecl install intland I get:
make: *** [php_intl.lo] Error 1
ERROR:make' failed`
$ curl -s http://php-osx.liip.ch/install.sh | bash -s 7.1
I also tried $ curl -s http://php-osx.liip.ch/install.sh | bash -s 7.1 and it doesn't create the intl.so file.
How can I solve this problem?
Brew's PHP 7.1, 7.2 and 7.3 all have INTL enabled by default.
Most probably, you're just using your Mac OS' bundles version of PHP.
Run
ls -l $(which php)
to find out where the current PHP binary is located and whether it is symlinked to a Brew installation or not. In my case, for example:
lrwxr-xr-x 1 27 May 23 16:30 /usr/local/bin/php -> ../Cellar/php/7.3.5/bin/php
Meaning that my php is linked to Brew's 7.3.5 version.
If you are NOT using Brew's PHP, you'll see something like
-rwxr-xr-x 1 11169664 Mar 21 07:09 /usr/bin/php
Installing PHP through Brew
Find out whether you've already installed PHP:
brew list | grep php
If there is any output, and your version of PHP is present, go to step 2, or use step 1 to update PHP to the latest version.
1. Install Homebrew's PHP
brew install php#7.3
(or 7.2, 7.1). If Brew complains about not being able to find a formula, you might have messed with taps. Instead of php#7.3, you could try to supply the full path to the current php formula:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/php.rb
Still not working, check whether you are running a recent version of Homebrew brew --version.
Homebrew 2.1.3-31-geaf2370
Homebrew/homebrew-core (git revision fd1ef; last commit 2019-05-25)
Homebrew/homebrew-cask (git revision 16d50; last commit 2019-05-26)
2. Link Homebrew's PHP
Now, to have php 'in your path', there are two options.
a) Either homebrew's version must be linked from its install location (/usr/local/bin/Cellar/php....) to a directory in your path (e.g., /usr/local/bin). To do this, run:
brew link --force php#7.3
If you are not able to link, this is typically caused by set permissions or System Integrity Protection. In the first case, try sudo chown "$USER":admin /usr/local/bin/php.
b) Or, add the /usr/local/opt/php#7.3 directory (opt-prefix) to your $PATH variable. E.g., for Bash:
echo 'export PATH="/usr/local/opt/php#7.3/bin:/usr/local/opt/php#7.3/sbin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
3. Validate installation
ls -l $(which php)
should show that php is linked to a Homebrew PHP installation in /usr/local/bin/Cellar.
php -v
should show the recently installed version of PHP. Try to restart your terminal if that's not the case.
php -i | grep -i intl
should show some information about the current install of intl.
If you're using webservers and/or PHP FPM, this is the time to restart those services. (Or restart your system, if you don't know how to do that and cannot figure out).
Possible issues
If you still get warnings about missing extensions (Unable to load dynamic library, etc.), then your php.ini is messed up.
Find the current location of php's ini
$ php -i | grep \.ini
Configuration File (php.ini) Path => /usr/local/etc/php/7.3
Loaded Configuration File => /usr/local/etc/php/7.3/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php/7.3/conf.d
Additional .ini files parsed => /usr/local/etc/php/7.3/conf.d/ext-opcache.ini
....
Edit /usr/local/etc/php/7.3/php.ini and find the offending extension load (e.g., extension="myext.so"). Comment out those that cannot be found.
Homebrew permissions
Some argue that it's a good idea to chown /usr/local.
sudo chown -R "$USER":admin /usr/local
This will make installing things here, by hand and through Homebrew, a lot easier, but also a bit less secure too, since non-root processes are now allowed to write here too.
Your web-application is using a different version of PHP.
Make sure that it doesn't... The configuration of this depends on the used webserver. A first step would be to output the current PHP configuration in your web-application with <?php phpinfo();.
This explains steps for Apache.
Another way to get a webserver + PHP stack running quicly is using Laravel Valet.
Installing additional extensions
To install additional PHP extensions, use PEAR.
pear -V
should output the current PEAR and PHP version.
PEAR Version: 1.10.9
PHP Version: 7.3.5
Zend Engine Version: 3.3.5
Now, to install an extension, for example, PHP's yaml extension:
pear install yaml
I have seen a lot of answers about this problem and anyone helped me, but the last (of course). This is for XAMPP´s use.
Xcode is needed.
Download the version of php you use in xampp from php.net.
Extract it and open the extracted folder in a terminal using cd.
Change to subfolder ext/intl.
Run these commands to build the extension:
/Applications/XAMPP/bin/phpize
./configure --enable-intl --with-php-config=/Applications/XAMPP/bin/php-config --with-icu-dir=/Applications/XAMPP/xamppfiles/
make
sudo make install (password required)
Delete all files you downloaded and also the extracted folders.
Add to php.ini file in xampp/etc folder line
extension="intl.so"
Original link: https://community.apachefriends.org/viewtopic.php?p=255061&sid=27afc55649dfe6ea7b0824cb0bb8486b
Since php 7 it's not necessary load the extension php_intl.so, what do you need to do?, edit your php.ini and delete or comment the line that is loading the extension php_intl.so, after this reload your apache and try again.
There might be an issue with brew
You could try to use this as mentioned there:
brew tap kyslik/homebrew-php
brew install kyslik/php/php71-intl
i tried all but intl not working in mac so please uninstall xampp and install mamp it will work
So, on Pecl Official site ( https://pecl.php.net/package/intl ), it's clear that Intl package is not maintained anymore and has been superseded. Since PHP 5.3.0 you don't need to use Pecl to install intl extension, it's bundled with PHP.
But, it's missing on native instalation of PHP 7.1.24 on Mac OS Mojave.
if you wanna use only native apache and php pre-installed instead of using homebrew, do this:
Download PHP 7.1 from php.net, install XCode Command Line Tools, ICU (http://site.icu-project.org/), Autoconf, reinstall the developer tools header files, and finally install Intl extension using phpize.
Important: you'll have to disable SIP.

Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128'

I have successfully installed Laravel, but after running php artisan serve and going to localhost:8000 I get this error:
Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128'
I have checked phpinfo() on localhost:8888 and it says that mcrypt is properly installed. However the only thing I can think of is that maybe my path is wrong?
in my .bash_profile I have
PATH=/usr/local/bin:$PATH
Every time I try to run Laravel commands I have to type this in the terminal:
export PATH="~/.composer/vendor/bin:$PATH"
I am running on a Mac. Is there a simple way I can set up my bash_profile so that I can consistently change between localhost addresses and still have all the proper PHP functions working?
More simple way on ubuntu
apt-get install php5-mcrypt
mv -i /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/
php5enmod mcrypt
service apache2 restart
Note: if you don't have "/etc/php5/conf.d" just skip that step and it will work ok
check http://php.net/manual/en/mcrypt.installation.php
This problem relative to the PHP extensions loader.
You no need to use laravel command at all after successful installation.
Laravel framework need Mcrypt Library for the security module and encrypt some of configure file.
The things that you need is theses steps.
Download Mcrypt http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
then configure make and install it.
Download php http://php.net/releases/index.php
Above 5.5.14 are suggested. (Use this path later on step 4)
then download Autoconfigure
curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar xvfz autoconf-latest.tar.gz
cd autoconf-2.69/
./configure
make
sudo make install
then you have to go to directory level
cd ***YOURPHPDIRECTORY***/ext/mcrypt/
and run phpize within this directory level
/usr/bin/phpize
./configure
make
sudo make install
modify your php.ini to enable the mcrypt extension by insert this into php.ini
extension=mcrypt.so
Restart web server.
For Mac users's specially - install it using Home Brew
I’ve installed an empty Laravel installation and got the following error message when navigating to http://localhost/kanban/public/:
Notice: Use of undefined constant MCRYPT_RIJNDAEL_128 – assumed ‘MCRYPT_RIJNDAEL_128′ in /Library/WebServer/Documents/xxx/config/app.php on line 83
Googling for this error message return many tutorials on how to install mcrypt on Mac OS X (whether building it from source or using Homebrew). The problem was that both the mcrypt and the php55-mcrypt packages were properly installed:
$ brew install mcrypt
Warning: mcrypt-2.6.8 already installed
$ brew install php55-mcrypt
Warning: php55-mcrypt-5.5.20 already installed
Mcrypt was also properly loaded by PHP:
$ php -m | grep mcrypt
mcrypt
$ php -i | grep mcrypt
Additional .ini files parsed => /usr/local/etc/php/5.5/conf.d/ext-mcrypt.ini,
Registered Stream Filters => zlib.*, bzip2.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, mcrypt.*, mdecrypt.*
mcrypt
mcrypt support => enabled
mcrypt_filter support => enabled
mcrypt.algorithms_dir => no value => no value
mcrypt.modes_dir => no value => no value
for more details refer this link - http://benohead.com/mac-os-x-php-notice-use-undefined-constant-mcrypt_rijndael_128/
If you are seeing this on ubuntu or other flavors of *nix , it might help to do the following:
service php5-fpm restart
I just adjusted the .bash_profile in MacOS and it worked:
export PATH="/usr/local/sbin:$PATH"
PHP_AUTOCONF="/usr/local/bin/autoconf"
source ~/.bash_aliases
I also had this problem in trying to deploy a Laravel to Apache on Mac OS Sierra. I eventually found this post that gave step-by-step instructions to resolve this issue. These instructions assume that you have Homebrew installed; if you don't have it installed, then paste the following into a Terminal window to install it:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Here is the relevant steps pasted from the post given above:
Step 1: Install autoconf and mcrypt
I used homebrew to install autoconf and mcrypt, which is as easy as:
brew install autoconf mcrypt
If this does not work for you, or you don't want to use homebrew, then check out this tutorial.
Step 2: Build the PHP extension
To build the PHP extension you will need the PHP 5.4.17 source code that is available for download here and extract it:
cd ~/Downloads
unzip PHP-5.4.17.zip
Then build the extension using the following commands:
cd php-src-PHP-5.4.17/ext/mcrypt/
/usr/bin/phpize
./configure
make
sudo make install
Step 3: Enable the extension
All that is left is to enable the extension by editing /etc/php.ini. If this file is not present, copy /etc/php.ini.default and rename it:
sudo cp /etc/php.ini.default /etc/php.ini
Edit the /etc/php.ini file and add the following:
extension=mcrypt.so
Step 4: Restart apache
Now just restart apache and you're done!
sudo apachectl restart
ADDITIONAL NOTES AND CLARIFICATION
I did encounter two issues with following these steps:
I had to match the PHP zip file that I downloaded to the version of PHP that was installed on my machine.
So I did
php -v
to determine the version number and then changed the download to match that version number. In my case the PHP version was 5.6.28 and so I needed to download the PHP source from
https://github.com/php/php-src/archive/PHP-5.6.28.zip
I got an exception at step 2 when I tried to do the sudo make install, the exception was caused by SIP, a security featured added by El Capitan. The exception is outlined in this question, and the resolution to this problem I found in this answer.
Applying the information from this answer changed the step 2 listed above and replaced the sudo make install with the following:
mkdir -p /usr/local/lib/php/extensions
sudo make EXTENSION_DIR='/usr/local/lib/php/extensions' install
Take note that because of this change, step 4 above also needs to changed to include the path to mcrypt.so. So the following must go in the php.ini:
extension=/usr/local/lib/php/extensions/mcrypt.so
I use nginx and php-fpm, and already did apt-get install php5-mcrypt, and moved the mcrypt.ini file to mods-available.
I had to do sudo service php5-fpm restart before it actually worked.
detailed instructions here https://www.php.net/manual/en/install.pecl.windows.php
make sure you choose appropriate extension version as of your PHP version

Mountain Lion php pear and pecl

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.

Enabling PostgreSQL support in PHP on Mac OS X

I'm having a terribly difficult time getting the command "pg_connect()" to work properly on my Mac. I'm currently writing a PHP script (to be executed from console) to read a PostgreSQL database and email a report.
I've gone into my php.ini file and added
extension=pgsql.so
But, I'm met with the following error.
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_pgsql.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_pgsql.so, 9): image not found in Unknown on line 0
PHP Fatal error: Call to undefined function pg_connect() in... (blah file here)
When running phpinfo(), I see nothing about PostgreSQL, so what is my issue here?
The PHP version that comes bundled with OS X doesn't include PostgreSQL. You'll have to compile the extension yourself. Here are some instructions:
Find your version of PHP: php -v.
Download the version of PHP that matches yours: curl -O http://us.php.net/distributions/php-5.3.3.tar.gz. (This example downloads PHP 5.3.3 but this must match your version)
Extract the archive you downloaded: tar -xzvf php-5.3.3.tar.gz
Change to the PostgreSQL's extension directory: cd php-5.3.3/ext/pgsql/
Type phpize.
Type ./configure.
Type make.
Type sudo make install.
Add the extension to you php.ini file by adding extension=pgsql.so. (You may already have done this)
Restart Apache.
Update for OS X Mountain Lion
Apple has removed autoconf from the newer versions of XCode so the procedure above will fail at #5. To solve that problem:
Type /usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)".
Type sudo chown -R $USER /usr/local/Cellar.
Type brew update.
Type brew install autoconf.
That should install autoconf and allow you to install the module using the instructions above.
If you use home brew, you can solve this with a command as simple as:
brew install php55-pdo-pgsql
for other php version, search with:
brew search pgsql
This worked for me with OSX 10.9.4 «Mavericks»
Install sources
Download the PHP source code. Unlike on Mountain Lion, you don’t get any headers preinstalled to link against so need to put it in /usr/include/php. Mavericks ships with PHP 5.4.17, but the latest 5.4.x source from php.net should do:
tar -jxvf php-5.4.20.tar.bz2
sudo mkdir -p /usr/include
sudo mv php-5.4.20 /usr/include/php
Configure PHP
cd /usr/include/php
./configure --without-iconv
sudo cp /etc/php.ini.default /etc/php.ini
Building a module
I needed the pdo_pgsql module - the same pattern should apply to just about any module assuming you have the necessary dependencies installed:
cd ext/pdo_pgsql
In my case I had the following error:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script. ERROR:
`phpize' failed
So I had to use this command:
brew install autoconf
Then:
phpize
After that I tried to do:
./configure
but I had the next problem:
checking for pg_config... not found configure: error: Cannot find
libpq-fe.h. Please specify correct PostgreSQL installation path
So the solution was to specify correct PostgreSQL installation path:
./configure --with-pdo-pgsql=/Library/PostgreSQL/9.3/
make
sudo make install
That copies pdo_pgsql.so to /usr/lib/php/extensions/no-debug-non-zts-20100525.
Then simply add
extension=pdo_pgsql.so to /etc/php.ini
Run php -m to confirm everything went to plan.
For those who installed php7/ngix/postgres with homebrew
You can install the PostgreSQL module with:
brew install php70-pdo-pgsql
After that, you have to restart the php service:
brew services restart php70
OS X El Capitan users can simply upgrade their version of PHP 5.6. This is a one liner that will do that.
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6
For php56 via brew:
brew install php56-pdo-pgsql
PostgreSQL by default is installed in a unusual place on MAC OS X:
/Library/PostgreSQL/9.3
Given the location above you can type this:
./configure --with-pgsql=/Library/PostgreSQL/9.3
I killed the whole day trying to make it work on El Capitan after I made an upgrade yesterday and it turned out that I forgot to modify httpd.conf and change the path from the default php module (version 5.5.27) to the one I installed (version 5.6.14). This should be done in httpd.conf by modifying your default LoadModule php5_module path to LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so.
Just decided to leave it here as the potential solution for those who upgrade their OS or just the PHP version and face the same problem.
For those of you having openssl error while make here is the solution
OSX uses openssl 0.98 while installer is searching for 1.0.0
refer this link for instructions
psycopg2 installation error - Library not loaded: libssl.dylib
I downloaded PostgreSQL for Mac, and used the stack builder after installation to standup the entire EnterpriseDB Apache/PHP stack end-to-end. I mention this as a possible time saving option, probably not ideal for all situations. Should work OK if the apache and postgres shipped with Mac OS X were never started.
To keep existing apache hosted applications (i.e. pre-PostgreSQL install legacy) stable, I would just install the newer EnterpriseDB apache on port 81 (stackbuilder will prompt for new port if legacy apache instance is already running). Then, use mod_proxy in httpd.conf for the apache running on port 80 to provide seamless user experience to applications hosted on PostgreSQL.

Install PEAR on MAMP

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/

Categories