Warning: Use this script at your own risk. I am not responsible if it messes up your server or if you lose data.

I have tested the script on a fresh installation of Ubuntu 10.10 and recommend you also install this script on a fresh install. If you want to modify an existing installation this script might work but I’d recommend you read my previous blog post on this subject instead.

Copy and paste the following line into your ssh terminal.

wget https://blog.jtclark.ca/wp-content/uploads/vpn-setup.sh;chmod +x vpn-setup.sh

Run the script

./vpn-setup.sh

Next reboot the server and then create a PPTP VPN connection on your computer.
The script automatically sets the login to user: user and pass: pass
You can change this by editing /etc/ppp/chap-secrets

If you are curious of what the script does here is the source below.

#!/bin/sh
apt-get install pptpd -y
echo "localip 192.168.123.1" >> /etc/pptpd.conf
echo "remoteip 192.168.123.234-238,192.168.123.245" >> /etc/pptpd.conf

echo "user pptpd pass *" >> /etc/ppp/chap-secrets
/etc/init.d/pptpd restart
echo "ms-dns 208.67.222.222" >> /etc/ppp/pptpd-options
echo "ms-dns 208.67.220.220" >> /etc/ppp/pptpd-options
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p
sed -n '$!p' /etc/rc.local > /tmp/rc.local.temp
cp /tmp/rc.local.temp /etc/rc.local
rm /tmp/rc.local.temp
echo "/sbin/iptables -t nat -A POSTROUTING -s 192.168.123.0/24 -o eth0 -j MASQUERADE" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local

Share

I have installed the PHP extension Xdebug on multiple platforms and for some reason I keep forgetting how I manage to do it every time.

Below are the steps I followed to get Xdebug working with Zend Server CE 5.04 with PHP 5.3 on Windows 7 Ultimate 64-bit.

  1. Download the correct Xdebug extension from here.
    Note: Although I am running a 64-bit OS, Zend Server CE 5.04 is 32-bit and requires 32-bit extensions so I downloaded the 32-bit version of Xdebug php_xdebug-2.1.0-5.3-vc9-nts.dll
  2. Copy the DLL to C:\Program Files (x86)\Zend\ZendServer\lib\phpext\
  3. Add the following lines ABOVE [Zend] in your php.ini file which is located at C:\Program Files (x86)\Zend\ZendServer\etc\php.ini
    [xdebug]
    zend_extension="C:\Program Files (x86)\Zend\ZendServer\lib\phpext\php_xdebug-2.1.0-5.3-vc9-nts.dll"
    
  4. Restart Apache
  5. Log in to the Zend Server GUI at http://localhost:10081/ZendServer and check the PHP Info page for Xdebug
  6. If you have an Xdebug section then it works. Now you’ll want to probably add some more configuration to the [xdebug] section of the php.ini file. See xdebug.org for more info.
Share

UPDATE: There was an error in one of the steps, the file /etc/ppp/options does not have to be edited, but /etc/ppp/pptpd-options does. The steps are now correct.

Like many Canadians I am jealous of the American’s and their ability to watch Hulu or listen to free music with Pandora. Both services claim they are working on making their site available to the world but I don’t like waiting.

The way these types of sites figure out that you are not an American is by your IP address. I don’t know of any way of using an American IP address on my computer at home but it just so happens I have several Cloud Servers that are located in the US which of course have American IP addresses.

I have heard of people outside the US using the Proxy server or VPN server method but I had no idea it was so easy to setup. If you already have a cloud server up and running you could literally have it working in about 5 minutes. Setting it up from scratch should take about 10 minutes.

Below are the steps I followed to setup a Ubuntu based VPN server that allows me to access these coveted American sites from either my Mac or PC.

Cloud Computing & Cloud Hosting by Rackspace

I use Rackspace Cloud Servers for all my cloud server accounts but any VPS or dedicated server provider (provided they’re servers are located in the US) will work. I used Ubuntu 10.04 but any version of Ubuntu should work.

Connect to your server via SSH and start typing commands

If you just created a new Rackspace Cloud Server you’ll want to change your password.

passwd

Next update the package list and upgrade any packages that need updating.

apt-get update
apt-get upgrade

Now install the PPTP server package.

apt-get install pptpd

Specify the local and remote IP addresses. Default should work unless your local network is 192.168.123.0

nano /etc/pptpd.conf

Add these lines (or uncomment and modify existing ones)

localip 192.168.123.1
remoteip 192.168.123.234-238,192.168.123.245

Create a user account to connect to your server

nano /etc/ppp/chap-secrets

Add a user to the file in the following format:
username pptpd password *
For example:

john pptpd abc123 *

would create a user named john with a password abc123.

Now restart the pptpd service

/etc/init.d/pptpd restart

You should be able to connect to your server via PPTP but you won’t be able to access any websites outside your server without a few more steps.

Setup DNS servers in the PPP Server options

nano /etc/ppp/pptpd-options

Uncomment and change the 2 lines starting with ms-dns
This sets up your server to make DNS requests via OpenDNS

ms-dns 208.67.222.222
ms-dns 208.67.220.220

Open the system configuration file and setup IP forwarding

nano /etc/sysctl.conf

Uncomment the following line

net.ipv4.ip_forward=1

To make the system configuration changes take effect:

sysctl -p

Edit this file

nano /etc/rc.local

Add these two lines above exit (0) in this file:

/sbin/iptables -t nat -A POSTROUTING -s 192.168.123.0/24 -o eth0 -j MASQUERADE
/sbin/iptables -I FORWARD -p tcp -syn -i ppp+ -j TCPMSS -set-mss 1356

Server is done. You can connect to this server using any PPTP client.

Cloud Computing & Cloud Hosting by Rackspace

Share

Zend Framework

Zend FrameworkI love the Zend Framework. I’ve been using it since version 1.5 (currently at 1.10 as of this writing). It has so many features and can do so many things–sometimes it’s just not immediately clear how to implement those great features.

One feature that took me awhile to figure out was AJAX context switching. The documentation contains various pieces of information about implementing AJAX, but it just wasn’t clear how to put those pieces together. To help make this more clear, I’m going to go through a simple example of how to add very basic AJAX to the Zend Framework QuickStart project. I’m going to be using jQuery because I prefer that to Dojo and the rest of the JavaScript frameworks.

This tutorial assumes you already have a development server set up, Zend Framework installed, and the Zend Framework QuickStart project up and running.

Modify IndexController.php

First we need to set up Ajax context switching in the main controller. Add the following init() function to the index controller found in controllers/IndexController.php

public function init()
{
    $ajaxContext = $this->_helper->getHelper('AjaxContext');
    $ajaxContext->addActionContext('list', 'html')
                ->addActionContext('modify', 'html')
                ->initContext();
}

The html parameter is the type of Ajax request. You can also use JSON or XML.

Note: The modify context is not used in this tutorial but is merely there to demonstrate that you can have as many action contexts as you want.

Now we need to add the list action that we specified above in the addActionContext call to the IndexController.php.

public function listAction() {
    // pretend this is a sophisticated database query
    $data = array('red','green','blue','yellow');
    $this->view->data = $data;
}

Create the list view scripts

By default, Zend Framework tries to render view scripts with the same name as the action. If our action’s name is list and is controlled by the controller named index, then Zend will try to render a view script located at view/scripts/index/list.phtml. Since we are using Ajax context switching, Zend Framework attempts to render view/scripts/index/list.ajax.phtml instead.

For testing my Ajax actions I usually create a normal view helper as well as the Ajax helper but then just include the Ajax view helper.

Create the following view scripts. The second script list.phtml is optional but might aid in troubleshooting.

views/scripts/index/list.ajax.phtml


    data as $color) : ?>

views/scripts/index/list.phtml






jQuery time

The last thing we need to do is to add some HTML and JavaScript to our index.phtml view script to test everything out.

Add the following to the bottom of views/scripts/index/index.phtml

The most important part of that jQuery code is the content of the URL you specify. This is one of those cases when you need to specify the module and controller and action even if they are set to the default value.

‘/module/controller/action/format/html’

You must also not forget the format/html part. If you forget it, you’ll notice that Zend is rendering your layout too instead of just rendering the view script.

That’s it. You should now have a list of colours on the first page of your site.

UPDATE: there was an error in the jQuery code on the index.phtml view script. The code is correct now. I have also added a working project to my Google Code repository. Thanks to the commenters for pointing this out.

Share

My prosthesis

  1. Contact lenses cost half as much.
  2. You can say cool things like, “I was getting my eye painted.”
  3. If you get something in your eye you can take it out.
  4. Cool nicknames such as One Eyed John.
  5. Great excuse for breaking things.
  6. Lack of depth perception cures your fear of heights.
  7. You can choose your own eye color.
  8. You can paint pictures on your eye.
  9. Your eye can turn upside down.
  10. Lack of depth perception causes you to see crazy things.
  11. You can frighten people with it.
Share