Installing RabbitMQ and MongoDB on Centos 6

Rabbit MQ

Install wget if you don’t have it.
yum install wget

We need to install EPEL and REMI, package repositories that have a wider variety of more up to date software than centos are prepared to support.
Download the RPM files that will install the packages:
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
Use yum to install them:
sudo rpm -Uvh remi-release-*.rpm epel-release-*.rpm
We now need to alter the yum config for the remi repo to enable it (EPEL is enabled by default):
sudo vim /etc/yum.repos.d/remi.repo
Within the [remi] section set enabled to 1
Get the latest erlang repo definition and put it with our other yum repos:
wget -O /etc/yum.repos.d/epel-erlang.repo http://repos.fedorapeople.org/repos/peter/erlang/epel-erlang.repo
Install erlang:
yum install erlang

Add the rabbitmq repo:
rpm –import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
Download and install rabbitMQ:

http://www.rabbitmq.com/releases/rabbitmq-server/v3.0.4/rabbitmq-server-3.0.4-1.noarch.rpm

yum install rabbitmq-server-3.0.4-1.noarch.rpm
Set rabbit to run on boot:
chkconfig rabbitmq-server on

Set the IP address to bind on – I’ve got multiple NICs and I only want it to listen on one
vim /var/lib/rabbitmq/rabbitmq-env.conf
add:
RABBITMQ_NODE_IP_ADDRESS = 192.168.56.30

start rabbit:
service rabbitmq-server start

Mongo DB

Follow instructions supplied at http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux/
Set a specific IP to bind to:
vim /etc/mongod.conf
add a line:
bind_ip = 192.168.56.30
Remember to restart the service (service mongod restart)

Firewall Config

Open the port in IPTables:
vim /etc/sysconfig/iptables
add the following line before blanket reject statement to allow port 5672 on eth1
-A INPUT -i eth1 -m state –state NEW -m tcp -p tcp –dport 5672 -j ACCEPT
-A INPUT -i eth1 -m state –state NEW -m tcp -p tcp –dport 27017 -j ACCEPT

How I set up and configure CentOS in VirtualBox on OSX

Network Settings

Instructions derived from http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-networkscripts-interfaces.html
We’ll configure two interfaces, one for public traffic and one to communicate with the host, this allows you to have a known IP for the host to talk to the VM on for SSH, Web etc, while allowing for the host using DHCP on it’s NIC.
If you don’t already have a host only network set up in virtual box then go to menu VirtualBox->Preferences, network tab and create one, edit the settings – the adapter tab is the network settings for the host, the virtual NIC that your computer will use to participate in this network, give it a memorable IP address and set the subnet mask, ignore the DHCP tab as we’ll set static IPs for the VMs
On the VM configuration give it two network adapters, one NAT, one host only – pick the network you created earlier.
Edit /etc/sysconfig/network-scripts/ifcfg-eth0 and change the ONBOOT line to yes
Create a script for the second NIC by copying the first one
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth1
Edit /etc/sysconfig/network-scripts/ifcfg-eth1 change:
BOOTPROTO to static
Add IPADDR and NETMASK settings with values that fit with your host network
Change DEVICE to eth1
Set HWADDRESS to the MAC address listed in the VM network config for the second adapter.
service network restart (to pick up the new settings)
Edit the hosts file on the host and vm machines (vim /etc/hosts) and add an entry for the VM with the DNS name you’ll be using

SSH

yum install openssh-server
set SSH to start on boot: chkconfig sshd on
service sshd start
You should now be able to ssh from the host to the vm

Firewall

By default Centos has iptables in and running and only ssh open so open port 80 by:
iptables -I INPUT 1 -p tcp –dport 80 -j ACCEPT
/sbin/service iptables save
service iptables restart

Once you’ve done this once I’d advise you to clone from it in future and change MAC+IP addresses to save yourself time.

How to write a CV for a technical role that will get you an interview with me.

There is a major shortage of .Net and PHP developers forcing me to consider all but the worst candidates that come my way but the quality of the CVs submitted, even by people that turn out to be great at interview, is often so poor that I have been frustrated into writing this post.
Incidentally, if after reading this you reckon you have a CV that won’t make me angry please get in touch via linkedin as I’m always looking for staff.

Covering letter
A CV should present the facts about you, a covering letter should provide context describing your reasons for looking for a job and why you think my role is suitable. Keep it short and informal, it can just be the body text of an email with your CV attached but it goes a long way to show me you are serious about the role.

CV
Length -
Traditional wisdom has it that a CV should be between one and two pages long but I disagree with this. Your CV needs to allow someone to make a quick judgement and it can do this in two ways, brevity and clarity. A very brief CV allows people to make this judgement of you quickly but so does a long but well structured CV that uses sections, headers, italics etc effectively. The difference is that the longer cv will reveal greater detail about the candidate allowing more confidence in the decision to interview and feeding the conversation that takes place.

Skills -
A long list of technologies in isolation is of no use, any list like this should only include those that you will refer back to in your professional, academic and personal experience.

Work Experience -
Tell me what you actually did, list the two or three biggest projects in your latest role and for each one describe what it was, the technologies you used, the role you had and the key contributions you made. This sounds like basic advice but a huge number of CVs contain a high level description of what the application that was worked on did with no details of how it was implemented (to the extent of not knowing if it was web or desktop) or what role the candidate had.
Do not leave gaps, you don’t need to give your history back to the womb but if you tell me about four roles with a two year gap my sordid imagination will fill it – a candidate who applied from prison serving a short sentence for pimping got me thinking.
Explain major changes in career, gaps or mis-steps, there is no shame in changing things around but let me know why you did it so I can see you are not just flitting around.
If a role was a contract then say so, several contracts lasting around a year can be misread as flitting between permanent positions.

Layout -
I would assume this would go without saying but experience tells me otherwise. Do not use clip art, boxes, drop shadows or word art. Nothing fancy, it will probably be broken if I view with MS Word and if you are a programmer you will not have the skills to do it well.

File format -
I use Apple Pages and my colleagues use OpenOffice or Google Docs so if you send a CV in MS-Word format that uses fancy layout options and doesn’t render correctly you are immediately being outclassed by the candidate who sent a PDF or RTF.

Salary expectation -
The grubby bottom line, do not shy away from it. If you apply for a senior role as a middle weight but you are cheap then you are in the running. If you apply for a junior role but are expensive I might decide to recruit higher up.

Language -
I have read CVs written in the third person and as I read them I picture the candidate talking to me while stroking a gun. It’s weird. Don’t do it.
Do not use superlatives, it makes you look insecure.

Online
If you are applying for a role as a web developer then you must provide links to projects you have been involved with where possible either in your CV, covering letter or online portfolio, this shows me you are proud of what you have achieved and makes you more real.
I always look candidates up online using google, pipl.com, twitter, facebook and LinkedIn so manage your online presence. A LinkedIn profile with different job titles and dates to your CV looks extremely suspicious so get your story straight. Make sure there is nothing controversial on your public facebook timeline. If you have a personal site that serves up an error page take it down. The differences between a good candidate and a great one are things like an active github account, a high reputation on stack exchange a well written blog.

Getting ready to develop on OSX + Macports (PHP, Tomcat, MySQL, Apache, PostgreSQL)

This is a quick and nasty post with the exact steps I went through to get my Macbook Air running Lion ready to develop PHP, Tomcat, MySQL, Apache and PostgreSQL. I know I need to tidy up the formatting.
These instructions built on three sources:
Chad Kieffer’s apache2 and php5 install guide
Chad Kieffer’s MySQL5 install guide
Macports install guide

Set up macports

Install XCode 4.3.2 from the app store.
Install the XCode command line tools by launching XCode and going to Open XCode->Preferences->Downloads->Components->Install Command Line Tools

Run the following command to set up the XCode environment:
sudo xcode-select -switch /Applications/Xcode.app

Dowload and install Java from the Apple web site – here.

Download macports and run the installer.

Set up apache

sudo port install apache2
Edit /opt/local/apache2/conf/httpd.conf
Uncomment the line “Include conf/extra/httpd-vhosts.conf”
Change “User www” to “User _www” and “Group www” to “Group _www”

Make somewhere in your home directory for your projects to live and give apache access rights to it:
cd ~
mkdir Projects
chgrp www Projects/

Add to /etc/hosts:
127.0.0.1 projects.mba.local

Add to /opt/local/apache2/conf/extra/httpd-vhosts.conf

Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
AllowOverride All
Order allow,deny
Allow from all

ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot “/Users/USERNAME/Projects”
ServerName projects.imac.local

Set up PHP

sudo port install php5 +apache2 +pear +mysql5 +postgresql

This tells you to compile the apache php extension as follows:
cd /opt/local/apache2/conf/
sudo /opt/local/apache2/bin/apxs -a -e -n “php5″ libphp5.so

Now edit your apache config (/opt/local/apache2/conf/httpd.conf)
Add the lines

AddType application/x-httpd-php .php

Change

DirectoryIndex index.html

To

DirectoryIndex index.html index.php

Choose a PHP.ini file to use:
cd /opt/local/etc/php5/
sudo mv php.ini-development php.ini

- You’ve now installed PHP5 but there’s loads of other packages you’ll want installed, the ones I require are:
sudo port install php5-mysql +mysqlnd
sudo port install php5-apc php5-curl php5-gd php5-iconv php5-imagick php5-imap php5-mbstring php5-mcrypt php5-openssl php5-xmlrpc php5-xdebug

- Finally you need to add the xdebug config to the php.ini file – note that if you put it in the xdebug.ini file it will get over written when macports upgrades xdebug:
sudo vim /opt/local/etc/php5/php.ini
Add the following lines to the end of the file:
[xdebug]
xdebug.remote_enable=on
xdebug.remote_log=”/var/log/xdebug.log”
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
xdebug.remote_port=9000

Set up MySQL

I made things slightly harder for myself by installing MySQL 5.5 which is slightly more fiddly.
sudo port install mysql55 +server
sudo port install mysql55-server
These install mysql but for all the tools to be available on the command line you want to:
sudo port select mysql mysql55
this creates symlinks into opt/local/bin for convenience

For some reason the permissions on all the folders that contain mysql are set to be owned by root not the mysql user so run the following command to correct this:
sudo chown -R mysql /opt/local/var/db/mysql55

mysql55-server said to run sudo -u _mysql /opt/local/lib/mysql55/scripts/mysql_install_db5 – this command is wrong it should be:
sudo -u mysql /opt/local/lib/mysql55/bin/mysql_install_db

Set the following properties in php.ini
mysqli.default_socket = /opt/local/var/run/mysql55/mysqld.sock
mysql.default_socket = /opt/local/var/run/mysql55/mysqld.sock
pdo_mysql.default_socket=/opt/local/var/run/mysql55/mysqld.sock

Out the box mac ports doesn’t set the max allowed packet for mysql which means that some apps (Drupal) will fall over very quickly. It also sets no networking which prevents anything from connecting via tcp
To fix this we need to edit the my.cnf file:
sudo vim /opt/local/etc/mysql55/my.cnf

Comment out (#) the line !include /opt/local/etc/mysql55/macports-default.cnf

And add the following lines:
[mysqld]
max_allowed_packet = 64M

Postgres

sudo port install postgresql91-server
sudo port install php5-postgresql

sudo mkdir -p /opt/local/var/db/postgresql91/defaultdb (-p creates all missing folders in the path not just the last one)
sudo chown postgres:postgres /opt/local/var/db/postgresql91/defaultdb
sudo su postgres -c ‘/opt/local/lib/postgresql91/bin/initdb -D /opt/local/var/db/postgresql91/defaultdb’

start server:
sudo su postgres -c ‘/opt/local/lib/postgresql91/bin/pg_ctl -D /opt/local/var/db/postgresql91/defaultdb -l /tmp/pg.log start’

sudo su postgres -c ‘/opt/local/lib/postgresql91/bin/createuser -s andrewdchancox’
sudo su postgres -c ‘/opt/local/lib/postgresql91/bin/createdb andrewdchancox’

sudo su postgres -c ‘/opt/local/lib/postgresql91/bin/createuser -s moodleuser’
psql91
\password moodleuser
give it a password

Tomcat

TODO
sudo port install tomcat6

Aliases to start and stop

Because I use my laptop for many things other than development I like to start and stop all these services manually, to do this I’ve edited my bash profile (~/.bash_profile) and added the following aliases:
alias start_mysql=’sudo /opt/local/bin/mysqld_safe &’
alias stop_mysql=’sudo /opt/local/bin/mysqladmin shutdown’
alias start_apache=’sudo /opt/local/apache2/bin/apachectl start’
alias stop_apache=’sudo /opt/local/apache2/bin/apachectl stop’
alias start_tomcat=’sudo tomcatctl start’
alias stop_tomcat=’sudo tomcatctl stop’
alias stop_postgresql=”sudo su postgres -c ‘/opt/local/lib/postgresql91/bin/pg_ctl -D /opt/local/var/db/postgresql91/defaultdb -l /tmp/pg.log stop’”
alias start_postgresql=”sudo su postgres -c ‘/opt/local/lib/postgresql91/bin/pg_ctl -D /opt/local/var/db/postgresql91/defaultdb -l /tmp/pg.log start’”

Installing mod_sed on OSX/Macports

I had to use mod_sed for a project that required more exotic functionality than mod_substitute could deliver.
The version of apache that includes mod_sed in core (2.4) is not available via macports, neither is a package containing this one module and I couldn’t find a binary to download so that left me having to compile it myself which wasn’t as scary as I thought it would be.

Go somewhere you can put the files while you work on them:
cd ~/Documents

Download the tarball containing the code:
wget wget http://src.opensolaris.org/source/raw/webstack/apache-modules/sed/mod_sed.tar.gz

Decompress and expand the archive:
tar xzf mod_sed.tar.gz

Go into the folder containing the sourcecode:
cd mod_sed

Now you’ve got the source files accessible we need to compile them. You do this using apxs which is a tool dedicated to compiling apache extensions – you need to make sure that you use the copy of this tool that sits in your macports installation, not the stock OSX version so prepend the path to your mac ports apache bin folder (probably /opt/local/apache2/bin) to the commands:
/opt/local/apache2/bin/apxs -c mod_sed.c sed0.c sed1.c regexp.c
/opt/local/apache2/bin/apxs -i -a mod_sed.la

Once this is done the module should be in the apache modules folder (/opt/local/apache2/modules/mod_sed.so) and enabled in httpd.conf (/opt/local/apache2/confhttpd.conf) by the line:
LoadModule sed_module modules/mod_sed.so

So restart your instance of apache and you can start using the module.