The Glenbot

Code and other thoughts about geeky stuff

Glen Zangirolami – Python developer, musician, sailor, creator.
           

Multiple Virtual Hosts with Apache in Windows on your PC

Posted on February 11th, 2010 –  0 comments  –  apache  tutorial  windows 

When you work in an environment that requires you to switch back and forth from Drupal, to Wordpress, to Django, it can become difficult to manage the file and URL structure in Apache. A URL like localhost/wordpress/thesite/blog-post-here just sucks. Running applications from the root of the URL helps to ease the transfer from development to production.

Let's see if we can sort this out.

Setting up the folder structure

Assuming Apache is installed and running, let's start with organizing the document root. The default install of Apache creates the document root under program files. 

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs

If needed, substitute C:\Program Files\Apache Software Foundation\Apache2.2\htdocs with your document root setting. Sticking with the default root, create subfolders for each application. For this tutorial we will create the folders Drupal, Wordpress, and Django.

The structure should look like this:

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\drupal
C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\wordpress
C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\django

For later testing, create a file labeled  index.html, insert the text It Works!and place it within each subfolder.

The next step would be to setup virtual hosts in the Apache configuration file. Unfamiliar with virtual hosts? Apache documentation provides tutorials.

The default Apache configuration file is located here:

C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf

Virtual Hosts

The first part to setting up virtual hosts is to provide Apache with the NameVirtualHost directive. This is required if you want to use name based virtual hosts. Place this directive at the very bottom of the configuration file (away from other directives to avoid issues).

NameVirtualHost *

Directly after the NameVirtualHost directive we can start setting up virtual hosts. We need three for Drupal, Wordpress and Django. 

<VirtualHost *>
    ServerName wordpress

    # set the document root
    DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/wordpress"

    # set the directory settings
    <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/wordpress">
        Options All Includes Indexes
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

# virtual host for drupal site
<VirtualHost *>
    ServerName drupal

    # set the document root
    DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/drupal"

    # set the directory settings
    <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/drupal">
        Options All Includes Indexes
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

# virtual host for django site
<VirtualHost *>
    ServerName django
    # set the document root
    DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/django"

    # set the directory settings
    <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/django">
        Options All Includes Indexes
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Virtual hosts will allow us to use Drupal, Wordpress, and Django sites from http://drupal/, http://wordpress/, http://django/ respectively. Note that all the directories within the configuration file are expressed with a frontslash and not a backslash. Running more than one site under each URL is just a matter of creating more subfolders. 

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\wordpress\site1
C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\wordpress\site2
C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\wordpress\site3

The HOSTS file

The last step is to map the value of the ServerName directive from the virtual hosts example above to your computers loopback ip address in the windows hosts file. 127.0.0.1 is generally the loopback ip.

Hosts can be found here:

C:\Windows\System32\drivers\etc\hosts

The content of the hosts file should look like:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost

Add the following lines to the bottom of the file.

127.0.0.1    wordpress
127.0.0.1    drupal
127.0.0.1    django

Save the file, reload Apache, and test the URLs in your browser. If everything works right you should see It works! rendered in the browser window. If there is an issue check your paths in the Apache configuration file. Make sure they all use forward slashes.

With each application under its own virtual host you can also you customize they way they run and keep the settings isolated within each one. For instance, Django requires mod_python and Wordpress requires the htaccess file to be enabled but those settings do not need to cross pollinate. The possibilities are endless. 

Happy Coding!

Loading mentions Retweet

Comments [0]

My Google Reader Development Bundle

Posted on February 4th, 2010 –  1 comment  –  rss 

Education, knowledge sharing, and creation are all parts of my daily diet. I enjoy reading about what other developers say and so should you! Exercising the knowledge sharing, here is my development RSS bundle. 

http://www.google.com/reader/bundle/user/04345256806204706511/bundle/Development

Some of my favorites

High Scalability - http://highscalability.com/

Reliably Broken - http://reliablybroken.com/b/

B-list - http://www.b-list.org/

Signal vs. Noise - http://37signals.com/svn/posts

Armin Ronacher - http://lucumr.pocoo.org/

 

Please feel free to leave comments about your favorite development feeds.

Loading mentions Retweet

Comments [1]

Django Template Syntax Highlighting For Dreamweaver

Posted on January 14th, 2010 –  0 comments  –  django  python 

My development environment consists of Eclipse, Dreamweaver, and Putty

Eclipse can do syntax highlighting for Python with awesomeness but lacks in others.
I use Dreamweaver for syntax highlighting of HTML, CSS, and Javascript. The auto completion is great too.

But what about syntax highlighting of the Django template language?
Over time I created a simple coloring scheme with earthy tones to highlight just that.

To install the syntax highlighting you will need the following snippets of XML:

Add the scheme to CodeColoring.xml and the colors to Colors.xml then RESTART Dreamweaver

Windows XP
C:\Documents and Settings\<user>\Application Data\Adobe\Dreamweaver xx\Configuration\CodeColoring

Windows Vista/7
C:\Users\<user>\AppData\Local\Adobe\Dreamweaver xx\Configuration\CodeColoring

If you don't like the colors you can always change them by going to "Edit | Preferences | Code Coloring" in Dreamweaver, selecting "HTML", and clicking "Edit Coloring Scheme"


You will then find yourself with a list of styles for each scheme. Locate the Django scheme and you customize your colors
from there. 


Happy Coding! 
Loading mentions Retweet

Comments [0]

Django Model Field to MySQL Datatype

Posted on December 16th, 2009 –  0 comments  –  django  mysql  python 

Creating models and syncing them with the database in Django is a pretty easy process. Remembering the Django model fields and what MySQL data types they use in the database is not. 

I have created a spreadsheet that relates a Django models field to its MySQL datatype.

Django Model Field to MySQL Datatype Spreadsheet

Loading mentions Retweet

Comments [0]

Tweetstone Project

Posted on November 19th, 2009 –  0 comments

This morning I released Tweetstone. It's a way to calculate when you will reach any number of tweets. Let's say your goal is 1000 tweets. Just enter in your name and the number of tweets and it will give you an estimated date of completion based on your recent frequency of tweeting. 

The twitter frequency is derived from the Twequency API and the rest is calculated from the Twitter API  with some simple math. The design was done by my good friend Illustrationdan

It was a fun little side project and brought back some cowboy programming memories. :)

Try it out!  

Loading mentions Retweet

Comments [0]

Useful Linux Commands and Files

Posted on November 9th, 2009 –  0 comments  –  linux  ubuntu 

On an almost daily bases I work in Linux (Ubuntu).

I research and find commands that are useful to my daily work routine and save them in evernote.

Here is a compiled list of commands I commonly use. Share!

Grab Useful Linux commands and files with Google Docs

Download Useful Linux commands and files in Word format

Download Useful Linux commands and files in Evernote format

Users & Groups:

adduser <username> (add user to the system. Will create /home/<username> folder.)

adduser --group <groupname> <username> (add user to a group)

id <username> (display users id, groupid, and group information)

userdel -r <username> (remove user from system and home directory)

/etc/groups (file that holds all the groups in the system)

System:

cat /proc/meminfo (check the memory usage of the system)

vmstat (summary of the memory usage)

free -m (another summary of the memory usage)

ps -u <username> -o pid,rss,command (check memory usage under a specific user)

saidar (realtime monitor of system usage. Installed from apt-get)

pgrep (search for running processes)

kill <pid> (kill a running process by process id)

pidof <processname> (get the process id of a process by name)

Networking:

/etc/init.d/networking restart - (restart the network)

iftab (file that stores manual information of the NIC cards like mac address. Exists in older systems)

ifup ethx (bring a NIC up)

ifdown ethx - (bring a NIC down)

ifconfig (similar to ipconfig in windows. It display the networks properties)

/etc/network/interfaces (file that stores the settings for all NIC cards)

netstat -plntu (shows the open ports and what is listening on them)

iptables -L (displays the current configuration of the tables)

FTP/SSH:

/etc/ftpusers (list of users allowed and not allowed to connect to the machine via ftp)

/etc/ssh/sshd_config (config file for open ssh)

/etc/init.d/sshd restart (restart the open ssh services)

File System:

sudo (run a command as the super user)

pwd (shows the present working directory)

cp (copy a file from one location to another)

cp -R dir newdir (copy a fill directory from one place to another)

mv (move a file from one location to another)

rm (remove a file or folder)

rm -rf (remove files and folders recursively)

rm link (remove a symbollic link)

cat (display the contents of a file)

ln -s (create a symbolic link)

mkdir (make a folder)

df -h (get hard drive and partition usage)

find . -type d -print0 | xargs -0 chmod 755 (chmod all folders in a given folder)

find . -type f -print0 | xargs -0 chmod 444 (chmod all files in a given folder)

find . -mtime -1 -print > last_modified_24hours.txt (find files modified within last 24 hours)

Web & Packages:

wget (download a file from the internet. Usage: wget <addresstofile>)

apt-get update (updates the package in the Advanced packaging tool.)

apt-get install <application> (downloads and installs a linux package. i.e mysql squid etc.)

/etc/apt/sources.list (file that lists the advanced packaging tools (apt-get) sites)

Text Editors:

nano (a great easy to use text editor)

vi (a basic text editor for linux)

Apache:

/etc/init.d/apache2 (start, stop, or restart the apache server)

a2ensite (enable a site in sites-available)

a2dissite (disable a site in sites-available)

/usr/sbin/apache2ctl -k graceful (gracefully restart apache)

Subversion:

sudo svn export -r HEAD file:///var/svn/repository/tron/trunk/ folderorfilename (export files from a specific svn folder)

svn co urltorepository (check out files from a remote or local repository)

Mysql:

mysql -u root -p (connect to mysql with use root)

Loading mentions Retweet

Comments [0]

Rise of the glenbot

Posted on November 8th, 2009 –  0 comments  –  introduction 

I have decided to create a professional blog. Phew. *wipes sweat* 

That last sentence took a lot of designing, chopping, coding, and platform research. I chose the wonderful posterous as my platform. No solid reason other than the connections to social media and easy posting by email.

My plans for content types in the informative/rant/tutorial forms are:

Check out the awesome people I have linked in the Link Love section!

Loading mentions Retweet

Comments [0]