Click to search Andy Jarrett.co.uk RSS feed

Loading Twitter

htaccess for moving domain names

Apache uses .htaccess files as a way to make configuration changes on a per-directory (and subdirectories) basis. They are a powerful tool when it comes to moving folders of changed files or in my case domain name rewriting.

Currently I am using a short domain name (prsos.co.uk) as a redirect to a specific page on the full domain name petrescuesos.co.uk. In the past I've even used ColdFusion to do by putting something along the lines in my Application.cfm.

view plain print about
1<cfif findNoCase('prsos', cgi.server_name)>
2<cfheader statustext="Moved permanently" statuscode="301" />
3<cfheader value="http://www.petrescuesos.co.uk" name="Location">
4</cfif>

This still gives the browser/spider the correct http header but why waste cpu styles on even doing this when the web-server can handle it natively. Below is the Apache .htaccess I've just put in place.

view plain print about
1#Turn rewrite on
2RewriteEngine on
3#Look at the HTTP_HOST and regex search for old domain name
4rewritecond %{http_host} ^(.*)prsos.co.uk [nc]
5# The rule. Change the http_host to the new domain location. NC means NoCase
6rewriterule ^(.*)$ http://www.petrescuesos.co.uk/index.cfm?action=pets.found [r=301,nc]

Comments Comments (0) | Print Print | Send Send | 736 Views

My blog has moved

Please update your bookmarks and feeds for my site.

I now have a Mango Blog at:

http://www.andyjarrett.com/blog

Feed URL: http://feeds.feedburner.com/andyjarrett

Comments Comments (0) | Print Print | Send Send | 1195 Views

Speed up Apche2 with mod_deflate

Before there was mod_gzip but now in Apache 2 there is mod_deflate. Its pretty much the same, and included with the default source package now. The syntax is pretty much the same. You can set it across the board or on a MIME type basis.

Check out the Apache docs for a proper understanding. Currently I am still testing my setup and on my Ubuntu installation I edited the following configuration to add some MIME Type rules

view plain print about
1$ sudo nano etc/apache2/mods-enabled/deflate.conf

The following rules I am using are

view plain print about
1<Location />
2AddOutputFilterByType DEFLATE text/plain
3AddOutputFilterByType DEFLATE text/xml
4AddOutputFilterByType DEFLATE application/xhtml+xml
5AddOutputFilterByType DEFLATE text/css
6AddOutputFilterByType DEFLATE application/xml
7AddOutputFilterByType DEFLATE application/rss+xml
8AddOutputFilterByType DEFLATE application/atom_xml
9AddOutputFilterByType DEFLATE application/x-javascript
10AddOutputFilterByType DEFLATE text/html
11<Location>

Do read the docs though, as not all browsers can handle this but there are ways to get around that.

Comments Comments (0) | Print Print | Send Send | 1173 Views

Setting up Apache and Subversion on JeOS (Ubuntu)

I'll be honest, I don't have much linux experience. I've always liked the idea of Linux and a command line driven OS but as soon as I see the GUI I tend point and click, which means I don't learn anything new. Then comes along JeOS (Just enough OS, pronounced as "juice") from Ubuntu which doesn't give you a GUI, it just gives you the bare minimum to run a server. It's designed for VM's and perfect for running a Subversion server on your local machine in the background. The specs are:

  • Less than 100Mb ISO image
  • Less than 300Mb installed footprint
  • Specialised -virtual Kernel 2.6.24
  • Optimised for VMWare ESX, VMWare Server and KVM
  • Intel or AMD x86 architecture
  • Minimum memory 128M
  • No graphical environment preloaded as it is aimed at server virtual appliance

So with JeOS and VMWare Fusion armed I was ready to setup a light-weight Subversion and Apache server. Below documents what I did to get a single SVN repository up and running. Im not installing Trac or SSL with this just so you know. I might try and cover them later, along with multiple repositories.

Setting up JeOS with VMWare fusion is no different than setting up any other VM so I won't go over that here. I'll assume that you can do that, and have done that and now at the command prompt.

Obviously because there is no GUI supplied all commands have to be run from the Command Line/Terminal. This also means editing txt files from the terminal too. If you've never used VIMM you might want to have the following URL handy www.gnulamp.com/vi.html

First things first, lets make sure your install is up-to-date.

view plain print about
1$ sudo apt-get update

We're going to get curl to help with HTML checking later

view plain print about
1$ sudo apt-get install curl

We need vim to edit some files (If you need help with Vi check out http://www.gnulamp.com/vi.html)

view plain print about
1$ sudo apt-get install vim

Install Apache

view plain print about
1$ sudo apt-get install apache2
This command will not only install Apache, but will start it up as well. You can check that its running by using CURL and the following command
view plain print about
1$ curl http://localhost
You should see something like:
view plain print about
1<html><body><h1>It works!</h1></body></html>

To view this from this from outside of the VM i.e. your host machine, you need to get the IP address which you can do with the following command.

view plain print about
1$ ifconfig eth0
In the response look for inet addr. You should then be able to hit the IP address from your host machine and see "It works!" on your screen.

Install SVN

view plain print about
1$ sudo apt-get install subversion

Install LibApach2

view plain print about
1$ sudo apt-get install libapache2-svn

Note: For neatness we could of written the above to lines as

view plain print about
1$ sudo apt-get install subversion libapache2-svn

Create SVN folders

view plain print about
1$ sudo mkdir /var/svn
2$ sudo mkdir /var/svn/MyFirstRepos

Set up SVN folders

view plain print about
1$ sudo svnadmin create /var/svn/MyFirstRepos
2$ sudo chown -R www-data /var/svn/MyFirstRepos

Create a password file Replace {your name here} with your name i.e. andy

view plain print about
1sudo htpasswd -cm /etc/apache2/dav_svn.passwd {your name here}
You'll be asked to enter a password. Do so, hit return until complete.

No we configure Apache by editing the following file with Vim that we installed at the beginning

view plain print about
1sudo vim /etc/apache2/mods-enabled/dav_svn.conf
The file needs to look like this. To achieve this all you really need to do is remove the comments "#"
view plain print about
1<Location /svn>
2 DAV svn
3 SVNPath /var/svn/MyFirstRepos
4
5 AuthType Basic
6 AuthName "Subversion Repository"
7 AuthUserFile /etc/apache2/dav_svn.passwd
8 Require valid-user
9</Location>

Restart Apache

view plain print about
1$ sudo /etc/init.d/apache2 restart

Thats it, you're done. You can get to your repository via your hosts browser by going to http://{your VM IP}/svn. You should get a username/password dialog which to enter the details you created in.

The final size of my VM is 1.02GB, but with no graphical UI it is only using 25MB of real memory, so leaving it running on a low end machine, which is what I intend will be easy.

Comments Comments (4) | Print Print | Send Send | 4744 Views

Building and installing Apache 2 on a Mac

Ok Below is a rough guide to get anyone up and going when it comes to building and installing Apache 2 from source. We're gonna do this all from the Terminal found in /Applications/Utilities/Termain.app.

Please note that '$' means new line, don't type this character If you want to know about any of the commands we make from the terminal you can always type "man + command" e.g.

view plain print about
1$ man curl
If you run the above code it should tell you that
curl is a tool to transfer data from or to a server, using one of the supported protocols (HTTP, HTTPS, FTP, FTPS, GOPHER, DICT, TELNET, LDAP or FILE). The command is designed to work without user interaction.

This will also detail the options I use.

1: Download Apache 2 from source. Now you can do this from the browser by simply going to http://httpd.apache.org/ but where is the fun in that :o) From the Termainal type:

view plain print about
1$ curl -O http://www.eu.apache.org/dist/httpd-2.2.0.59.tar.gz
2$ gnutar -xzf httpd-2.0.59.tar.gz

2: Building
Our installation of Apache2 is going to be stored on the root i.e. /apache2

view plain print about
1$ cd httpd-2.2.2
2$ sudo ./configure --prefix=/apache2

3: Installing

view plain print about
1$ sudo make
2$ sudo make install

4: Starting and Stopping Apache 2 Apache 2 should now be installed.

To start Apache 2:

view plain print about
1$ sudo /apache2/bin/apachectl start

To restart Apache 2:

view plain print about
1$ sudo /apache2/bin/apachectl restart

To stop Apache 2:

view plain print about
1$ sudo /apache2/bin/apachectl stop

That's all you need to get it installed. Once you are at this point the next move is to edit the httpd.conf file, which you can find at /apache2/conf/httpd.conf

Comments Comments (7) | Print Print | Send Send | 4764 Views

Setting up and using windows HOST file

Host files used in windows to describe many-to-one mapping of device names to IP addresses. Using this file is helpful when developing locally as it allows you to assign the URL of the site to a local IP.

First, find you host file:
Windows NT/2000/XP Pro c:\winnt\system32\drivers\etc\hosts
Windows XP Home c:\windows\system32\drivers\etc\hosts

The HOST file doesn't have an extention and can be opened with notepad.

** Before we go any further make sure you back this up - just in case ***

You should see something like:

view plain print about
1......
2# Additionally, comments (such as these) may be inserted on individual
3# lines or following the machine name denoted by a '#' symbol.
4# For example:
5# 102.54.94.97 rhino.acme.com # source server
6# 38.25.63.10 x.acme.com # x client host
7
8127.0.0.1    localhost

As with SQL '#' mean comments, so the only active line there is

view plain print about
1127.0.0.1    localhost

What does that mean. Well everytime you access localhost (like in a browser, or PING'd from a command line) you are acutally accessing the IP address 127.0.0.1. So lets say i'm developing a new blog. In Apache (or any web server) i'd set up the IP address 127.0.0.2 to look at my document root. Then in the HOST file i'd have

view plain print about
1127.0.0.2    www2.andyjarrett.co.uk

Alternatively I could just point the host to 127.0.0.1 instead of setting up a new IP. What you cannot do is map to a IP and port i.e. 127.0.0.1:8080

By the way, if you're wondering why i've changed the URL to have www2 as the prefix? It's that the HOST file is used first when going to a domain. For example try out the following

view plain print about
1127.0.0.1    www.google.co.uk

then goto www.google.co.uk.

N.B. If you use a proxy then you will need to bypass the proxy server for local addresses

Comments Comments (2) | Print Print | Send Send | 12010 Views

Apache, CFMX 6.1, CFMX 7

Im currently running two seperate installs of CFMX, both 6.1 and 7 with apache as my local server. To do this ensure in your httpd.conf file you have the following

#######################

### FOR CFMX 6.1

#######################

#
# Bring in additional module-specific configurations
#
<IfModule mod_ssl.c>
Include conf/ssl.conf
</IfModule>
# JRun Settings
LoadModule jrun_module "C:/CFusionMX/runtime/lib/wsconfig/1/mod_jrun20.so"
<IfModule mod_jrun20.c>
JRunConfig Verbose false
JRunConfig Apialloc false
JRunConfig Ssl false
JRunConfig Ignoresuffixmap false
JRunConfig Serverstore "C:/CFusionMX/runtime/lib/wsconfig/1/jrunserver.store"
JRunConfig Bootstrap 127.0.0.1:51010
#JRunConfig Errorurl <optionally redirect to this URL on errors>
AddHandler jrun-handler .jsp .jws .cfm .cfml .cfc
</IfModule>
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so


#######################

### FOR CFMX 7

#######################

# JRun Settings
LoadModule jrun_module "C:/CFusionMX7/runtime/lib/wsconfig/1/mod_jrun20.so"
<IfModule mod_jrun20.c>
JRunConfig Verbose false
JRunConfig Apialloc false
JRunConfig Ssl false
JRunConfig Ignoresuffixmap false
JRunConfig Serverstore "C:/CFusionMX7/runtime/lib/wsconfig/1/jrunserver.store"
JRunConfig Bootstrap 127.0.0.1:51011
#JRunConfig Errorurl <optionally redirect to this URL on errors>
#JRunConfig ProxyRetryInterval 600
#JRunConfig ConnectTimeout 15
#JRunConfig RecvTimeout 300
#JRunConfig SendTimeout 15
AddHandler jrun-handler .jsp .jws .cfm .cfml .cfc .cfr .cfswf
</IfModule>

Also to make my life easier (though not as easy as i first thought it would but thats for another post) i'm using System Manager

Comments Comments (2) | Print Print | Send Send | 2969 Views

Open source Java by Apache

ZDnet is reporting that Apache is going to create, from scratch, an open source implementation of J2SE, and has Sun's approval to do so

The implementation which is (at the moment) welcomed by Sun, might even have Sun helping them out. Though don't get too excited analysts are expecting it to take 3-5 years

Comments Comments (4) | Print Print | Send Send | 1901 Views

Subversion on Apache Installation Tutorial for Windows (newbies)

A stright forward guide to the initial set up of Subversion (on Apache)

better-scm.berlios.de/subversion/Svn-Win32-Inst-Guide.html

Comments Comments (1) | Print Print | Send Send | 4813 Views

apache, with virtualhosts on multiple ports

Here mainly because i forget this. If you want to set up a new VirtualHost ,on your Apache Server,on new port i.e. 81 just add this to your HTTPD.conf file

<VirtualHost 127.0.0.1:81>
   ServerAdmin temp@temp.com
   DocumentRoot "c:/wwwroot/"
   ServerName www.newsiteport81.com
</VirtualHost>

but before you restart the services don't forget to make Apache Listen on that port as well by adding the following under "LISTEN 80"

# ADD PORT 81
Listen 81

Without this Apache will not be listening on PORT 81, and you'll be sitting in front of your box wondering what you've missed - you'll realise - then you'll blog about it ;o)

Comments Comments (3) | Print Print | Send Send | 4421 Views

More Entries

BlogCFC by Raymond Camden + Twitter @AndyJ + ColdFusion jobs + Contact Me + Snippets/Downloads + RSS .