Tutorial on how to Install Apache, Subversion and Trac with Virtual Hosting suppor in Ubuntu Linux
November 2, 2008
We recently had to setup Apache, Subversion and Trac all within a virtual hosting environment for one of our Clients to be able to develop easily and effictively among team members. They wanted to use multiple domain names for separate projects. Made sense to us, so we started looking for instructions on setting this up.
We wanted to setup LigHTTPD, however it's not nearly as easy because of no svn-dav module available, so we stuck with Apache 2 for now.
We found a howto on doing this, however there were a few vital steps and explanations missing so we've re-written it in hopes it will help others the trouble of searching to find this information.
So, lets move on to the tutorial shall we.
First install the required packages on your system. We started with a clean Ubuntu JEOS 8.0.4 Install on our server.
# sudo aptitude install enscript libapache2-mod-python python-docutils trac db4.3-util libapache2-svn subversion-tools
Now create a virtual host for your SVN container.
# mkdir -p /var/local/svn/svn.yourdomain.com
Now create a development group, and add the web user to it.
# addgroup svngroup; adduser www-data svngroup
Now Add a user to the system and add them to that group
# adduser username
# passwd username
Now add that user to the group required for SVN
# adduser username svngroup
Now setup the permissions for your SVN site.
# chmod 2770 /var/local/svn/svn.yourdomain.com
Now setup the repo as you normally would
# svnadmin create /var/local/svn/svn.yourdomain.com
Remove the current password file. We're using HTTPS (or HTTP) instead of SVNSERVE so no need for it.
# rm /var/local/svn/svn.yourdomain.com/conf/passwd
# touch /var/local/svn/svn.yourdomain.com/conf/passwd
Allow your group to write to the repo
# chmod -R g+w www-data:svngroup /var/local/svn/svn.yourdomain.com
Now set the repo access permissions.
# nano /var/local/svn/svn.yourdomain.com/conf/authz
It should look something similar to the following. If in doubt, refer to the Path-Based Auth section of Subversion.
[groups]
svngroup = username1,username2,username2
[/]
@svngroup = rw
Now, create a log directory within apache for your development site.
# mkdir /var/log/apache2/svn.yourdomain.com
Now create your virtual host.
# nano /etc/apache2/sites-available/svn.yourdomain.com
Copy the following in, editing to suit your environment. Note we're using a self signed certificate, you can change this to a properly signed one if you have it.
<VirtualHost [server's IP address]:443>
ServerName svn.yourdomain.com
<Location />
DAV svn
AuthType Basic
AuthName "svn.yourdomain.com"
AuthUserFile /var/local/svn/svn.yourdomain.com/conf/passwd
AuthzSVNAccessFile /var/local/svn/svn.yourdomain.com/conf/authz
SVNPath /var/local/svn/svn.yourdomain.com
Require valid-user
</Location>
CustomLog /var/log/apache2/svn.yourdomain.com/access.log combined
ErrorLog /var/log/apache2/svn.yourdomain.com/error.log
SSLEngine on
SSLCertificateFile /etc/ssl/certs/selfsigned.pem
# Add this once there is a real (non self-signed) certificate.
# SSLCertificateKeyFile /etc/apache2/ssl/server.key
</VirtualHost>
<VirtualHost [server's IP address]:80>
ServerName svn.yourdomain.com
Redirect / https://svn.yourdomain.com/
</VirtualHost>
Now, enable the site
# a2ensite svn.yourdomain.com
Now, create a username and password to access the svn site.
# htpasswd /var/local/svn/svn.yourdomain.com/conf/passwd username1
Now, create your SSL certificate. Details are here if you need them.
# sudo aptitude install ssl-cert
Now, we found out that the default Ubuntu SSL cert is only for 30 days, so, we changed this to be 365 a little more sane no? Thanks for the tip Devio.
# which make-ssl-cert
/usr/sbin/make-ssl-cert
# nano /usr/sbin/make-ssl-cert
Replace the line near the bottom that looks like this
openssl req -config $TMPFILE -new -x509 -nodes -out $output -keyout $output
With a line that looks like this instead
openssl req -config $TMPFILE -new -x509 -days 365 -nodes -out $output -keyout $output
Exit and save the file. Now we're ready to generate our final self signed SSL certificate for Apache on Ubuntu. Like this;
# make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/ssl/certs/selfsigned.pem
Make sure to set your "common name" to your server name - ie: svn.yourdomain.com
Now you can go ahead and restart Apache to verify your DAV enabled SVN site functions.
# /etc/init.d/apache2 restart
To verify, hit it's url in a browser
If everthing was successful, you now have SVN setup, with WEB-Dav support in Apache2 on Ubuntu. Continue to setup Trac.
First we have to create the web directory for Trac.
# mkdir -p /var/local/trac/trac.yourdomain.com
Now we setup the permissions
# chmod 2770 /var/local/trac/trac.yourdomain.com
Create a Trac instance for your project
# trac-admin /var/local/trac/trac.yourdomain.com initenv
Setup the proper ownerships for the directory
# chown -R www-data:svngroup /var/local/trac/trac.yourdomain.com
Now make sure the group is added to the repo
# chmod -R g+w /var/local/trac/trac.yourdomain.com
Configure Trac where required
# nano /var/local/trac/trac.yourdomain.com/conf/trac.ini
Create a directory for log files
# mkdir /var/log/apache2/trac.yourdomain.com
Now create a virtual host for your trac instance
# nano /etc/apache2/sites-available/trac.yourdomain.com
Now, copy the following into the virtual host configuration, changing to suit your domain and configuration
# Trac Configuration
<VirtualHost [server's IP address]:80>
ServerName trac.yourdomain.com
Redirect / https://trac.yourdomain.com/
</VirtualHost>
<VirtualHost [server's IP address]:443>
ServerName trac.yourdomain.com
DocumentRoot /var/local/trac/trac.yourdomain.com/
Alias /trac/ /usr/share/trac/htdocs
<Directory "/usr/share/trac/htdocs/">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Location />
SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonInterpreter main_interpreter
PythonOption TracEnv /var/local/trac/trac.yourdomain.com/
PythonOption TracUriRoot /
AuthType Basic
AuthName "trac.yourdomain.com"
# Use the SVN password file.
AuthUserFile /var/local/svn/svn.yourdomain.com/conf/passwd
Require valid-user
</Location>
CustomLog /var/log/apache2/trac.yourdomain.com/access.log combined
ErrorLog /var/log/apache2/trac.yourdomain.com/error.log
SSLEngine on
SSLCertificateFile /etc/ssl/certs/selfsigned.pem
# Add this once there is a real (non self-signed) certificate.
# SSLCertificateKeyFile /etc/apache2/ssl/server.key
</VirtualHost>
Now, enable this virtual host as well
# a2ensite trac.yourdomain.com
Configure Trac Permissions for your Trac instance.
# trac-admin /var/local/trac/trac.yourdomain.com
Use the following commands to view permissions, and set permissions.
"help permission"
We set the following permissions to one of our users from the command line
# trac-admin /var/local/trac/trac.yourdomain.com permission add username1 TRAC_ADMIN
Now you're ready to restart Apache with your new Trac VHOST.
# /etc/init.d/apache2 restart
Now you're ready to restart Apache and visit your Trac installation
Login with your user (username1) and password you setup earlier.
We hope this tutorial helps others when trying to setup SVN and Trac on Ubuntu with Virtual Hosts. Let us know if you have any other handy tips!
Migrating and Mounting VMWare Images from VMWare Server 2.x into a VMWare Server 1.x environment
September 5, 2008
Tonight we decided we'd had enough of VMWare Server 2.0's issues and shakiness. We started getting the following error, because as it turns out (we're stupid for not thinking of this ahead of time - lesson learned) VMWare server beta's have an expiry date, along with it's bugs. Today we started getting this error:
"VCommand error: This product has expired."
This box holds some Asterisk Development stuff and some other Dev systems that we couldn't really have go down on us. So, we downgraded our VMWare 2.x Server to the latest 1.x branch of VMWare. Then on we went to importing Virtual Machines from Server 2.0 and Workstation 6. As soon as we started to power them on, the fun started. Of course! The VM's weren't compatible anymore and gave us a couple errors. Here's how we fixed it.
The first error we received was:
"A General System Error Occurred: Unknown Error"
This happened as soon as we tried to power on the VM. This was easily fixed. We entered the Virtual Machine's directory, and edited the .vmx file for the virtual machine, this is just plain text. Replacing the next few lines fixed it right up for us.
config.version = "8"
virtualHW.version = "6"became
config.version = "4"
virtualHW.version = "4"
Now we could power them up. However, we now encountered another error that we couldn't open the virtual disk we had created. The error was something about how the Virtual Disks were created in a later version of vmware, and couldn't be mounted. We'd have to re-create them. Obviously this wasn't an option.
In some of the Virtual Machine directories, we had a file to edit with a text editor, this was simple enough.
# nano virtualdiskname.vmxf
Then change this:
ddb.virtualHWVersion = "6"
became
ddb.virtualHWVersion = "4"
However, some of the other directories (mainly the ones created with VmWare Workstation 6) did not have a simple text file to edit, instead we had to edit the actual virtual disk using a hex editor. We chose the wonderful heme editor. Usage Instructions for Heme are here.
Basically put, do this:
# heme virtualdisk.vmdk
Now press "w" on your keyboard to search for "virtualHWVersion". You will find it in the ascii column eventually. Hit "TAB" to enter Ascii mode, move your cursor with the arrow keys to where you need to replace the number. Replace the "8" or the "6" with a "4" and then press "s" to save the file. Answer yes to saving and then wait for it to save. Now exit the program by pressing "q". You'll notice it created a backup file with the "~" extension on it incase you messed up the hex editing. Leave this backup file here for now. Continue on, nothing to see here.
Now on the VMWare server, make sure that all the files in the virtual machine directory are chmodd'd properly.
# cd /virtual machine/directory/
# chown user:group *
# chmod og=rwx *
Now you should be able to start your vm without any issues.
If it all works, feel free to delete the backup .vmdk~ that heme created for you.
Good luck!
Monitoring Asterisk with SNMP, Nagios and Nagios Administrator using Ubuntu LTS 8.0.4 Server
June 19, 2008
Gone are the days of tedious console only configuration of Nagios. While it's an excellent system monitoring tool, it can be a little daunting to configure and setup. Not to mention editing 5 or 6 configuration files when adding one host.
In April 2008, Nagios Administrator was released, which promises to deliver an easy to use administration interface for configuring your Nagios installation with ease. The interface allows for adding contacts, contact groups, services, operating systems, and other settings. The one thing we noticed that was missing was service groups, but we're not sure that really matters.
Using this article in conjunction with our previous Monitoring Asterisk with SNMP article will yeild you great results and awesome statistics.
Since there is already a demo running of the Nagios Administrator, I don't think I need to show you screenshots, instead here is a link from their site.
NagiosAdministrator: http://demo.nagiosadmin.de
Nagios: http://demo.nagiosadmin.de/nagiosUsername: nagiosadmin
Password: nagiosadmin
We installed this on a VMWare Appliance, running Ubuntu Server Edition LTS 8.04, so you may have to change the instructions to suit your particular flavour of Linux. Or Microsoft Windows if you're brave enough to try this on that OS.
Anyhow, now on to the tutorial on getting Nagios 3.0 running with Nagios Administrator on your Ubuntu Server.
First, with the help of Michel Sigloch, we have this from a script of his that we've edited. This will install Nagios 3.0 from source on your ubuntu server, since the apt tree still holds an older version.
Installing Nagios
Start with the preliminaries:
# sudo apt-get install apache2 build-essential wget perl libgd2-xpm-dev openssl libssl-dev openssh-server openssh-client ntpdate snmp smbclient libldap-2.3-0 libldap2-dev mysql-server libmysqlclient15-dev qstat libnet-snmp-perl mrtg nut unzip
# sudo userdel -f nagios
# sudo useradd -c "Nagios Admin" nagios
# sudo groupadd nagcmd
# sudo usermod -G nagcmd nagios
# sudo usermod -G nagcmd www-data
# sudo usermod -a -G nagios www-data
Then We'll setup the Nagios directories and configure Nagios.
# sudo mkdir /usr/local/src
# cd /usr/local/src
# sudo wget http://nagios.sourceforge.net/download/cvs/nagios-cvs.tar.gz
# sudo tar xvzf nagios-cvs.tar.gz
# sudo rm nagios-cvs.tar.gz
# cd nagios-cvs
# sudo ./configure --with-command-group=nagcmd
Now lets install Nagios and update the default boot programs, while restarting apache and Nagios
# sudo make all
# sudo make install
# sudo make install-init
# sudo make install-commandmode
# sudo make install-config
# sudo ln -sf /usr/local/nagios/etc/ /etc/nagios
# sudo make install-webconf
Next we'll setup our htaccess file:
# sudo htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
# sudo chown www-data htpasswd.users
# sudo chmod 600 htpasswd.users
Download and configure nagios plugins. The plugins are what let you monitor things like your Asterisk PBX using SNMP or other methods.
# cd /usr/local/src
# sudo wget http://heanet.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz
# sudo tar xvzf nagios-plugins-1.4.11.tar.gz
# cd nagios-plugins-1.4.11
# sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# sudo make
# sudo make install
Now we are pretty much done with Nagios setup. We can move on to setting up Nagios Administrator. This part of the process can be a little confusing since their documentation is in german. I taught myself a bit of german last night reading this, but I decyphered it for us to use it. Keep reading for the Nagios Administrator Setup portion.
Configuring and installing Nagios Administrator
First, we'll have to install any pre-requisite packages for Nagios Administrator:
# sudo apt-get install php5-common traceroute php5-cli php5-gd
Now lets create our web directory
# sudo mkdir /var/www/nagiosadmin
Now we can download our Nagios Administrator files and drop them into the web directory on our server.
# cd /usr/src
# sudo wget http://www.nagiosadmin.de/nagiosadmin-0.9.1.tar.bz2
# sudo tar xjpf nagiosadmin-0.9.1.tar.bz2 -C /var/www/nagiosadmin/
Now we'll create the mysql database. Like this
# mysqladmin -u root -p create nagiosadmin
# mysql -u root -pmysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER,INDEX,DROP
ON nagiosadmin.*
TO 'nagiosadmin'@'localhost'
IDENTIFIED BY 'somepassword';
Now we have to configure Nagios Administrator to connect to our Database.
# cd /var/www/nagiosadmin
# nano config/propel.ini
and set
propel.database.url = mysql://nagiosadmin:yourpassword@localhost/nagiosadmin
Now we edit the databases file and enter our database settings
# sudo nano config/databases.yml
and set
database: nagiosadmin
username: nagiosadmin
password: yourpassword
Now we have to make sure our Nagios shell commands are set properly in Nagios Administrator.
# sudo nano apps/backend/modules/generator/config/module.yml
and make sure your paths are correct for these two lines
config_check_command: /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg 2>&1
reload_nagios_command: /usr/bin/sudo /usr/bin/killall -HUP nagios
Now we have to enter visudo to set up the permissions for our Nagios user, done like this:
# sudo visudo
then add
# for nagios
%nagcmd ALL= NOPASSWD: /usr/bin/killall -HUP nagios
Exit visudo by hitting the ESC key, and then typing ":wq" hitting enter.
Now, We have to do a few things that are pretty self explanitory with the Nagios Administrator control file.
# cd /var/www/nagiosadmin
# sudo ./symfony fix-perms
# sudo ./symfony propel-insert-sql
# sudo ./symfony propel-load-data backend
# sudo ./symfony check
Next we'll have to insert our Apache virtual host.
# sudo nano /etc/apache2/conf.d/nagios.conf
Make sure you enter this line, and change the path to match your install if you changed the above instructions
Alias /nagios/images/logos/nagiosimages /var/www/nagiosadmin/web/uploads/os_images
Also, in the default settings, make sure to change all of the references to the htpasswd file to the following
AuthUserFile /etc/nagios/htpasswd.users
Now, lets setup the new virtual host for our Nagios Administrator and Nagios site.
# sudo mv /etc/apache2/sites-enabled/000-default ~/000-default.backup
# sudo rm /etc/apache2/sites-enabled/000-default
Now we have to add our new default virtual host configuration like so
# sudo touch /etc/apache2/sites-enabled/nagios.conf
Enter the following, changing any paths as according to your configuration if you deviated from above.
<VirtualHost *:80>
ServerAdmin root@yourdomain.com
ServerName monitor.yourdomain.com
DocumentRoot "/var/www/nagiosadmin/web"
php_admin_flag magic_quotes_gpc 0
php_admin_value memory_limit "32M"<Directory "/var/www/nagiosadmin/web">
AllowOverride All
Order allow,deny
Allow from all
</Directory><Files index.php>
AuthType Basic
AuthName "NagiosAdmin"
AuthUserFile /etc/nagios/htpasswd.users
require user nagiosadmin
</Files>Alias /phpmyadmin /var/www/phpmyadmin
<Directory /var/www/phpmyadmin>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now we have to enable mod rewrite like this
# sudo mod_rewrite aktivieren
And next lets restart Apache
# sudo /etc/init.d/apache2 restart
Configuring Nagios 3.0 to work with Nagios Administrator
Now we have to make some quick edits to the nagios configuration and we'll be up and running in no time.
First lets edit the Nagios configuration file
# nano /etc/nagios/nagios.cfg
Now make sure yours looks like the following, commenting out the ones that are on by default and adding the new Nagios Administrator directory at the bottom.
#cfg_file=/usr/local/nagios/etc/objects/commands.cfg
#cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
#cfg_file=/usr/local/nagios/etc/objects/templates.cfg# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg#cfg_dir=/usr/local/nagios/etc/servers
#cfg_dir=/usr/local/nagios/etc/printers
#cfg_dir=/usr/local/nagios/etc/switches
#cfg_dir=/usr/local/nagios/etc/routers
cfg_dir=/var/www/nagiosadmin/data/nagios
Now, before starting nagios for the first time, lets go into the configuration interface and set up some default values.
Open a web browser and hit this url:
You should see the login box for your Nagios Administrator site, which you can login with "nagiosadmin" and the password you entered earlier.
Once you login to the site, you will have to configure the following things:
contacts -> create -> make one or two contacts
contact groups -> create -> create a contact group, and assign some contacts to it
host groups -> create -> create a host group
host -> create -> create some hosts
Now, go to the "Generator" Menu, and click on "Save".
Now, go back to your command prompt, and start Nagios. It should start with no errors.
# sudo /etc/init.d/nagios start
Now, go back to the web interface, you should be able to save and generate your configuration file with no errors.
Finally, add Nagios to your default runlevel
# sudo update-rc.d nagios defaults
Congratulations, we're finished!
We are now finished with the setup. It's up to you to setup proper security measures for the Nagios Administrator and Nagios site.
You can visit the Nagios Administrator panel here:
and you can visit Nagios here
Remember, you can also take a look at our Monitoring Asterisk with SNMP Howto for information on getting even more statistics from your Asterisk PBX than you ever thought possible. We hope you like this article, and welcome comments.
Ubuntu Asterisk 1.4 Init Script with FreePBX and FOP
March 3, 2008
Note, If you're looking for current information please see Free PBX Guide for the latest tutorial with updated information from what is located below.
Free PBX Guide
We had to edit the stock Asterisk Init script to use with Asterisk on Ubuntu. In order for it to actually stop the Flash Operator Panel when you run the stop command a few additions had to be made.
Find it below for download.
asterisk.init
Installation is like any other script,
# mv asterisk.init /etc/init.d/asterisk
# chmod +x /etc/init.d/asterisk
# /etc/init.d/asterisk stop | stop | restart



