Installing Zend Framework on Ubuntu (Hardy)

As of the 8.04 Hardy release of Ubuntu, Zend Framework has been added to the repositories, so you can install it by simply running:

sudo apt-get install zend-framework

The package installs 17M of files into /usr/share/php/libzend-framework-php/.

Once that has finished, you then need to ensure that the framework is in your PHP include path. The best way to do this is to add the include to your PHP scripts directly, or better still via a global include file. The line you would need to add is:

set_include_path(get_include_path().PATH_SEPARATOR.'/usr/share/php/libzend-framework-php');

An example project would then look like:

set_include_path(get_include_path().PATH_SEPARATOR.'/usr/share/php/libzend-framework-php');
require_once 'Zend/Mail.php';
$mail = new Zend_Mail();
$mail->setBodyText('My Nice Test Text');
$mail->setBodyHtml('My Nice Test Text');
$mail->setFrom('[email protected]', 'Mr Example');
$mail->addTo('[email protected]', 'Mr Test');
$mail->setSubject('TestSubject');
$mail->send();

As Andy pointed out in a comment, Zend Framework is evolving quite rapidly, so if the Ubuntu repository version fails to meet your needs, then you could easily install and switch to a newer version for certain projects if you modify the include path this way.

← Back to Blog