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):
1 | $ sudo apt-get install build-essential |
2 | $ sudo apt-get install libncurses5-dev |
3 | $ sudo apt-get install libxml2-dev |
4 | $ sudo apt-get install libcurl4-openssl-dev |
5 | $ sudo apt-get install libpng12-dev |
6 | $ sudo apt-get install autoconf |
7 | $ sudo apt-get install libtool |
zLib
This is a pre-requisite for MySQL and PHP, so let’s build it from source.
3 | $ sudo tar xzvf zlib-1.2.3. tar .gz |
4 | $ sudo chown -R $USER:$USER zlib-1.2.3 |
6 | $ ./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:
and change the CFLAGS line to:
1 | CFLAGS=-O3 -DUSE_MMAP -fPIC -m64 |
Now let’s build and install:
MySQL
DEPENDS ON: zLib
03 | $ chown -R $USER:$USER mysql-5.0.51b |
05 | $ sudo useradd -g mysql mysql |
07 | --prefix=/usr/ local /mysql \ |
08 | --with-mysqld-user=mysql \ |
10 | --with-client-ldflags=-all-static \ |
11 | --with-mysqld-ldflags=-all-static \ |
13 | --localstatedir=/usr/ local /mysql/data \ |
14 | --with-extra-charsets=none \ |
16 | --with-zlib- dir =/usr/ local /zlib \ |
17 | --with-unix-socket-path=/tmp/mysql.socket \ |
18 | CXXFLAGS=-fPIC CFLAGS=-fPIC CPPFLAGS=-fPIC |
21 | $ sudo rm -f /usr/ local /mysql/lib/mysql/libz.a |
22 | $ 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:
01 | $ sudo cp support-files/my-medium.cnf /etc/my.cnf |
02 | $ sudo /usr/ local /mysql/bin/mysql_install_db --user=mysql |
03 | $ sudo chown -R root /usr/ local /mysql/ |
04 | $ sudo chown -R mysql /usr/ local /mysql/data |
05 | $ sudo chgrp -R mysql /usr/ local /mysql/ |
06 | $ sudo cp support-files/mysql.server /etc/init.d/mysql |
07 | $ sudo chmod +x /etc/init.d/mysql |
08 | $ sudo update-rc.d mysql defaults |
09 | $ sudo /etc/init.d/mysql stop |
10 | $ sudo /etc/init.d/mysql start |
11 | $ /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:
1 | $ gksudo gedit /etc/my.cnf |
And right after the [mysqld] line place the following:
1 | character_set_server=utf8 |
2 | skip-character- set -client-handshake |
Now look for the line [mysql] and right after it add:
1 | default-character- set =utf8 |
Finish up by restarting the MySQL server:
1 | $ sudo /etc/init.d/mysql stop |
2 | $ sudo /etc/init.d/mysql start |
Apache 2
DEPENDS ON: zLib
03 | $ sudo tar xzvf httpd-2.2.8. tar .gz |
04 | $ sudo chown -R $USER:$USER httpd-2.2.8 |
05 | $ cd /usr/ local /src/httpd-2.2.8/srclib/apr |
06 | $ ./configure --prefix=/usr/ local |
09 | $ cd /usr/ local /src/httpd-2.2.8/srclib/apr-util |
10 | $ ./configure --prefix=/usr/ local --with-apr=/usr/ local |
13 | $ cd /usr/ local /src/httpd-2.2.8 |
15 | --prefix=/usr/ local /apache2 \ |
16 | --with-apr=/usr/ local \ |
17 | --with-apr-util=/usr/ local \ |
22 | -- enable -mods-shared=all \ |
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.
1 | $ sudo cp /usr/ local /apache2/bin/apachectl /etc/init.d/apachectl |
2 | $ sudo chmod +x /etc/init.d/apachectl |
3 | $ sudo /usr/sbin/update-rc.d apachectl defaults |
4 | $ sudo adduser --system apache |
5 | $ 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:
to:
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:
1 | $ gksudo gedit /usr/ local /apache2/conf/httpd.conf |
Uncomment the following line (if it’s commented out):
1 | 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):
1 | 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.
1 | $ cd /usr/ local /apache2/conf |
2 | $ sudo openssl genrsa -des3 -out server.key 1024 |
3 | $ sudo openssl req -new -key server.key -out server.csr |
4 | $ sudo openssl x509 -req -days 730 - in server.csr -signkey server.key -out server.crt |
5 | $ sudo cp server.key server.key.cryp |
6 | $ sudo openssl rsa - in server.key.cryp -out server.key |
7 | $ sudo chmod 400 server.key |
Now edit the SSL configuration file in Apache:
1 | $ 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:
1 | $ sudo /etc/init.d/apachectl stop |
2 | $ sudo /etc/init.d/apachectl start |
PHP5
DEPENDS ON: Apache 2
03 | $ sudo tar xzvf php-5.2.6. tar .gz |
04 | $ sudo chown -R $USER:$USER php-5.2.6/ |
07 | --prefix=/usr/ local /php \ |
08 | --with-config- file -path=/usr/ local /php \ |
09 | --with-apxs2=/usr/ local /apache2/bin/apxs \ |
10 | --with-libxml- dir =/usr/include/libxml2 \ |
11 | --with-mysql=/usr/ local /mysql \ |
12 | --with-zlib=/usr/ local /zlib \ |
13 | -- enable -force-cgi-redirect \ |
23 | $ sudo cp /usr/ local /src/php-5.2.6/php.ini-recommended /usr/ local /php/php.ini |
24 | $ sudo /etc/init.d/apachectl stop |
25 | $ sudo /etc/init.d/apachectl start |
xDebug
DEPENDS ON: PHP5
03 | $ sudo tar xzvf xdebug-2.0.3.tgz |
04 | $ sudo chown -R $USER:$USER xdebug-2.0.3/ |
06 | $ /usr/ local /php/bin/phpize |
07 | $ ./configure -- enable -xdebug \ |
08 | --with-php-config=/usr/ local /php/bin/php-config |
10 | $ 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:
1 | $ gksudo gedit /usr/ local /php/php.ini |
And add the following lines just before the [Date] line
01 | zend_extension=/usr/local/php/lib/php/xdebug.so |
05 | xdebug.remote_autostart=off |
06 | xdebug.remote_enable=on |
07 | xdebug.remote_handler=dbgp |
09 | xdebug.remote_host=localhost |
10 | xdebug.remote_port=9000 |
14 | xdebug.collect_includes=on |
15 | xdebug.collect_params=off |
16 | xdebug.collect_return=off |
17 | xdebug.default_enable=on |
20 | xdebug.show_local_vars=0 |
21 | xdebug.show_mem_delta=0 |
22 | xdebug.max_nesting_level=250 |
27 | xdebug.trace_output_dir=/tmp |
29 | xdebug.trace_output_name=crc32 |
32 | xdebug.profiler_append=0 |
33 | xdebug.profiler_enable=0 |
34 | xdebug.profiler_enable_trigger=0 |
35 | xdebug.profiler_output_dir=/tmp |
36 | xdebug.profiler_output_name=crc32 |
Python (with mod_python, SWIG bindings, and mysql_python)
DEPENDS ON: Apache 2, MySQL
03 | $ sudo tar xzvf Python-2.5.2.tgz |
04 | $ sudo chown -R $USER:$USER Python-2.5.2/ |
06 | $ ./configure --prefix=/usr/ local /python \ |
07 | CFLAGS=-fPIC CPPFLAGS=-fPIC |
12 | $ sudo tar xzvf mod_python-3.3.1.tgz |
13 | $ sudo chown -R $USER:$USER mod_python-3.3.1/ |
16 | --with-apxs=/usr/ local /apache2/bin/apxs \ |
17 | --with-python=/usr/ local /python/bin/python \ |
18 | CFLAGS=-fPIC CPPFLAGS=-fPIC |
23 | $ sudo tar xzvf swig-1.3.35. tar .gz |
24 | $ sudo chown -R $USER:$USER swig-1.3.35/ |
27 | --prefix=/usr/ local /swig \ |
28 | --with-python=/usr/ local /python/bin/python \ |
29 | CFLAGS=-fPIC CPPFLAGS=-fPIC |
34 | $ sudo tar xzvf MySQL-python-1.2.2. tar .gz |
35 | $ sudo chown -R $USER:$USER MySQL-python-1.2.2/ |
36 | $ 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:
1 | $ gksudo gedit /usr/ local /src/MySQL-python-1.2.2/site.cfg |
And change lines:
2 | mysql_config = /usr/local/bin/mysql_config |
to:
2 | mysql_config = /usr/local/mysql/bin/mysql_config |
Let’s now build and install:
1 | $ 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:
1 | $ gksudo gedit /etc/init.d/apachectl |
And let’s add the following lines right after the ULIMIT_MAX_FILES line:
4 | export PATH= "/usr/local/python/bin:$PATH" |
Let’s finish by restarting Apache:
1 | $ sudo /etc/init.d/apachectl stop |
2 | $ sudo /etc/init.d/apachectl start |
Neon
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.
02 | $ sudo tar xzvf neon-0.25.5. tar .gz |
03 | $ sudo chown -R $USER:$USER neon-0.25.5/ |
06 | --prefix=/usr/ local /neon \ |
08 | CXXFLAGS=-fPIC CFLAGS=-fPIC CPPFLAGS=-fPIC |
Subversion (with Python bindings)
DEPENDS ON: Neon, Swig, Apache 2, Python
03 | $ sudo tar xzvf subversion-1.4.6. tar .gz |
04 | $ sudo chown -R $USER:$USER subversion-1.4.6/ |
09 | --with-apxs=/usr/ local /apache2/bin/apxs \ |
11 | --with-apr=/usr/ local \ |
12 | --with-apr-util=/usr/ local \ |
13 | --with-neon=/usr/ local /neon \ |
14 | --with-swig=/usr/ local /swig/bin/swig \ |
15 | PYTHON=/usr/ local /python/bin/python |
19 | $ sudo make install -swig-py |
20 | $ sudo cp -R /usr/ local /lib/svn-python/* /usr/ local /python/lib/python2.5/site-packages |
22 | $ sudo mkdir /var/lib/svn |
23 | $ sudo mkdir /var/lib/svn/repository |
24 | $ sudo chown -R apache:root /var/lib/svn/repository |
25 | $ sudo chmod -R 770 /var/lib/svn/repository |
26 | $ sudo chmod -R g+ws /var/lib/svn |
Let’s create our first SVN user (replace $USER with your desired SVN user name):
1 | $ 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:
1 | $ 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:
1 | Include conf/extra/dav_svn.conf |
Now let’s create that file:
1 | $ gksudo gedit /usr/ local /apache2/conf/extra/dav_svn.conf |
And place the following contents on it:
4 | SVNParentPath /var/lib/svn/repository |
6 | AuthName "SVN repository" |
7 | AuthUserFile /var/lib/svn/dav_svn.passwd |
Restart Apache:
1 | $ sudo /etc/init.d/apachectl stop |
2 | $ sudo /etc/init.d/apachectl start |
As an example, let’s create an SVN project called test:
1 | $ sudo svnadmin create /var/lib/svn/repository/ test |
2 | $ 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
2 | $ sudo wget http:// ftp .edgewall.com/pub/trac/Trac-0.11rc1. tar .gz |
3 | $ sudo tar xzvf Trac-0.11rc1. tar .gz |
4 | $ sudo chown -R $USER:$USER Trac-0.11rc1/ |
6 | $ sudo /usr/ local /python/bin/python ./setup.py install --prefix=/usr/ local /python |
7 | $ sudo mkdir /var/lib/trac |
Now let’s edit the main Apache configuration file:
1 | $ gksudo gedit /usr/ local /apache2/conf/httpd.conf |
And add the following at the end:
3 | PythonInterpreter main_interpreter |
4 | PythonHandler trac.web.modpython_frontend |
5 | PythonOption TracEnvParentDir /var/lib/trac |
6 | PythonOption TracUriRoot /trac |
7 | SetEnv PYTHON_EGG_CACHE /tmp |
Restart Apache:
1 | $ sudo /etc/init.d/apachectl stop |
2 | $ 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”:
1 | $ mysqladmin -uroot -ppassword create trac_test |
2 | $ 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
REFERENCES
http://marianoiglesias.com.ar/ubuntu/apache2-php5-mysql-xdebug-ssl-svn-python-trac-on-ubuntu-hardy-8-04-64-bits/