Category Archives: Uncategorized

Making and installing Python on a 1and1 shared host

In my last post I built and installed Subversion. In this post, I’ll build and install the current 2.x version of Python, which will be needed for Trac, later.

Similar to how we built and installed Subversion, where are the commands to install Python. As before, you will need to get the HTTP address for the current version of Python (from http://www.python.org/download/) and modify the procedure for your home directory path, which you can get by running the pwd command.

For line six, in the following list of commands, get the prefix path by entering cd ~/opt and then running the pwd command.

cd ~/dev
wget http://www.python.org/ftp/python/2.6.4/Python-2.6.4.tgz
tar -xzvf Python-2.6.4.tgz
cd Python-2.6.4
mkdir ~/opt
./configure --prefix=$HOME/opt
make
make install

Modify your ~/.bash_profile file so you can run Subverison commands without typing the full path. If you’ve already modified your PATH to look in ~/opt/bin, then you should skip this.

echo 'export PATH=$HOME/opt/bin:$PATH' >> ~/.bash_profile

Note that I stuck the new Python at the beginning of the path so it overrides the random old Python that 1and1 has installed.

Use the source command to reset your environment from your newly modified ~/.bash_profile file.

source ~/.bash_profile

Test the result

python

Look at the version printed and exit with control-d.

End of procedure.

Komodo IDE macro to process current file with PHP Beautifier

I use Komodo IDE for dynamic languages. I like it because it works extremely well and you get a license to use it on whatever machine you happen to be sitting at. Also it works well in Ubuntu and Mac OS/X, both of which I use constantly.

Here’s a macro I use in Komodo to make the file I am currently editing instantly pretty:

var ke = komodo.editor
if (komodo.view.scintilla) { komodo.view.scintilla.focus(); }
var currentPos = komodo.editor.currentPos;
 
try {
    var tidycmd = "/usr/bin/php_beautifier -t1 -l 'Pear() ArrayNested IndentStyles() NewLines'"
    komodo.doCommand('cmd_save');
    ke.beginUndoAction();
    komodo.doCommand('cmd_selectAll');
    Run_RunEncodedCommand(window, tidycmd + " {'insertOutput': True, 'operateOnSelection': True}");
    ke.gotoPos(currentPos);
    komodo.doCommand('cmd_cleanLineEndings');
} catch (e) {
    alert(e);
} finally {
    ke.endUndoAction();
}

Installing Trac and Subversion on Ubuntu Ibex

These are basically my notes from installing Trac and Subversion on an Ubuntu Intrepid Ibex server.

Install Software Packages

sudo aptitude install libapache2-mod-python libapache2-svn python-setuptools subversion python-subversion
sudo easy_install Trac

Create the Trac Environments Directory

sudo mkdir /var/lib/trac
sudo chown www-data:www-data /var/lib/trac

Setup Apache2

Using the default Ubuntu Apache virtual server setup, create a virtual server instance for
Trac. This single instance will be used for all Trac projects on the server.

sudo vi /etc/apache2/sites-available/trac.websitename.com

Your file will look a lot like the following. Use your website name instead of websitename.com and use a valid e-mail addressinstead of webmaster@websitename.com.


	ServerAdmin it@sitename.com
	ServerName trac.sitename.com
	DocumentRoot /hkm/var/www/trac.sitename.com/public
	LogLevel warn
	ErrorLog /hkm/var/www/trac.sitename.com/logs/error.log
	CustomLog /hkm/var/www/trac.sitename.com/logs/combined.log combined
	# DirectoryIndex index.html
 
	
		SetHandler mod_python
		PythonInterpreter main_interpreter
		PythonHandler trac.web.modpython_frontend
		PythonOption TracEnvParentDir /var/lib/trac
		PythonOption TracUriRoot /projects
		PythonOption PYTHON_EGG_CACHE /tmp
	
 
	# use the following for one authorization for all projects 
	# (names containing "-" are not detected):
	
		AuthType Basic
		AuthName "trac"
		AuthUserFile /path/htpasswd_filename_here
		Require valid-user
	

Now, use the Debian/Ubuntu utility a2ensite to create a link in apache2/sites-enabled to the file you just created in apache2/sites-available. Then, reload apache2 to enable the new subdomain.

sudo a2ensite trac
sudo  /etc/init.d/apache2 reload

You will also need to create a DNS A record to point to the server for this subdomain, but this is outside the scope of this blog entry.

Create Trac and Subversion Environments

Here we will make directories and create the Subversion repositories.

sudo mkdir /var/lib/svn
sudo mkdir /usr/share/trac
sudo svnadmin create /var/lib/svn/project1
sudo svnadmin create /var/lib/svn/project2

Set some permissions:

sudo chown -R www-data /var/lib/svn
sudo chown -R www-data /usr/share/trac
sudo  /etc/init.d/apache2 reload

Set up Trac

sudo mkdir /var/lib/trac

Initialize Trac for one of your projects.

sudo trac-admin /var/lib/trac/project1 initenv

The utility will ask for:

Project Name [My Project]>: project1
Database connection string [sqlite:db/trac.db]>:
Repository type [svn]>:
Path to repository [/path/to/repos]>: /var/lib/svn/project1

Repeat the above for the following, substituting the project code for each:

sudo trac-admin /var/lib/trac/project2 initenv
sudo chown -R www-data /var/lib/trac

Get Subversion Running

Modify /etc/apache2/mods-available/dav_svn.conf

sudo vi /etc/apache2/mods-available/dav_svn.conf
<Location /svn>
  DAV svn
 
  SVNParentPath /var/lib/svn
  SVNListParentPath On
 
  AuthType Basic
  AuthName "Subversion Repository"
  AuthUserFile /path/htpasswd_filename_here
 
  # To enable authorization via mod_authz_svn
  #AuthzSVNAccessFile /etc/apache2/dav_svn.authz
 
  <LimitExcept GET PROPFIND OPTIONS REPORT>
    Require valid-user
  </LimitExcept> 
 
</Location>

Install More aptitude packages for Trac plugins

Install some packages that will be needed.

sudo aptitude install build-essential graphviz
sudo aptitude install enscript
sudo aptitude install htmldoc

Using easy_install to Install more Trac Plugins

Because these are installed, you will be able to turn these on easily as Trac administrator.

sudo easy_install http://svn.edgewall.org/repos/genshi/trunk/
sudo easy_install http://trac-hacks.org/svn/accountmanagerplugin/trunk
sudo easy_install http://trac-hacks.org/svn/customfieldadminplugin/0.11
sudo easy_install http://trac-hacks.org/svn/eclipsetracplugin/tracrpcext/0.10
sudo easy_install http://trac-hacks.org/svn/iniadminplugin/0.11
sudo easy_install http://trac-hacks.org/svn/masterticketsplugin/0.11
sudo easy_install http://trac-hacks.org/svn/pagetopdfplugin/0.10/
sudo easy_install http://trac-hacks.org/svn/progressmetermacro/0.11
sudo easy_install http://trac-hacks.org/svn/ticketdeleteplugin/0.11
sudo easy_install http://trac-hacks.org/svn/tracwysiwygplugin/0.11
sudo easy_install http://wikinotification.ufsoft.org/svn/trunk

Ubuntu: Open Terminal from Nautilus

This will allow you to open a Terminal instance in context in Nautilus.

sudo aptitude install nautilus-open-terminal

You will need to restart Gnome for it to take effect. Note that all you user programs will be terminated…so save data first. Then either use , or:

sudo /etc/init.d/gdm restart

And Bob’s your uncle. Now you can right-click and open a Terminal.

Basic Password Protection for Apache Webpage

This is the bare bones basics to protect a web page or series of pages on an Apache web server.

.htaccess file

AuthName "SectionName"
AuthType Basic
AuthUserFile /full/path/to/.htpasswd
Require valid-user

Replace SectionName with the name of what you are protecting (in and below the directory that you are putting the .htaccess file in. Example: My Web Site

Replace /full/path/to/.htpassword with the actual full path to the .htpassword file you created.

.htpassword file

username:encryptedPassword

Replace encryptedPassword with your choice of password encrypted with the htpasswd program that came with Apache. Use man htpassword for instructions.

You can then access the page with the normal address…in which case it will ask for the username and password, or you can use this:

http://username:password@website.com/page

Padding a Numeric in Bash

I needed to pad a day of the month value to 2 places in a bash script.

This is made easy by the GNU program printf, which is part of standard distributions of Linux. In the following script snippet, the current day of the month is passed from the command invocation (or, if not specified, defaulted to the current day). It is then zero-padded with printf.

TODAY=$(date +%d)
if [[ "$1" != "" ]]; then
  TODAY=$1
fi
TODAY=$(printf "%02d" $TODAY) # Zero pad day.

Nautilus as Root in Ubuntu

Firstly, you can just run Nautilus as root from the command line with:

gksudo nautilus

The following procedure will add a root file browser to the Applications | System Tools menu.

I got this from http://ubuntuforums.org/archive/index.php/t-256998.html.

Create a text file with:

gksudo gedit /usr/share/applications/Nautilus-root.desktop

Add these lines to the file:

[Desktop Entry]
Name=File Browser (Root)
Comment=Browse the filesystem with the file manager
Exec=gksudo "nautilus --browser %U"
Icon=file-manager
Terminal=false
Type=Application
Categories=Application;System;

Open Nautilus with: Applications -> System Tools -> File Browser (Root)

An Alternative

This is from a comment by Cerebrux to this post:

1) Open Synaptic and install the “nautilus-gksu”

2) Logout- Login

3) And now do right-click on a folder and “open as administrator”.

P.S. If you want the “open terminal here” in your right-click, then just install “nautilus-open-terminal”

Firstly, you can just run Nautilus as root from the command line with:

gksudo nautilus

The following procedure will add a root file browser to the Applications | System Tools menu.

I got this from http://ubuntuforums.org/archive/index.php/t-256998.html.

Create a text file with:

gksudo gedit /usr/share/applications/Nautilus-root.desktop

Add these lines to the file:

[Desktop Entry]
Name=File Browser (Root)
Comment=Browse the filesystem with the file manager
Exec=gksudo "nautilus --browser %U"
Icon=file-manager
Terminal=false
Type=Application
Categories=Application;System;

Open Nautilus with: Applications -> System Tools -> File Browser (Root)

An Alternative

This is from a comment by Cerebrux to this post:

1) Open Synaptic and install the “nautilus-gksu”

2) Logout- Login

3) And now do right-click on a folder and “open as administrator”.

P.S. If you want the “open terminal here” in your right-click, then just install “nautilus-open-terminal”

SQLyog on Ubuntu

SQLyog is a popular MySQL GUI client that can be very convenient for certain operations like quickly dumping a database, schema changes. For operations that are awkward via the command line, it is useful.

I’ve installed SQLyog on my Ubuntu (Hardy Heron) laptop. It was very easy using Wine.

To install SQLyog with Wine

Install Wine on your Ubuntu system using the Synaptic Package Manager. As of this writing, version 1.0.0.1 was current. the exact version of Wine is probably not important.

Download SQLyog from here. I use the community edition. It is not important where you download the installation (Windows EXE) to. Just save the program file someplace convenient that you can easily navigate to via bash in the Terminal.

Open a Terminal window and change to the directory where you stored the EXE installation file. Type:


wine SQLyog714.exe

This is the exact filename that I downloaded. You will probably need to change it to the filename you downloaded.

Follow through the installation process using the standard SQLyog installer. Accept defaults. The program will be installed under a directory in your home directory called .wine.

At the end of the installation, the dialog will allow you to run the program. Go ahead and run it for the thrill of seeing a Windows program run on Linux. Wine is great!

Create a shortcut to run SQLyog in Terminal

I like to run SQLyog from the command line. I could change to the program’s directory and start the program with wine SQLyog.exe. Like this:

cd ~/.wine/drive_c/Program\ Files/SQLyog\ Community wine SQLyog.exe

For convenience, I created a script to start SQLyog just by typing sqlyog. I created a text file called sqlyog with the above two lines and made it executable with chmod +x sqlyog. I have a directory in my $PATH for scripts like this, so I can fire SQLyog from anywhere.

Adding SQLyog to the Ubuntu Applications menu

On my installation of SQLyog, an entry was not made in the Applications menu to launch SQLyog. I added it to Applications | Wine by right-clicking on Applications and selecting Edit Menus. I added a new menu item with the New Menu button. The command to run SQLyog is:


env WINEPREFIX="/home/andrew/.wine" wine "C:\Program Files\SQLyog Community\SQLyog.exe"

Virtual Web Server Sandboxes on Ubuntu

Problem: Multiple virtual web sites are needed on an Ubuntu machine.

Solution: Set-up virtual servers in Apache and modify the /etc/hosts file so URLs of your choosing will resolve to the virtual sites that you create.

This procedure was tested using Ubuntu Hardy Heron.

For Apache’s documentation about name based virtual hosting, see:

http://httpd.apache.org/docs/1.3/vhosts/name-based.html

Step One: Modify the hosts File

The /etc/hosts text file is owned by root and allows a simple means to resolve a URL that your type into your web browser to an IP number. In this case we want our example URL of my.example.com to resolve to the IP address of the local machine, just like localhost. This is normally 127.0.0.1. Edit the /etc/hosts file with:


sudo vi /etc/hosts

Find the line that reads:


127.0.0.1 localhost

On the same line, after localhost, add a space and the name of your virtual site:


127.0.0.1 localhost my.example.com

That’s it for the hosts file. You do not need to restart anything.

Step Two: Set-up a Virtual Website on Apache

Apache has the handy ability to discern the URL from a browser’s address line and serve up the site that has been configured for it. This allows a server with a single IP address (like our 127.0.0.1) to host several sites at once.

For each virtual web site on the server, create a text file in the /etc/apache2/sites-available directory. Use the following template to create the file (called my.example.com in this example):




ServerAdmin username@localhost
ServerName my.example.com
DocumentRoot /home/username/public_html/my.example.com
CustomLog /var/log/apache2/my.example.com.log combined



You will need to create this file as root, so:


sudo vi /etc/apache2/sites-available/my.example.com

Now, you can use a Debian (Ubunto is a Debian variant) utility to easily create a link to this configuration file:


sudo a2ensite my.example.com

The above line simply creates a link to the my.example.com file in the /etc/apache2/sites-available directory. This allows you to enable and disable sites easily. The Debian disable counterpart to a2ensite is a2dissite (which just deletes the link).

Lastly, reload Apache:


sudo /etc/init.d/apache2 reload

After ensuring that you have something to sever in the site’s document directory, enter the URL you used in your browser’s address field and try it out!