i'm working with ubuntu 11.10 as root on my local machine, i've installed xampp 1.7.7 and i'm a newbie to ubuntu,
while following a tutorial on sitepoint(http://www.sitepoint.com/getting-started-with-pear/) on how to install pear to use PhpUnit, i didnt notice it then, but it seems that i installed or used an existing php version 5.3.6 in CL to do that, also the pear installation was built on this version, while xampp being installed,i now have two versions of php,xampp's 5.3.8 and the 5.3.6, anyway, what i want to do is to use the existing xampp php version and build pear on that, to make all my work through xampp.so my questions are:
how to uninstall the php V5.3.6 and it's pear installation?
how to link the CL with the php ver. of xampp?
how to build the next pear installation on the php ver. of xampp?
i want all my web dev. work through xampp, is there anything else i need to unistall, to avoid this confusion? 4.
i did the following in attampet to solve the problem:
i wrote this in bash:
gedit ~/.bashrc
i added that to the end of ~/.bashrc file in attempt to change environment path:
export PATH=/opt/lampp/bin:$PATH
export PATH=/opt/lampp/lib/php:$PATH
export PATH=/opt/lampp/lib/php/PHPUnit/pearcmd.php:$PATH
i checked the php and pear version using 'php -v' and 'pear list'
i got an ouput of:
PHP 5.3.8 (cli) (built: Sep 19 2011 13:29:27)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
and for pear:
Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.9 stable
Console_Getopt 1.3.1 stable
PEAR 1.9.4 stable
PHPUnit 1.3.2 stable
Structures_Graph 1.0.4 stable
XML_Util 1.2.1 stable
when i run: 'phpunit MessageTest.php': i get
PHP Warning: require_once(PHP/CodeCoverage/Filter.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 38
Warning: require_once(PHP/CodeCoverage/Filter.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 38
PHP Fatal error: require_once(): Failed opening required 'PHP/CodeCoverage/Filter.php' (include_path='.:/php/includes:/opt/lampp/lib/php:/opt/lampp/bin:/opt/lampp/lib/php/PEAR') in /usr/bin/phpunit on line 38
5.i ran the following commands as reported in other questions as a solution to that error:
sudo apt-get remove phpunit
sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no
sudo pear update-channels
sudo pear upgrade-all
sudo pear install --alldeps phpunit/PHPUnit
sudo apt-get install phpunit
and updated include path of php.ini to be:
include_path = ".:/php/includes:/opt/lampp/lib/php:/opt/lampp/bin:/opt/lampp/lib/php/PEAR"
the php file MessageTest.php:
<?php
require 'PHPUnit/Autoload.php';
$path = '/opt/lampp/lib/php/PEAR';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'PHPUnit/Framework/TestCase.php';
require_once 'Message/Controller/MessageController.php';
class MessageTest extends PHPUnit_Framework_TestCase{
private $message;
public function setUp() {
$this->message = new MessageController();
}
public function tearDown() {
}
public function testRepeat(){
$yell = "Hello, Any One Out There?";
$this->message->repeat($yell); //sending a request
$returnedMessage = $this->message->repeat($yell);//get a response
$this->assertEquals($returnedMessage, $yell);
}
}
?>
MessageController class from MessageController.php that i'm trying to test
<?php
class MessageController {
public function actionHelloWorld() {
echo 'helloWorld';
}
public function repeat($inputString){
return $inputString;
}
}
$msg = new MessageController;
?>
I'm not using any PHP framework, i just made the files and classes sounds like it that's all.
and still i get the same error:
PHP Warning: require_once(PHP/CodeCoverage/Filter.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line
Warning: require_once(PHP/CodeCoverage/Filter.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 38
PHP Fatal error: require_once(): Failed opening required 'PHP/CodeCoverage/Filter.php' (include_path='.:/php/includes:/opt/lampp/lib/php:/opt/lampp/bin:/opt/lampp/lib/php/PEAR') in /usr/bin/phpunit on line 38
sure, i'm getting demanding here, i've wasted a lot of time and got really frustrated over this, hope you guys dont get bored reading through my questions, i appreciate your help
thanks in advance,
Mohamad elbialy
Finally, i got the answer for the question on how to link the xampp's php and pear to CL (bash shell for ubuntu),
type the following in a terminal window:
gedit ~/.bashrc
the file opens and you add the following to the end of file:
export PATH=/opt/lampp/bin:$PATH
and to make sure type the following in the terminal:
echo $PATH
you'll see '/opt/lampp/bin' in the echoed path along with others added by default
this is the only way that worked for me after 2-3 days of searching forums, other stackoverflow and superuser questions
to check that the CL is dealing with xampp's php and pear version, type the following:
php -v shows the version of php
pear list shows the version of pear along with pear dependent packages
Now, i've been doing this to make PHPunit work in CL, for 5 days, imagine the frustration,
being a newbie to Ubuntu i made alot of sudo and not so sudo commands that missed the whole thing for me, so i decided to make a fresh installation of ubuntu (to delete all those pear, php and phpunit packages that i installed and couldnt track thier path)
so starting from a fresh ubuntu 11.10 and xampp 1.7.7, i did the following to make phpunit work:
i made the link for xampp's php and pear with cL (i wrote how above),
type the following steps in CL:
sudo /opt/lampp/bin/pear uninstall phpunit (xampp's is 1.2.something, i want to install 3.6.10)
sudo /opt/lampp/bin/pear list (PHPunit is not there, that's a check),
the following steps as advised in PHPunit manual1
sudo /opt/lampp/bin/pear config-set auto_discover 1 (opens the download channel or something)
sudo /opt/lampp/bin/pear install pear.phpunit.de/PHPUnit (this installs ver. 3.6.10),
now type in CL:
sudo /opt/lampp/bin/phpunit --version (this shows the version of 3.6.10, yes you've made it)
i used /opt/lampp/bin/phpunit, to make you see quick results and no, you dont need to include anything in path to work, you already done that, you need to close that terminal and open a new one and type only, phpunit --version, you'll get the same result, it's there, it's all yours
Note:
i used '/opt/lampp/bin/something and then the command', to force my installations through xampp's php and pear, this is not needed (cause you set the environment path), but that's how you get to do things when you spend more than 5 days of search.
i tried working with phpunit 1.2.something of xampp's, but it seems that it's not there for the command line, i dont know why and i dont want to, so if that happens to you and you want ver.1.2.something, find all versions, using the instructions in this link (http://pear.phpunit.de/) and do the same steps to install it,
i didnt try the method in that link and if you get stuck you can comment to this answer,
Related
I have php 7.4 installed on my macbook pro m1
% php -v
PHP 7.4.15 (cli) (built: Feb 26 2021 09:28:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.15, Copyright (c), by Zend Technologies
I'm trying to install the mongodb driver running:
sudo pecl install mongodb
But fails after a while:
mp/pear/temp/mongodb/src/contrib/ -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/temp/mongodb/php_phongo.c -fno-common -DPIC -o .libs/php_phongo.o
In file included from /private/tmp/pear/temp/mongodb/php_phongo.c:29:
In file included from /opt/homebrew/Cellar/php#7.4/7.4.15_1/include/php/ext/spl/spl_iterators.h:24:
/opt/homebrew/Cellar/php#7.4/7.4.15_1/include/php/ext/pcre/php_pcre.h:25:10: fatal error: 'pcre2.h' file not found
#include "pcre2.h"
^~~~~~~~~
1 error generated.
make: *** [php_phongo.lo] Error 1
ERROR: `make' failed
I tried with
arch -x86_64 sudo pecl install mongodb
but results in the same error.
Somebody knows how can I solve this please? Or if I can install the mongodb driver without using pecl. Thanks in advance.
I have finally solved my problem.
I followed these steps from https://github.com/mongodb/mongo-php-driver/issues/1159
After installing a newer PHP version where previously I used 7.3.24 and updated to 7.4.16.
Still had the same issue but diffrent file:
fatal error: 'pcre2.h' file not found #include "pcre2.h"
From this error I tried to check the files in the MacOs Big Sur File system and in the end I found where the pcre2.h is located, and oddly it was being called in the pcre folder, so I manually copied from the pcre2 folder to pcre
The solution that I used:
$cp /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php\#7.4/7.4.16/include/php/ext/pcre/pcre2.h
Then, I installed mongodb using
$brew install mongodb
After that, I once again tried
$sudo pecl install mongodb
Finally, it worked. However, I'm not sure if this is a good way to solve the problem by manually adding a header file to the directory.
(Sorry I'm still new to the MacOs Environment, just bought a mac mini m1 last week for developing my programming skills)
If you were to install php multiple versions from homebrew make sure you are using the current version as you wanted to. You could check the version by using which php.
To switch from 7.4 to 5.6
$brew unlink php#7.4
$brew link php#5.6 --force
credits: https://www.markhesketh.com/switching-multiple-php-versions-on-macos/
New error
Success Installation:
There is a simpler way to fix the installation issue than symlinking the header file into PHP sources. When running pecl install, you can provide additional compile arguments via the CFLAGS environment variable. So, on the Apple Silicon platform, you can use the following command to get the extension to compile:
CFLAGS=-I/opt/homebrew/include pecl install mongodb
Note that this is only necessary on Apple Silicon, not on x64. It also works for other extensions that fail because of similar errors (e.g. apcu)
I had the same issue with PHP 7.3, I solved it just by running the following commands:
cp /opt/homebrew/Cellar/pcre2/10.38/include/pcre2.h /opt/homebrew/Cellar/php#7.3/7.3.31/include/php/ext/pcre/pcre2.h
Then installed it successfully:
sudo pecl install mongodb
I have finally solved my problem. I used PHP 8.1.7 - Mac Pro 2022 - Apple Silicon (M1)
My errors: fatal error: 'pcre2.h' file not found
The solution that I used:
1. brew install pcre2
2. ln -s /opt/homebrew/Cellar/pcre2/10.40/include/pcre2.h /opt/homebrew/Cellar/php/8.1.7/include/php/ext/pcre/pcre2.h
Please check your path again when use `ln -s`
3. sudo pecl install mongodb
See more: Install pecl pear on MacOs - Link
Success Installation:
Hope it help you :) Thanks
cp /Applications/MAMP/Library/include/pcre2.h /Applications/MAMP/bin/php/php8.0.8/include/php/ext/pcre/pcre2.h
then run
sudo pecl install mongodb
If you use MAMP,
Based on #Kelwin Tantono's answer follow instructions to install mongodb then,
Firstly, check for the location of pcre2.h file by
cd /opt/homebrew/Cellar/pcre2/
In this directory find the folder with ls command, in my case it was 10.40 .
Change 10.40 value in the below code with the result of ls command.
Then, check your php version with moving to php directory at MAMP by
cd /Applications/MAMP/bin/php/
Change php8.0.8 value in the below code with your desired php version.
cp /opt/homebrew/Cellar/pcre2/10.40/include/pcre2.h /Applications/MAMP/bin/php/php8.0.8/include/php/ext/pcre
Now you can install mongodb extension with below command after changing your working directory to
cd /Applications/MAMP/bin/php/php8.0.8/bin
sudo pecl install mongodb
Now, you should add extension=mongodb.so to php.ini file with
echo "extension=mongodb.so" > /Applications/MAMP/bin/php/php8.0.8/conf/php.ini
Do not forget to change php version.
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 followed this post but it did not help
I am executing following shell commands on a Remote CI system (Fedora) to install php tools:
wget http://pear.php.net/go-pear.phar
php go-pear.phar
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit
On execution of php unit command I encounter following exception -
pear install pear.phpunit.de/PHPUnit
PHP Fatal error: Call to undefined method PEAR::raiseErro() in /usr/share/pear/PEAR/REST.php on line 165
PHP Stack trace:
PHP 1. {main}() /usr/share/pear/pearcmd.php:0
PHP 2. PEAR_Command_Common->run() /usr/share/pear/pearcmd.php:305
PHP 3. PEAR_Command_Install->doInstall() /usr/share/pear/PEAR/Command/Common.php:271
PHP 4. PEAR_Downloader->download() /usr/share/pear/PEAR/Command/Install.php:661
PHP 5. PEAR_Downloader_Package->initialize() /usr/share/pear/PEAR/Downloader.php:279
PHP 6. PEAR_Downloader_Package->_fromString() /usr/share/pear/PEAR/Downloader/Package.php:190
PHP 7. PEAR_Downloader->_getPackageDownloadUrl() /usr/share/pear/PEAR/Downloader/Package.php:1713
PHP 8. PEAR_REST_13->getDownloadURL() /usr/share/pear/PEAR/Downloader.php:850
PHP 9. PEAR_REST->retrieveData() /usr/share/pear/PEAR/REST/13.php:68
Finished: FAILURE
Are there any more commands I need to add?
You need to update your PEAR. Here is a bug report showing the same error http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=619307 and the solution is to get the updated PEAR version.
What the pear installer is trying to tell you is that there was an error when trying to install the package.
It fails because the pear version that is used is buggy :/
Yes you installed the "current/right" pear package from the php site with the commands shown so that leaves three options:
a) Some permission issue with access to /tmp/ or some other pear config-show folder that doesn't get properly reported.
Maybe throwing in a sudo might help if you can do that?
b) You still have another pear version running alongside or you didn't install pear system-wide or something related to that issue.
Try to run pear upgrade pear and see if that helps. pear version should produce 1.9.4.
c) It's failing because it can't connect to the server it wants to pull the files from and it then fails trying to report the error.
Maybe run wget pear.phpunit.de just to see if that works to check or if your firewall blocks that.
Those are the only two options I currently see to solve your issue with pear without more debugging. Should that not suffice you can find help on freenodeIrc in #phpunit or in the stackoverflow php chat.
All php-qa-tools can be run from a git checkout but it is, usually, considerably(!) more hassle to get that to run.
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.
I've installed a copy of MAMP on my macbook so I can run my php/mysql based website locally.
The MAMP package itself seems to work fine but I needed the PEAR MDB2 Package.
I did the following to install
pear install MDB2
pear install MDB2_Driver_mysql
pear channel-update pear.php.net
All apparently worked and if I try again, they say already installed.
The php include path set in php.ini also looks to be correct:
include_path = ".:/Applications/MAMP/bin/php5.3/lib/php"
Yet after restarting the server and trying to hit my site, I still get
Fatal error: require_once() [function.require]: Failed opening required 'MDB2.php' (include_path='.:/Applications/MAMP/bin/php5.3/lib/php') in /Applications/MAMP/htdocs/config.php on line 5
Is /Applications/MAMP/bin/php5.3/lib/php the root directory for PEAR? That doesn't sound right. Run the command pear config-get php_dir, it will tell you where the PEAR root directory is (despite the misleading configuration name). The default is /usr/share/pear.