Mountain Lion php pear and pecl - php

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.

Related

Install phpredis MAC OSX

Can anyone help me install php-redis in MAC OSX .
brew install php-redis
not working.
pecl install php-redis
also not working getting -
invalid package name/package file "php-redis".
Homebrew Error:
homebrew_error
git clone https://www.github.com/phpredis/phpredis.git
cd phpredis
phpize && ./configure && make && sudo make install
Add extension=redis.so in your php.ini
brew services restart php#7.2
make test
You can check working or not
php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"
As of 2019, with homebrew php7.2 and up, pecl is now installed by default alongside the php binaries.
To see this for yourself type which pecl.
Steps to install
Check your version of redis, then find a suitable version of the extension here.
If unfamiliar with pecl, type pecl to see the options.
Issue pecl install redis-5.0.2. (or your version). Enter no to each question asked if you're not sure.
If that succeeds check the new file it created at: /usr/local/lib/php/pecl/20180731/redis.so
The install will have added extension="redis.so" to top of your php ini.
Check that by opening the file /usr/local/etc/php/7.3/php.ini.
(assuming you're on 7.3 there)
brew services restart php.
php -i | grep Redis
Redis Support => enabled
Redis Version => 5.0.2
This is what I just did in September 2019 and it works for me.
If what mwal wrote above doesn't work (please try his/her answer first),
first, try to uninstall first (if you have it but broken):
sudo pecl uninstall redis
and after that run:
sudo pecl install redis
After that, ini the php.ini, use full path for the extension.
Mine was /usr/local/Cellar/php#7.3/7.3.21/pecl/20180731/redis.so (assuming you are using php#7.3)
so at the top of my php.ini file is like this:
extension="/usr/local/Cellar/php#7.3/7.3.21/pecl/20180731/redis.so"
Here are steps to use pickle, for PHP >= 7.3 (tested with 8.1):
brew install pickle
pickle install redis
Find your php.ini location via php -i|grep php.ini
Edit the php.ini, insert extension=redis. Preferable at Dynamic Extensions section.
No restart of Apache httpd service is required. You may test your PHP code with Redis
Bonus
If you use VS Code, to enable intellisense / auto complete, at Preference -> paste intelephense.stubs at Search setting box -> Add Item -> select redis.
If you got the following error,
Please make sure the PHP Redis extension is installed and enabled
despite doing everything in the verified answer above, try valet restart . It worked for me
I have tried all these solutions but didn't work for me for a while so I tried this link https://developer.redis.com/develop/php/ from the original docs and it works as charm
If someone gets an error during sudo pecl install redis
Warning: mkdir(): File exists in System.php on line 294
PHP Warning: mkdir(): File exists in /opt/homebrew/Cellar/-----/pear/System.php on line 294
that means you need to create the broken directory manually.
Try to create the directory...
pecl config-get ext_dir | pbcopy
mkdir -p {paste clipboard value}
# in my case, it was
mkdir -p /opt/homebrew/lib/php/pecl/20200930
Now try to install any pecl extensions.
sudo pecl install redis
After installing any extension, restart php
brew services restart php
Happy coding :)

Can't phpize or configure an extension in OS X 10.9 Mavericks

I am trying to build the memcached extension on OS X 10.9 Mavericks for use with the built in PHP 5.4, initially I tried pecl install memcached but that threw the following.
checking for zlib location... configure: error: memcached support requires ZLIB. Use --with-zlib-dir=<DIR> to specify the prefix where ZLIB headers and library are located
ERROR: `/private/tmp/pear/install/memcached/configure' failed
So I created a tmp directory and executed pecl download memcached, unzipped the code and cd'd to the appropriate directory.
Trying to phpize it returned the following:
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
I had brew installed zlib a while ago and pointed ./configure at my installation.
./configure --with-zlib-dir=/usr/local/Cellar/zlib/1.2.8 I was greeted with the following error message:
checking for session includes... configure: error: Cannot find php_session.h
So now I'm wondering the best course of action here... /usr/include/ doesn't exist at all... is this a Mavericks thing? I don't remember having this problem in 10.8 at all.
I could try brew installing php-devel but I presume that isn't going to be the right version of what I need? Any help would be greatly appreciated here
Update
locate php_session.h reveals
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/php/ext/session/php_session.h
should I just ln -s this to the expected location or is there some way to do this via XCode? I have the command line tools installed...
run xcode-select --install to install the XCode5 Command Line Tools, then sudo pecl install memcache. You should be good to go.
After install XCode5 Command Line Tools as afessler sugest (xcode-select --install) I couldn't do the "sudo pecl install memcache" because pecl was missing.
I had to install PEAR and PECL following this guide: http://techtastico.com/post/como-instalar-pear-y-pecl-en-os-x-mavericks/.
Then all worked good. Thanks!
I had this problem and it was due to MAMP not having all the PHP sources.
I found this really helpful solution that explains how to download and configure them:
https://stackoverflow.com/a/11175197/369326
Note that the MAMP components doesn't include the extras for any versions of PHP higher than php 5.4.10 but you can download the extras from http://php.net/releases.
As said above but not using xcode install
Try installing pecl manually:
curl -O http://pear.php.net/go-pear.phar
sudo php -d detect_unicode=0 go-pear.phar
and then:
sudo pecl install memcache
See more at: http://jason.pureconcepts.net/2012/10/install-pear-pecl-mac-os-x/#sthash.x2LKdqj6.dpuf

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.

Installing PHPUnit w/ XAMPP on Mac OS X

Does anyone know how to install PHPUnit on Mac OS X (I'm using XAMPP). I tried the following commands and it said installation succeeded (no errors). Now, when I try to run a phpunit command in Terminal, I get an error that the command phpunit could not be found. Also, running "which phpunit" returns nothing.
The commands I ran:
$sudo /Applications/XAMPP/xamppfiles/bin/pear channel-discover pear.phpunit.de
$sudo /Applications/XAMPP/xamppfiles/bin/pear channel-discover pear.symfony-project.com
$sudo /Applications/XAMPP/xamppfiles/bin/pear channel-discover components.ez.no
$sudo /Applications/XAMPP/xamppfiles/bin/pear install -a phpunit/PHPUnit
Thanks.
Installing PHPunit through XAMPP almost drove me mad, an error was telling me that my xdebug version was to old to install the Coverage lib required for PHPunit, three seconds later another was telling me that everything was fine but no phpunit command was installed.
I've chosen to bypass that problem by installing phpunit at system level (outside of XAMPP).
cd /tmp
curl http://pear.php.net/go-pear.phar > go-pear.phar
sudo php -d detect_unicode=0 go-pear.phar
This should install pear (and tell you where, default is in your home).
cd ~/pear/bin
sudo ./pear channel-discover pear.phpunit.de
sudo ./pear channel-discover pear.symfony-project.com
sudo ./pear channel-discover components.ez.no
sudo ./pear install -a phpunit/PHPUnit
./phpunit should now return you something (in my case it's displaying that some import where unmet.
Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in ~/pear/share/pear/PHPUnit/Autoload.php on line 45
Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:') in ~/pear/share/pear/PHPUnit/Autoload.php on line 45
If you don't have a /etc/php.ini, create it:
sudo cp /etc/php.ini.default /etc/php.ini
Then edit /etc/php.ini and set the right path:
include_path = ".:/php/includes:/Users/YOURUSERNAME/pear/share/pear"
Then calling ./phpunit in your pear bin directory should work... It's quite a pain comparing to a few aptitude and pear call on Ubuntu, but it let you work on OSX. You should be able to still use XAMPP as a webserver but remember that XAMPP uses its buildin PHP environment, phpunit will use the one of your system.
AsTeR's method worked for me though because being stuck with old PHP 5.3.1 current PHPUnit versions will complain because function stream_resolve_include_path is missing.
So I ended up used the solution together with this answer: https://stackoverflow.com/a/8249291
I did as #trent-scott did and got same error.
Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:')
As you can notice there is an empty include path (include_path='.:')..
Go to your php.ini file. Figure out which by doing this in terminal 'php --ini'.
Make sure you've got something similar to this somewhere in the file (be sure to replace username):
include_path=".:/Users/hfossli/pear/share/pear"
It should be sufficient, but I for some reason got this (be sure to replace username):
include_path=".:/Applications/XAMPP/xamppfiles/lib/php/pear:/Applications/XAMPP/xamppfiles/lib/php/pear:/Users/hfossli/pear/share/pear"
I fund an other temporary solution that worked for me. Instead of using the pear command directly within your Xampp app, try using the full path to pear executable like : /Applications/XAMPP/xamppfiles/bin/pear
hope it helped.

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