0

I have installed pear and php_beautifier with sudo...

From what I've read I should be able to format code with the command

php_beautifier x.php

But when I try to do this I get this error:

Warning: require_once(PEAR.php): failed to open stream: No such file or directory in /Users/philip/pear/bin/php_beautifier on line 37

Fatal error: require_once(): Failed opening required 'PEAR.php' (include_path='.:') in /Users/philip/pear/bin/php_beautifier on line 37

I have looked at the php_beautifier.php code and I don't know what's wrong. Line 37:

require_once 'PEAR.php';

and the file is in the same dir as pear.php?

Philip
  • 6,827
  • 13
  • 75
  • 104
  • @SalmanA Ahh my bad, I have pear but not pear.php in my folder.. Is it safe to just copy a version of pear and name it pear.php in the same folder? – Philip Oct 30 '12 at 11:09
  • 1
    Perhaps you do not have to. Do a `php -i > phpinfo.txt`, open the file and note down the value for `include_path`. If it contains valid `/path/to/the/folder/that/contains/PEAR.php` then problem is somewhere else. Otherwise you just need to add/edit the path in the php.ini file. – Salman A Oct 30 '12 at 11:13
  • @SalmanA - I found that all my files that I needed was in .../pear/share/pear/ I just included that in php.ini and it worked :D Thanks! – Philip Oct 30 '12 at 12:49

3 Answers3

2

Ideally, the path to PEAR directory should be specified in include_path directive in php.ini. This allows you to include PEAR core and packages in your code easily, for example:

require_once 'PEAR.php';
require_once 'Console/Getopt.php';

Otherwise, you will have to specify full path to the PEAR directory which makes your code less portable:

require_once '/usr/share/pear/PEAR.php';
require_once '/usr/share/pear/Console/Getopt.php';

To probe the effective value of the include_path directive, use the phpinfo() function. If it does not contain the path to PEAR installation, use:

# UNIX
include_path = ".:/path/to/pear"
# Windows
include_path = ".;C:\path\to\pear"

More detailed and step-by-step instructions can be found here.

Salman A
  • 262,204
  • 82
  • 430
  • 521
0

Open /private/etc/php.ini

And replace this line (796):

;include_path = ".:/php/includes"

to:

include_path = "/usr/lib/php/pear"
leozera
  • 149
  • 1
  • 4
  • 10
0

First check pear is installed with command:

pear

If not installed use this command to install it:

sudo apt install php-pear
Houssin Boulla
  • 2,687
  • 1
  • 16
  • 22