Gentoo - Installing PHP modules

This article assumes you have installed apache and php.

In this article we'll look at using Gentoo's powerful package system to install external PHP modules, which are required by most modern PHP applications.

Add On Modules

There are more php libraries available than shown in our last article. You can get a list by searching through your copy of the Portage tree:

emerge -s "@dev-php" | less

You can move up and down the list with the arrow keys. Use 'ctrl+f' to move forward a whole page. Press 'q' to quit the listing.

Installing PEAR MDB2 - PHP Module

In this example we'll install the PEAR MDB2 module for mysql. Of course you may want to install different modules than demonstrated here, so just use this as a guide.

As usual, we'll see what options are available with a test install:

emerge -vp dev-php/PEAR-MDB2

In the output, we can see that the PEAR-MDB2 package has support for the 'mysql' and 'mysqli' flags:

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N    ] dev-php/PEAR-PEAR-1.6.2-r1  374 kB
[ebuild  N    ] dev-php/PEAR-MDB2-2.5.0_alpha2  USE="-mssql -mysql -mysqli -oci8
                                                     -oci8-instant-client -postgres -sqlite" 123 kB

In this example we're interested in using it with mysql, and we'll probably want to enable mysql support in other packages too, so lets enable those USE flags globally.

How to do this is shown in the Gentoo - Slice Setup article. Basically we'll be adding 'mysql mysqli' to the beginning of the USE option in '/etc/make.conf':

USE="mysql mysqli ..."

In the above example, '...' is not literal, but represents any flags entered there from the previous articles.

Once we're satisfied with the USE flags, we can install it for real:

sudo emerge dev-php/PEAR-MDB2

Installation Troubleshooting

In my case, the install failed and I got the error message:

* dev-lang/php-5.2.6-r7 needs to be re-installed with all of the following
 * USE flags enabled:
 *   cli pcre xml zlib

What an excellent opportunity to learn some Gentoo troubleshooting. To install 'PEAR-MDB2' we'll have to alter our USE flags for 'php'. To do this we can edit the file '/etc/portage/package.use' (just create it if it doesn't exist):

sudo nano /etc/portage/package.use

In the previous article (Gentoo - Installing PHP) we added the line starting with 'dev-lang/php'. We can now insert the newly required flags at the start of the same line:

dev-lang/php cli pcre xml zlib ...

Again, '...' is not literal, but represents any flags entered there from previous articles.

Once this file has been edited, we'll have to re-emerge php and PEAR-MDB2. A better technique however, would be to tell portage to automatically detect everything it needs to re-emerge due to USE flag changes, with the 'D' (deep) and 'N' (new-use flags) command line parameters, like this:

sudo emerge PEAR-MDB2 -vpDN

I've left the 'vp' in there so you can see what it would do. As always, adjust your USE flags as desired then repeat the command without the 'vp':

sudo emerge PEAR-MDB2 -DN

Once it's done, follow any instructions in the output, as you should always do when emerging.

All Done

Now you should be well on your way to getting PHP set up how you want it.

Next we'll talk more about the file layout used with Apache in gentoo, and how it differs from the classic file layout.

Want to comment?

(not made public)


(use plain text or Markdown syntax)