Apache2 + PHP5 + MySQL + xDebug + SSL + SVN + Python + Trac on Ubuntu Hardy (8.04) 64 bits

After setting up Ubuntu Hardy 64 bits (also known as AMD64) on my PC I had to do what every developer needs to do every now and then: set up my working environment. This is not a hard thing to do on Ubuntu, particularly if you choose to go with precompiled packages, installing them through the friendly Synaptic Package Manager. However, I do like to keep a tight control on what is the base of my day to day work, so instead of using the built-in packages, I chose to build them from source. Once again, this is not hard, but it can bring some complications for 64 bits environments. As I may probably need to do this once again in the future, I’ve decided to blog this guide on how to install the following packages on Ubuntu 8.04 64 bits: Apache 2 (with SSL support), PHP5 with xDebug, MySQL 5, Python through mod_python, SVN (client and server), and Trac integrated with SVN.

Setting up the Basics

As I said, we will install each package by building them from source. However, in order to do so we have lots of dependencies. The most important ones will also be built from source, but others we can safely get from the package manager. So without any further explanation, let’s go ahead and install those basic dependencies (I did mean to actually break it down so you could see which software needed which package, but its very late in the AM and I’m too tired to do that now):

$ sudo apt-get install build-essential
$ sudo apt-get install libncurses5-dev
$ sudo apt-get install libxml2-dev
$ sudo apt-get install libcurl4-openssl-dev
$ sudo apt-get install libpng12-dev
$ sudo apt-get install autoconf
$ sudo apt-get install libtool


This is a pre-requisite for MySQL and PHP, so let’s build it from source.

$ cd /usr/local/src/
$ sudo wget http://www.zlib.net/zlib-1.2.3.tar.gz
$ sudo tar xzvf zlib-1.2.3.tar.gz
$ sudo chown -R $USER:$USER zlib-1.2.3
$ cd zlib-1.2.3/
$ ./configure --prefix=/usr/local/zlib

Before proceeding with the build, we need to slightly modify the Makefile so we don’t get compile errors when trying to compile on a 64 bit environment. So go ahead and open the make file:

$ gksudo gedit Makefile

and change the CFLAGS line to:


Now let’s build and install:

$ make
$ sudo make install



$ cd /usr/local/src/
$ sudo wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.51b.tar.gz/from/http://mysql.patan.com.ar/
$ chown -R $USER:$USER mysql-5.0.51b
$ sudo groupadd mysql
$ sudo useradd -g mysql mysql
$ ./configure \
	--prefix=/usr/local/mysql \
	--with-mysqld-user=mysql \
	--without-debug \
	--with-client-ldflags=-all-static \
	--with-mysqld-ldflags=-all-static \
	--disable-shared \
	--localstatedir=/usr/local/mysql/data \
	--with-extra-charsets=none \
	--enable-assembler \
	--with-zlib-dir=/usr/local/zlib \
	--with-unix-socket-path=/tmp/mysql.socket \
$ make
$ sudo make install
$ sudo rm -f /usr/local/mysql/lib/mysql/libz.a
$ sudo cp /usr/local/zlib/lib/libz.a /usr/local/mysql/lib/mysql/libz.a

The following is only needed the first time you build MySQL, so avoid doing it when you are actually re-building:

$ sudo cp support-files/my-medium.cnf /etc/my.cnf
$ sudo /usr/local/mysql/bin/mysql_install_db --user=mysql
$ sudo chown -R root /usr/local/mysql/
$ sudo chown -R mysql /usr/local/mysql/data
$ sudo chgrp -R mysql /usr/local/mysql/
$ sudo cp support-files/mysql.server /etc/init.d/mysql
$ sudo chmod +x /etc/init.d/mysql
$ sudo update-rc.d mysql defaults
$ sudo /etc/init.d/mysql stop
$ sudo /etc/init.d/mysql start
$ /usr/local/mysql/bin/mysqladmin -u root password password

Now let’s default the MySQL server to use utf8 encoding. Open the MySQL configuration file:

$ gksudo gedit /etc/my.cnf

And right after the [mysqld] line place the following:


Now look for the line [mysql] and right after it add:


Finish up by restarting the MySQL server:

$ sudo /etc/init.d/mysql stop
$ sudo /etc/init.d/mysql start

Apache 2


$ cd /usr/local/src/
$ sudo wget http://apache.xmundo.com.ar/httpd/httpd-2.2.8.tar.gz
$ sudo tar xzvf httpd-2.2.8.tar.gz
$ sudo chown -R $USER:$USER httpd-2.2.8
$ cd /usr/local/src/httpd-2.2.8/srclib/apr
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
$ cd /usr/local/src/httpd-2.2.8/srclib/apr-util
$ ./configure --prefix=/usr/local --with-apr=/usr/local
$ make
$ sudo make install
$ cd /usr/local/src/httpd-2.2.8
$ ./configure \
	--prefix=/usr/local/apache2 \
	--with-apr=/usr/local \
	--with-apr-util=/usr/local \
	--enable-dav \
	--enable-dav-lock \
	--enable-rewrite \
	--enable-ssl \
	--enable-mods-shared=all \
$ make
$ sudo make install

The following instructions (everything until the next software package install) is only needed the first time you build Apache, so avoid doing it when you are actually re-building.

$ sudo cp /usr/local/apache2/bin/apachectl /etc/init.d/apachectl
$ sudo chmod +x /etc/init.d/apachectl
$ sudo /usr/sbin/update-rc.d apachectl defaults
$ sudo adduser --system apache
$ gksudo gedit /usr/local/apache2/conf/httpd.conf

Once the editor has opened the file /usr/local/apache2/conf/httpd.conf, change the following lines:

User daemon
Group daemon


User apache
Group nogroup

Now let’s enable SSL support. Once again this is only during your first build of Apache and it is not needed during re-builds. Let’s edit the main Apache configuration file:

$ gksudo gedit /usr/local/apache2/conf/httpd.conf

Uncomment the following line (if it’s commented out):

Include conf/extra/httpd-ssl.conf

And make sure the following line is not commented out (if it is commented out, uncomment it to enable; if the line doesn’t exist, add it):

LoadModule ssl_module modules/mod_ssl.so

Let’s create the certificate for our server. When you are asked for information do not forget to specify the CommonName.

$ cd /usr/local/apache2/conf
$ sudo openssl genrsa -des3 -out server.key 1024
$ sudo openssl req -new -key server.key -out server.csr
$ sudo openssl x509 -req -days 730 -in server.csr -signkey server.key -out server.crt
$ sudo cp server.key server.key.cryp
$ sudo openssl rsa -in server.key.cryp -out server.key
$ sudo chmod 400 server.key

Now edit the SSL configuration file in Apache:

$ gksudo gedit /usr/local/apache2/conf/extra/httpd-ssl.conf

And make sure the ServerName line reflects your server name. You can now reload apache:

$ sudo /etc/init.d/apachectl stop
$ sudo /etc/init.d/apachectl start


DEPENDS ON: Apache 2

$ cd /usr/local/src
$ sudo wget http://ar2.php.net/get/php-5.2.6.tar.gz/from/ar.php.net/mirror
$ sudo tar xzvf php-5.2.6.tar.gz
$ sudo chown -R $USER:$USER php-5.2.6/
$ cd php-5.2.6
$ ./configure \
	--prefix=/usr/local/php \
	--with-config-file-path=/usr/local/php \
	--with-apxs2=/usr/local/apache2/bin/apxs \
	--with-libxml-dir=/usr/include/libxml2 \
	--with-mysql=/usr/local/mysql \
	--with-zlib=/usr/local/zlib \
	--enable-force-cgi-redirect \
	--disable-cgi \
	--with-curl \
	--with-gd \
	--with-gettext \
	--enable-mbstring \
$ make
$ sudo make install
$ sudo /sbin/ldconfig
$ sudo cp /usr/local/src/php-5.2.6/php.ini-recommended /usr/local/php/php.ini
$ sudo /etc/init.d/apachectl stop
$ sudo /etc/init.d/apachectl start



$ cd /usr/local/src
$ sudo wget http://xdebug.org/link.php?url=xdebug203
$ sudo tar xzvf xdebug-2.0.3.tgz
$ sudo chown -R $USER:$USER xdebug-2.0.3/
$ cd xdebug-2.0.3
$ /usr/local/php/bin/phpize
$ ./configure --enable-xdebug \
$ make
$ cp modules/xdebug.so /usr/local/php/lib/php/

The following is only needed the first time you build xDebug, so avoid doing it when you are actually re-building. Let’s now enable xDebug on our php.ini file. Open the file for editing:

$ gksudo gedit /usr/local/php/php.ini

And add the following lines just before the [Date] line


; Remote settings

; General

; Trace options

; Profiling

Python (with mod_python, SWIG bindings, and mysql_python)


$ cd /usr/local/src
$ sudo wget http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz
$ sudo tar xzvf Python-2.5.2.tgz
$ sudo chown -R $USER:$USER Python-2.5.2/
$ cd Python-2.5.2.tgz
$ ./configure --prefix=/usr/local/python \
$ make
$ sudo make install
$ cd /usr/local/src
$ sudo wget http://apache.adcserver.com.ar/httpd/modpython/mod_python-3.3.1.tgz
$ sudo tar xzvf mod_python-3.3.1.tgz
$ sudo chown -R $USER:$USER mod_python-3.3.1/
$ cd mod_python-3.3.1
$ ./configure \
	--with-apxs=/usr/local/apache2/bin/apxs \
	--with-python=/usr/local/python/bin/python \
$ make
$ sudo make install
$ cd /usr/local/src
$ sudo wget http://prdownloads.sourceforge.net/swig/swig-1.3.35.tar.gz
$ sudo tar xzvf swig-1.3.35.tar.gz
$ sudo chown -R $USER:$USER swig-1.3.35/
$ cd swig-1.3.35
$ ./configure \
	--prefix=/usr/local/swig \
	--with-python=/usr/local/python/bin/python \
$ make
$ sudo make install
$ cd /usr/local/src
$ sudo wget http://downloads.sourceforge.net/mysql-python/MySQL-python-1.2.2.tar.gz?modtime=1172959928&big_mirror=0
$ sudo tar xzvf MySQL-python-1.2.2.tar.gz
$ sudo chown -R $USER:$USER MySQL-python-1.2.2/
$ cd MySQL-python-1.2.2

Since we also have built in MySQL support for PHP5 on our Apache, I needed to build MySQL-python with embedded libraries, or otherwise mod_python would complain about it. This probably means that whenever you re-build MySQL you’ll also need to rebuild its python support. So let’s open the MySQL-python configuration file:

$ gksudo gedit /usr/local/src/MySQL-python-1.2.2/site.cfg

And change lines:

embedded = False
mysql_config = /usr/local/bin/mysql_config


embedded = True
mysql_config = /usr/local/mysql/bin/mysql_config

Let’s now build and install:

$ sudo /usr/local/python/bin/python setup.py install

Since you probably have already installed (whithout even knowing) python on your Ubuntu box (through a software package, for example, AWN Manager), we need to tell Apache to use our custom Python build. So let’s open the Apache launcher for editing:

$ gksudo gedit /etc/init.d/apachectl

And let’s add the following lines right after the ULIMIT_MAX_FILES line:

# Set Python PATH
export PATH="/usr/local/python/bin:$PATH"

Let’s finish by restarting Apache:

$ sudo /etc/init.d/apachectl stop
$ sudo /etc/init.d/apachectl start


This is a pre-requisite for SVN, so let’s build it from source. Eventhough there’s a newer version (0.28.2 at the time of this writing), I found that there are known issues with SVN and Neon that only let us install the 0.25.5 version. You are welcome to try a newer version, but if it doesn’t work go back to 0.25.5.

$ sudo wget http://www.webdav.org/neon/neon-0.25.5.tar.gz
$ sudo tar xzvf neon-0.25.5.tar.gz
$ sudo chown -R $USER:$USER neon-0.25.5/
$ cd neon-0.25.5/
$ ./configure \
	--prefix=/usr/local/neon \
	--with-ssl \
$ make
$ sudo make install

Subversion (with Python bindings)

DEPENDS ON: Neon, Swig, Apache 2, Python

$ cd /usr/local/src
$ sudo wget http://subversion.tigris.org/downloads/subversion-1.4.6.tar.gz
$ sudo tar xzvf subversion-1.4.6.tar.gz
$ sudo chown -R $USER:$USER subversion-1.4.6/
$ cd subversion-1.4.6/
$ sh autogen.sh
$ ./configure \
	--prefix=/usr/local \
	--with-apxs=/usr/local/apache2/bin/apxs \
	--with-httpd \
	--with-apr=/usr/local \
	--with-apr-util=/usr/local \
	--with-neon=/usr/local/neon \
	--with-swig=/usr/local/swig/bin/swig \
$ make
$ sudo make install
$ make swig-py
$ sudo make install-swig-py
$ sudo cp -R /usr/local/lib/svn-python/* /usr/local/python/lib/python2.5/site-packages
$ sudo ldconfig
$ sudo mkdir /var/lib/svn
$ sudo mkdir /var/lib/svn/repository
$ sudo chown -R apache:root /var/lib/svn/repository
$ sudo chmod -R 770 /var/lib/svn/repository
$ sudo chmod -R g+ws /var/lib/svn

Let’s create our first SVN user (replace $USER with your desired SVN user name):

$ sudo /usr/local/apache2/bin/htpasswd -c /var/lib/svn/dav_svn.passwd $USER

Now let’s enable SVN over http with SSL. Open the main Apache configuration file:

$ gksudo gedit /usr/local/apache2/conf/httpd.conf

Look for the line “#Include conf/extra/httpd-dav.conf” and right after it add the following:

Include conf/extra/dav_svn.conf

Now let’s create that file:

$ gksudo gedit /usr/local/apache2/conf/extra/dav_svn.conf

And place the following contents on it:

<Location /svn>
    DAV svn
    SVNParentPath /var/lib/svn/repository
    AuthType Basic
    AuthName "SVN repository"
    AuthUserFile /var/lib/svn/dav_svn.passwd
    Require valid-user

Restart Apache:

$ sudo /etc/init.d/apachectl stop
$ sudo /etc/init.d/apachectl start

As an example, let’s create an SVN project called test:

$ sudo svnadmin create /var/lib/svn/repository/test
$ sudo chown -R apache:root /var/lib/svn/repository/test

You will now have SVN access to that project using the URL https://SERVER/svn/test

Trac (with SVN integration)

DEPENDS ON: Subversion, MySQL, Python

$ cd /usr/local/src
$ sudo wget http://ftp.edgewall.com/pub/trac/Trac-0.11rc1.tar.gz
$ sudo tar xzvf Trac-0.11rc1.tar.gz
$ sudo chown -R $USER:$USER Trac-0.11rc1/
$ cd Trac-0.11rc1
$ sudo /usr/local/python/bin/python ./setup.py install --prefix=/usr/local/python
$ sudo mkdir /var/lib/trac

Now let’s edit the main Apache configuration file:

$ gksudo gedit /usr/local/apache2/conf/httpd.conf

And add the following at the end:

<Location /trac>
  SetHandler mod_python
  PythonInterpreter main_interpreter
  PythonHandler trac.web.modpython_frontend 
  PythonOption TracEnvParentDir /var/lib/trac
  PythonOption TracUriRoot /trac

Restart Apache:

$ sudo /etc/init.d/apachectl stop
$ sudo /etc/init.d/apachectl start

As an example, let’s add Trac support to our SVN project called test. We then first create the MySQL database, and then run the tracd program to set up the environment. When you are asked for the database URL specify: “mysql://root:password@localhost/trac_test”:

$ mysqladmin -uroot -ppassword create trac_test
$ sudo /usr/local/python/bin/trac-admin /var/lib/trac/test initenv

You can now access your trac installation for the test project using the URL: http://server/trac/test

Leave a Comment

4 Comments to "Apache2 + PHP5 + MySQL + xDebug + SSL + SVN + Python + Trac on Ubuntu Hardy (8.04) 64 bits"

  1. Jun092008 at 4:37 am

    Felix Geisendörfer [Visitor] wrote:

    Looks good. Glad to see you being back to a *nix environment!

  2. Jun102008 at 12:00 am

    Kevin [Visitor] wrote:

    Great post. Even though I’ve done basically the same thing a couple of times myself, I still picked up a couple of new things.

    Just out of curiosity, what do you use for your xdebug remote debugging client?

  3. Jul132008 at 3:41 am

    Danilo Domínguez P [Visitor] wrote:

    Muchas gracias por el post. Excelente, de verdad me ayudó mucho.

    Saludos …

  4. Mar052009 at 1:16 pm

    anderson [Visitor] wrote:

    Cara, show de bola seu tutorial, muito bom mesmo, obrigado.

Powered by Wordpress and MySQL. Clauz's design for by Cricava