Home > Article > Backend Development > Using the PEAR package manager
Through the PEAR package manager, you can browse and search contributed packages, view the latest releases, and download these packages. The syntax for executing it on the command line is as follows: %>pear [options] command [command-options]
Open a command line prompt and execute %>pear, which will output a set of commonly used commands and some usage information.
%>pear help
1. View the installed PEAR package
%>pear list
2. Learn more about the installed PEAR package
%>pear info package name
3. Install the PEAR package
Syntax: %>pear install [options] package
Suppose, for example, you want to install an Auth package: %>pear install Auth
From the execution output of the command, you can see that many packages have some options dependency packages, if they are also installed, some available features can be expanded.
3.1. Automatically install all dependencies
Later PEAR versions will install any necessary dependencies by default. However, you may also want to install optional dependencies. At this time, pass -a which is the --alldeps option:
%>pear install -a Auth_HTTP
3.2. Manually install a package from PEAR Web Site
The PEAR package manager installs the latest stable version by default Bag. But if you want to install a previous version of the package, or you cannot use the package manager at all (because of some management restrictions on the shared server), then you can go to pear.php.net and find what you need package. If you know the package name, just add the package name to the end of the URL just now, which is a shortcut. The format of these packages is tgz.
Then, extract the downloaded tgz format file to the appropriate location. If you are forced to follow this installation process because you want to bypass ISP restrictions, then creating a PEAR directory in your home directory will suffice. Regardless, make sure the directory is in include_path.
4. Include the package into the script
Using the PEAR package is very simple, just use include or require to make the package content available to the script. Remember, PEAR's base directory needs to be added to the include_path directive.
require_once("Numbers/Roman.php")
5. Upgrade package
Syntax for upgrading a single package: %>pear upgrade [package name]. For example, sometimes you want to upgrade the PEAR package responsible for managing your package environment, then you can execute %>pear upgrade pear
to upgrade all packages: %>pear upgrade-all. Although unlikely, it is possible that some future package versions will be incompatible with previous versions. Therefore, it is not recommended to use this command unless you are clear about the consequences of upgrading each package.
6. Uninstall a package
%>pear uninstall [options] package name
For example: %>pear uninstall Numbers_Roman
If there are other packages that depend on the package you want to uninstall, one of these dependent packages will be output. list, uninstallation will also fail. You can use the -n
--nodeps option to force uninstallation, but this is not recommended because other packages that depend on the package you uninstalled will not work properly. Therefore, those dependent packages should be uninstalled first. Multiple packages can be uninstalled at once.
%>pear uninstall package1 package2 packageN
7. Downgrade PEAR package
There is no available method to downgrade a package through the package manager. To do this, you can go to http://pear.php.net to download a satisfactory version, then uninstall the previously installed version, and finally install the package you just downloaded.