Home » Php » php – PhpDocumentor installed via PEAR on OSX not working – missing files?

php – PhpDocumentor installed via PEAR on OSX not working – missing files?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I’m basically new to PEAR (and PhpDocumentor); I installed PhpDocumentor using the PEAR CLI, and everything seemed to go fine… until I went to use it, at which point I got the following error:

Warning: require(PhpDocumentor/phpDocumentor/phpdoc.inc): 
failed to open stream: No such file or directory in 
/usr/local/bin/phpdoc on line 40

Fatal error: require(): Failed opening required 
'PhpDocumentor/phpDocumentor/phpdoc.inc' (include_path='.:/usr/share/pear') 
in /usr/local/bin/phpdoc on line 40

I couldn’t find anything online about the error, so I uninstalled/reinstalled via the command line again without error, but I’m getting the same problem. Have I overlooked something? As I said I’m quite new to PEAR 🙂

Thanks. D

How to&Answers:

Well, this question is comically old, but I just had this same issue and solved it after much head-scratching so I thought I’d share.

I ran pear config-show as @ashnazg detailed and my php_dir is set to /usr/lib/php. I tried running phpdoc -h from there and — voila! — it worked. So the issue for me was that PHP needed to know about this path. I edited php.ini (which for me is in /private/etc/php.ini) and edited include_path to include /usr/lib/php. Mine then looked like:

include_path = ".:/usr/lib/php"

After that, it works like a charm! Hope this helps someone else out there. FWIW, I’m on Snow Leopard and I installed phpdoc by running sudo pear install phpdocumentor.

Answer:

To figure out where PEAR is putting things, run pear config-show. If PEAR had said earlier that it had successfully installed PhpDocumentor for you, then the file you’re looking for should be found in the php_dir setting’s value (on my Mac, this is /usr/lib/php/PEAR).

It is necessary for this php_dir value to be set in your include_path for most PEAR packages to function properly. Since /usr/share/pear DOES appear to be in your include_path, as per the error you included above, I’d have to guess that your PEAR installation has its php_dir set to some other location.

Now, if you want to change your PEAR installation to point to /usr/share/pear, you need to understand something about how PEAR installs things. Many packages use install-time text replacement, which puts YOUR installation’s settings into the package’s code itself. If you look back at your pear config-show output, you’ll see several other *_dir settings (data_dir, bin_dir, www_dir, etc.). So, it’s important that these be set like you want them BEFORE you install your packages. Don’t worry though, it’s not too late for the packages you have installed already.

To change the PEAR settings, use pear config-set (setting name) (setting value), like pear config-set php_dir /usr/share/pear. Since only php_dir is absolutely necessary to be in your include_path, you can probably leave the other settings as they are. I usually make sure they all point into the same root directory, just to keep everything in one overall place.

Once you change ANY of these settings, you should run a pear update of each and every package you already have installed. What this will do is perform that install-time text replacement I mentioned earlier, but this time will use the settings that are current, i.e. the ones you’ve just finished setting. Run this on the PEAR main package first, pear update --force pear… you’ll have to include the --force flag because PEAR will realize you’re asking me to update the package when it’s already ‘current’ and stop itself. Once you’ve run this update for ALL of your installed packages, your PEAR installation will have its files placed where your current include_path is expecting to find them.

Answer:

Does PhpDocumentor/phpDocumentor/phpdoc.inc exist? Does it exist in /usr/share/pear ? If the answers are “yes” and “no” respectively, then you need to add whatever dir PhpDocumentor is in to your include path.

Long story short, find phpdoc.inc, and then work from there.