Setting up a Linux development environment

Introduction

This is a step-by-step guide for setting up a Linux development environment for Apache log4php.

At the end of this procedure you will be able to:

  • run unit tests
  • generate site and documentation
  • create a new release
  • have a good starting point for development

This guide starts with a clean installation of Ubuntu 11.04 (Natty Narwhal). No optional packages (such as web server, php, lampp, etc.) have been installed during OS installation.

The OS installation is not covered by this document.

Root access is presumed. If you are not logged in as root, you must prefix each command with "sudo". To log in as root in Ubuntu, first log in as user, then execute "sudo su -".

Requirements overview

Requirements:

Required PHP extensions:

  • PDO_SQLITE for testing the PDO appender
  • mongo for testing the MongoDB appender
  • cURL is a pre-requisite for PHPUnit

Required PEAR components:

Installing components

Most required components are available from the Ubuntu package repository.

# Make sure apt is updated and upgrade the installation
apt-get update
apt-get upgrade

# Install make (later required for compiling)
apt-get install make

# Install git
apt-get install git

# Install Apache Maven
apt-get install maven

# Install php5, required extensions and PEAR
apt-get install php5-cli php5-sqlite php5-xdebug php5-curl php-pear

PEAR

At the time of writing this guide, some of the packages (namely PackageFileManager2) had dependancies which were not yet stable. This will cause the following error:

Failed to download <dependancy package> within preferred state "stable", latest release is version <version>, stability "beta"...

To install them, PEAR has to be adjusted to accept beta packages (be sure to switch it back to stable afterwards):

pear config-set preferred_state beta
pear install <package>
pear config-set preferred_state stable

First, make sure that PEAR is fully upgraded, and enable auto-discovery of cahnnels:

pear upgrade
pear config-set auto_discover 1

The following packges can be installed from PEAR and PECL:

# Install phpunit
pear install pear.phpunit.de/PHPUnit

# Install apigen
pear install pear.apigen.org/apigen

# Install the PEAR package manager
pear install PEAR_PackageFileManager2

MongoDB

Prerequisites for testing the MongoDB appender.

# Install mongoDB server
apt-get install mongodb

# Install mongoDB PHP extension
pecl install mongo

To activate mongo extension, add the following line to the php.ini file:

extension=mongo.so

Apache Maven 3 manual install

On newer Ubuntu distributions Apache Maven is available in the package repository. Disregard this chapter if you have already installed it using apt-get or similar.

However if not, you can install manually by following the following steps.

Instaling java

Java runtime must be installed to run Apache Maven. OpenJDK runtime works.

apt-get install openjdk-6-jre

Instaling Apache Maven

Download the latest 3.x binaries from the Maven download page and unpack them to a desired location. These instructions assume you chose /usr/local/apache-maven.

# Download the binaries
cd /tmp
wget http://ftp.carnet.hr/misc/apache//maven/binaries/apache-maven-3.0.3-bin.tar.gz

# Extract to desired location
mkdir /usr/local/apache-maven
tar xzvf /tmp/apache-maven-3.0.3-bin.tar.gz -C /usr/local/apache-maven

# Delete the archive
rm apache-maven-3.0.3-bin.tar.gz

Setting environment variables

Maven requires several environment variables to work.

export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/jre/
export M2_HOME=/usr/local/apache-maven/apache-maven-3.0.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

If bash shell is used, these lines can be added to the end of the ~/.bashrc file so they will be automatically applied on each logon.

Testing the installation

Test the installation by running:

mvn --version

This should produce output similar to:

Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: /usr/local/apache-maven/apache-maven-3.0.3
Java version: 1.6.0_22, vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/java-6-openjdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.38-8-server", arch: "amd64", family: "unix"

Testing the environment

Now all required software has been installed.

Clone the Apache log4php source repository.

git clone https://git-wip-us.apache.org/repos/asf/logging-log4php.git log4php

Now you can:

# Generate the web site
mvn site

# Perform unit testing
mvn test

# Create distribution packages
mvn package

Note that Maven will download it's own dependancies as required. This may take a while, but it is only performed once.

  • No labels