How to load a PEAR package - php

I've just installed a PEAR package (Event_Dispatcher) and I can't use the classes in that package. When I run the command pear list I see the new package, however I see that the classes in the package are saved in /usr/lib/php (I have a Mac).
Is there a loading part after installing a PEAR package? How exactly do I move the files to the right place? Can I simply cut and paste the folder to the pear root folder?
Thanks!

Most PEAR packages have to be included via the usual include() and require() functions. They're not precompiled binaries, like (say) the MySQL driver (mysql.so/mysql.dll) are. As long as /usr/lib/php is in your include_path, PHP should be able to load up the package automatically when you do include('nameofpackage.php').

When PEAR is installed it usually automagically configures your php.ini to add the PEAR library path to the php.ini. Then, for each package, the authors will usually provide a file that will load the library for you which sits in the root of this PEAR lib directory.
For example, a PEAR package MDB2 has a load of different classes located under /MDB2, but there's also a PHP script at /MDB2.php, so all you need to do from your PHP code is this:
require_once("MDB2.php").
You'll obviously need to keep track of what you have installed on your local dev machine and make sure it's installed on the production server(s) too.

Related

Composer installation questions

I am trying to get my head around how to install composer. Really confusing!
I have downloaded the windows installer and during the installation was asked to locate "php.exe". Does that mean I need to have a local server (Wamp) installed?
Lets say I manage to install composer on my PC. How do I get it to work on my web host? Do i copy files there or do I need to install composer on web host as well?
Composer requires php executable, but not webserver. So installing php from php site is sufficient. However, if you plan to develop or run php applications on your computer, you would prefer to install full stack (eg wamp) right away.
Composer is needed only to install and update dependencies, once you do it, all are just files, and you transfer them as you transfer other files to your webhost. So copy, no need to install composer on web host.

System or local when installing PEAR for PHPUnit

I am using XAMPP 1.8.1.
I need to write code with PHPUnit.
When I try to install PEAR using command prompt, I get the message below:
Are you installing a system-wide PEAR or a local copy?
Could some one suggest which option I should use?
Thanks in advance.
PEAR is usually installed system-wide. The benefit of this is that the various packages can be reused between different projects.
One reason why you might install a local copy of PEAR is that the administrator[s] of the server you are installing on might be reluctant to install additional packages or upgrade existing ones.
By performing a local install of PEAR you can choose the location of where the PEAR installer places the packages/PEAR code that you install.
So, another reason for installing local, even multiple, copies of PEAR is to have separate installs for each project you might be working on, though using Composer in this scenario is much more common place.
Naturally if you do install a local copy of PEAR then you will need to adjust your include-path accordingly.

How do I solve this PHP-PEAR error / install PEAR on Fedora?

I'm trying to save an old, failing web-server setup consisting of Fedora, PHP, PEAR, and Oracle.
With some difficulty (I'm very new to all four), I've been able to set up something similar on a newer system. I used Fedora 19, PHP 5.5.4 (with Apache 2.4.6), and Oracle 11g.
That just leaves PEAR.
Now, from what I understand, PEAR is some PHP code, like a library, which PHP Web Applications can use to save time from having to code them again - database connection, for example.
But I don't know what to do with it, or even how to get it. Copy paste from my old system? Download using the CLI using yum? Are there packages I need to be aware of, or is it just a one download-one install thing?
For instance, a basic PHP webpage with the following code:
<?php
phpinfo();
?>
works fine on the new server setup, so I'm assured that everything else is working. But when I try to load the PHP files from the other server, it returns an Internal Server Error. I checked the error_log files under /etc/httpd/logs, and most of the errors appear as below:
PHP Fatal error: require_once(): Failed opening required 'MDB2.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/hrweb/includes/functions.php on line 4
EDIT:
According to the PEAR Website, PEAR is included upon the installation of PHP, though not all modules / packages are there. Typing in the command pear in the CLI does confirm it is installed, though it does not help the issue.
I got the MDB2 package via pear install MDB2, though apparently, MDB2_Driver_oci8 is required. Whenever I try to download that, I get the following:
"MDB2_Driver_oci8" version "1.4.1" does not have REST XML available
In addition to this, I also tried to download OLE, which gets me the following:
No releases available for package "pear.php.net/OLE"
This was also previously the error of trying to download MDB2_Driver_oci8.
Thanks.
You have to install the (surprise!) MDB2 package to get MDB2.php:
$ pear install mdb2
and the adapter of your choice:
$ pear install mdb2_driver_mysql-beta
Then make sure the PEAR php directory is in your include path - see the PEAR manual.
"MDB2_Driver_oci8" version "1.4.1" does not have REST XML available
try to install the beta version:
$ pear install mdb2_driver_oci8-beta
No releases available for package "pear.php.net/OLE"
You're trying to install the stable version, but OLE does not have any stable version (yet): http://pear.php.net/package/OLE/download
Append either -alpha or -beta after OLE:
$ pear install OLE-beta

How to get Buildconf & Configure scripts for PHP5

Am trying to install a package which has given instructions to use Buildconf from the root of php build directory. In my php build directory's root(/etc/php5), I don't find a Buildconf or Configure script. How do I get these? I installed my php5 using sudo apt-get(yes, I have an Ubuntu).
What you probably have installed is PHP binary package, i.e. already built one. If you need to build a stand-alone PHP module, you may want to install package php5-dev and use utility /usr/bin/phpize5 to generate config files.
If what you really need is PHP source, you may download it from http://www.php.net/downloads.php. After you unpack the package, buildconf will be there.
If neither of these is what you need, I guess it would be helpful to post the instructions you received.

Installing PEAR on PHP 5?

I want to install PEAR on PHP 5, so I can use Spreadsheet_Excel_Writer.
I don`t know how to install it on my ISP nor my personal MacBook.
Thoughts for both?
The PEAR Manual has a quite extensive list of instructions on how to install the PEAR manager on Windows, *NIX and Mac OS X. The manual also has a section on installing PEAR remotely, for example using FTP. Following those instructions, you should be able to install PEAR (nearly) anywhere. :)
From the command line, do this:
pear install Spreadsheet_Excel_Writer
You can also download the package directly here without using PEAR: http://download.pear.php.net/package/Spreadsheet_Excel_Writer-0.9.1.tgz. It's pretty easy to use if you have the script located anywhere within your include path.
For your personal computer, using the "pear" script that ships with most PHP distributions is a good idea.
For shared hosting, you can
Track your dependencies manually, and copy all the appropriate files to the server yourself
With pear installed, do "pear install -R/my/root_dir -a Spreadsheet_Excel_Writer". This will install the package and all dependencies to the specified root directory. Copy this installation to your webhost.
You should also have a look at "pear help" and "pear help install".
You can't install pear to your isp's core. But you can install the individual files from pear's site and upload them to your host:
http://pear.php.net/package/Spreadsheet_Excel_Writer/download

Categories