Enabling MailHog and mhsendmail in Docker on a Ubuntu container

April 2nd, 2016

This captures emails sent from php via MailHog, so you can display them in it’s nice web GUI.

In your docker-compose.yml

build: containers/app
container_name: app
hostname: app
– TERM=xterm
– mailhog
– “80:80″
– “443:443″
– /code/:/app
– /data/:/data
container_name: mailhog
hostname: mailhog
image: “mailhog/mailhog”
– 8025:8025

In your main app container’s DockerFile, you need to configure “go” and install mhsendmail:

RUN DEBIAN_FRONTEND=noninteractive apt-get -y install golang-go
RUN mkdir /opt/go && export GOPATH=/opt/go && go get github.com/mailhog/mhsendmail

In your main app container’s php.ini

[mail function]
sendmail_path = “/opt/go/bin/mhsendmail –smtp-addr=mailhog:1025″

Change default browser in Thunderbird on Linux

March 1st, 2015

Go to Edit -> Preferences -> Config Editor

Toggle the values of the following to true:


The next time you click on a link in an email Thunderbird will ask you to select a browser to use :)
Yay to Thunderbird for being completely awkward.

MySQL Replication Setup (using dump)

October 19th, 2014

On the master, enable binary logging and set a unique server ID. Each MySQL server being replicated to must have a unique ID also. Modify my.cnf with the following, and restart MySQL.


On the Slaveedit my.cnf and add a unique server ID for the slave.


On the master, add a user for replication that has the ‘replication slave’ privilege. This should be a separate user that can only be accessed from specific hosts, for security purposes. More info at http://dev.mysql.com/doc/refman/5.1/en/replication-howto-repuser.html

Get master bin log coordinates and lock tables to prevent changes whilst synching…

Start a session on the master and run:


Using a different session, run SHOW MASTER STATUS to get the current bin log file name and position. Note these down as they are used in the ‘CHANGE MASTER TO’ slave statement later.

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
| mysql-bin.000003 | 73       | test         | manual,mysql     |

On the master, dump the database you’re wanting to replicate and scp it to the slave server.

mysqldump': mysqldump -u root -p TheDb > TheDb.sql
scp TheDb.sql user@server:

On the slave, import the DB dump from the master:

mysql -u dbuser -p < TheDb.sql

After that, run a ‘CHANGE MASTER TO’ statement:


and then start replication with:


You should now exit the session on the master that was locking the tables (or use the unlock tables statement).
Replication should now be setup :)

Repairing GRUB

October 25th, 2009

Here is how to restore your GRUB MBR after installing Windows 7 (or any version for that matter).

  1. Grab a boot CD of Ubuntu and boot it up
  2. Open the terminal
  3. > sudo grub
  4. If you have a none standard installation (multiple installations of linux or weird partition setup) then use:
    > find /boot/grub/stage1
    to discover where your root should be
  5. > root (hd0,0)
  6. > setup (hd0)
  7. > quit
  8. reboot :)

I personally have 2 different flavours of linux installed and my root happened to be 0,4 and 1,4 as I have 2 drives and each install was on a different partition of each drive. I would recommend choosing the one that you boot into most frequently – as when you install new Kernels etc via apt it will auto configure GRUB for you.

Mass text replace in multiple files with Sed

June 14th, 2009

I came across a neat method of replacing a string in loads ‘o’ files today.
Basically pipe the output of grep for your search string into sed doing a regex replace on the string.

grep -lre 'SEARCH_STRING' . | xargs -d'\n' sed -i "s/SEARCH_STRING/REPLACE_STRING/g"

Batch converting PSD images in linux using ImageMagick

February 24th, 2009

I found myself wanting to batch convert a load of psd files to jpegs today, so I went about looking for a way to do it via the command line.

The tool I chose was Imagemagick. At first I was going to use the tool ‘mogrify’ but it doesnt seem to support the -flatten parameter even though it says it does in the manual… hmmm. The flatten param is needed when converting a psd because of course the psd is multi layer so if you try convert to jpeg without flattening it will generate a jpeg for each layer.

I opted for the standard ‘convert’ command with a little bash magic. The following little script will process all psd files in a folder to jpeg files. You could easily change it to pass in more parameteres etc.


if [ -z “$1″ ]
echo “Usage: please specify a base directory”
exit $E_NOARGS

for file in $1/*; do
/usr/bin/convert -quality 80 -flatten $file ${file/psd/jpg}

Xdebug and PDT

February 22nd, 2009

Today I finally got round to getting debugging working with PDT (2.0) and Xdebug 2.

It wasn’t as hard as I thought as it turned out, I had previously presumed that because I make heavy use of mod_rewrite to rewrite my urls – Xdebug would not know how to find the correct class etc to debug.

The solution was simply to create a server mapping which tells the main site url e.g http://www.mysite.com to point to /ProjectName/index.php (which is where all URLs get pointed to).

Here are the exact steps I took:

  1. First of all, you need to obviously install Xdebug, which on ubuntu is as simple as doing an apt-get install php5-xdebug.
  2. Configure your php xdebug conf file located at (for ubuntu) /etc/php5/conf.d/xdebug.ini
  3. Add the lines:
  4. Restart apache2… then check your phpinfo() shows the correct Xdebug settings you just added (and the same for the cli using php -i | grep -i xdebug).
  5. Now for the eclipse configuration… go to Window -> Preferences -> PHP -> Debug
  6. PHP Debugger – set to XDebug
  7. Server: Add a new server by clicking on the ‘PHP Servers’ link and point the URL of the document root to your Virtual Host as setup in Apache2 e.g. http://www.mysite.co.uk.
  8. IMPORTANT – if you use mod_rewrite – add a Path Mapping  – Path on server should be your http://www.mysite.co.uk and path in workspace should be your main index.php (or whatever file you rewrite to).
  9. Set your PHP Executable to your php5 bin location (/usr/bin/php probably).
  10. You should now be golden. Go back to your project and use the Run -> Debug (F11) after selecting your index.php file in the project browser, and the debug perspective should open. Your script will be paused on the first line by default (you can change this in the debug prefs) so you can then step into your code and watch variables etc etc and other cool shit.

If you want to learn about mod_rewrite, then I suggest you RTFM :)  Its a wonderful thang…

Motd in Ubuntu

January 25th, 2009

I kept wondering why my motd file (/etc/motd) kept reverting on reboot… so I took a little looksy and noticed it symlinks to /var/run/motd, which is in turn populated by some lines in /etc/init.d/bootmisc.sh.

All you have to do to prevent that is to remove the symlink e.g rm -f /etc/motd and then create a ‘regular’ file with whatever fancy content you want :)

Personally im a fan of Network Science Ascii Generator for generating some pretty ascii text…

Love teh Caffeine

January 20th, 2009

Caffeine Kitty

This has gotta be the most amusing LolCat ever :)

It kinda reminds me of a collegue who is addicted to coke (the drink!) actually…