A few weeks ago I was trying to shell into my new microserver and from there access a media server to start some downloads.
What I realised was this… unless you know the IP address things get very tedious very quickly:
An attempt to find my media server on the local network
So thinking about my options, and the fact that I’ve just set up my first “real” home network (and by that I mean bothered to configure everything properly like QoS/routing/port forwarding, wired up the house etc). I recently bought my first dedicated server – previously this role was being fulfilled by something that was a warhorse 4 years ago, but now looks more like a panting, furry, very non-green home PC.
So, on with the setup…
I decided upon firing up a Windows Server 2008 instance on my ESXi server to handle both DHCP duties and DNS. I’d read that it was possible to configure the DHCP server to automatically create records with the local DNS server whenever a new client connected. The aim was something like this:
The DHCP server should:
Send the gateway IP address to all clients
Send the appropriate search domain (in this case home.danielbyrne.net)
Send the IP address of the yet-to-be-configured DNS server
Notify the DNS server of a newly connected client so A records can be created
The DNS server should
Answer any requests for its configured zone (*.home.danielbyrne.net)
Accept updates from a linked DHCP server
Forward any DNS queries that it can’t answer (basically the rest of the world) to the Google DNS service on 188.8.131.52
First connect over terminal services to my Windows 2008 server instance. Once in add both ‘DHCP Server’ and ‘DNS Server’ roles to your installation
Adding DNS and DHCP roles to Server Manager in Server 2008 R2
Video showing DHCP server configuration
Create a new scope and give it a name
Configure the pool (range) of IP addresses you want to make available. I chose 192.168.1.100 -> 192.168.1.200
Choose any excluded IP addresses if any
Configure the lease duration. I left a default of 8 days as clients on my network will be relatively static
Add your default gateway (Usually your router or ISP provided modem, in my case 192.168.1.1)
Specify your parent domain and DNS servers. Your parent domain could be something like mynetwork.local, in my case it’s mapped to home.danielbyrne.net. Important it must be a FQDN. mynetwork.local would work, mynetwork wont as it will cause issues with keeping the DNS records updated. Your DNS server will be the IP address of the machine with the DNS service on it and then any alternate DNS servers like Googles service at 184.108.40.206, or your own ISPs servers
After spending two fairly painful days refactoring some code away from PHPAMQPLib (some custom PHP classes that allow for a connection with RabbitMQ) and moving to the official PECL extension I thought I’d document. Let me know if this has helped you!
First of all you need to get a compatible version of the rabbitMQ C library, as the version shipped with Ubuntu 11.10 and 12.04 are not compatible with the PECL extension.
I’ve recently moved over to a custom framework for my main website and wanted deployments into the repositories release branch to be seamless. I could use Jenkins but that would probably be overkill.
To accomplish this, I wrote a quick post-commit post-receive script that will be called by git each time a commit is pushed into my repository. If the branch name matches ‘release’ the commit is extracted into a release folder under the webroot. The webroot directory (in reality a symbolic link) is then updated to point to this new release.
Using symbolic links has the advantage of not leaving your website in an inconsistant state as files are deleted and then re-extracted, it should be an atomic operation.
Here’s the script, put this in your git repository under the hooks subdirectory in a file named ‘post-commit’.
The old revision, new revision and branch name are handily passed into this script
Edit: One thing to keep an eye out for is that if you are running PHP5-FPM, when the symbolic link is switched to the new location the fpm seems to be still serving your scripts from the old location. I would love to figure out why this is but a workaround is to call /etc/init.d/php5-fpm restart as the final step in the post-receive script (not ideal!!)
#!/bin/bash## A post commit hook that takes any updates pushed to the 'release' branch# and creates a release directory for the new version under the webroot.# Live site is then symlinked to this new release directory.oldrev=$1newrev=$2branch=$3# this is the root of the website (a symlink to a release directory)webroot=/var/www/danielbyrne.net/www
if["$branch" == "release"]then# create a release directory to extract files intotarget=/var/www/danielbyrne.net/releases/$2/mkdir$targetecho"Making target directory: $target"# create an archive in the webroot of danielbyrne.net/usr/bin/git archive master --formatzip--output$target/deploy.zip
echo"unzipping archive..."# extract the archiveunzip-o-q$target/deploy.zip -d$targetecho"removing deployment archive"# remove the archive filerm$target/deploy.zip
echo"switching symbolic link to $target"# now switch the live site to point to the new releaseln-nsf$target$webrootecho"done";
My VPS is a little underpowered, and checking the amount of free memory I was, shall we say, a little surprised at just how much Apache thought it needed for the amount of visitors this domain brings in.
The combination of nginx and php-fpm is astoundingly lightweight on memory usage… with nginx and a seperate process manager for PHP (php-fpm) instead of mod_php I now have a few hundred MB to play with. Not just that but the requests per second my server can now handle is through the roof.
Using phpinfo as a test, I’m now managing to serve 3,000 requests per second at a maximum of 3ms per page.
Even the beastly wordpress is coming in at 1,628 requests per second with a helping hand from APC byte-code cache. Breezy.
I’m working on a new project using the latest Zend Framework. I’ve got a modular application and decided that I wanted to hold my module-specific logic classes in their own ‘logic’ subdirectory.
Setting up class to folder mappings is done inside ‘Zend/Application/Module/Autoloader.php’ in the function ‘initDefaultResourceTypes’. In here you’ve got your standard mappings like ‘Form’ => ‘forms’, ‘Model’ => ‘models’ etc.
You’ve either got the choice of overriding this class with your own implementation, or you add your own resource types by putting the following code in your application or module bootstrap:
class MyApp_Bootstrap extends Zend_Application_Module_Bootstrap
* Add some custom resource types to the resource loader
* @return void
This will make the autoloader look inside the logic subdirectory for any classes with the namespace ‘MyApp_Logic’
When using the Zend Framework tool to create directory structures and some basic classes, you might come across the message “An error has occurred. A project already exists here”. A quick Google search found a couple of other people reporting this issue but no solution.
The problem occurs because by default the project provider searches all parent directories for a .zfproject.xml project configuration file. In my case I’d created a testing project further up the directory tree and neglected to delete it – this was fooling the tool into thinking a project already existed.
…which makes sense – you wouldn’t normally have a project inside a project (although you can’t rule out that somebody wants to do this)
either look for a ZF project file in your parent directories:
or, modify the code to search only the current directory if you have a directory structure that the tool doesn’t like
Just got back this weekend from Tuscany Italy. We stayed in a villa two miles from San Gimignano and visited Sienna a Monteriggioni, and spent a lot of time drinking wine by our pool
‘Villa de Belfield’
Some houses in Sienna
An intelligent boar
Sarah striking a pose at the villa
There’s millions of photos (and even more from other trips) that I really should get sorted. Thinking about getting a Flikr or Photobucket account although I’d prefer to host them on my own webserver I’ve yet to find any decent Gallery software.