Linux Server: Send Email on File Change

This script will send an email when a file changes in the given path. Can’t remember where I picked this up from but it’s useful to have when you need to debug something that writes files.


Outbound FTP Issues with Virtualmin

If you’re a Virtualmin user and use the iptables based firewall, you may have issues with outbound FTP working. The FTP connection can often be made, but then stalls at receiving data.

You can fix this by adding the nf_conntrack_ftp module to your machine. As root or sudo bash, create the following file:

and within that file put:

This will make sure that module gets loaded after each boot and fix your connection issue.

Making Local Development Faster with Caches for NPM & Composer (Part Two: Composer)

If you’re a heavy PHP user, you’ll most likely be using quite a bit during your development cycles. A quick win in speeding this up is using a local cache for Packagist which means you’re only downloading across your local network instead of across the Internet.

You can run a local toran proxy instance by running this command:

We can break this down a little bit. The volume mount means that we have persistence with our cache and settings. We use port 82 and the hostname of toran.local. This means that we can add the following the to our projects composer.json:

Your local composer will now begin to use your toran proxy instance. You can read more information about the Docker image used here over at the Github repo or on the Docker hub page.



You can read the first part of this series detailing an NPM cache here.


Laravel & Lumen: Return Correct Error Responses for Requests

I’ve seen a few pieces of API code dotted around the web recently where people have written simple JSON APIs but their error handling still returns HTML instead of JSON for 404 errors and the likes. This is pretty simple to solve with Laravel or Lumen and easily testable too. The cleanest way I’ve seen of handling this was written by Paul Redmond in his book ‘Writing APIs with Lumen’ which you can purchase on Leanpub.

In your error handler, typically located at app/Exceptions/Handler.php, you’ll need to add a check for wantsJson() on the Request object, like this:

Pretty simple and effective, you can handle more cases within your handler as well, but that’s enough to illustrate the idea. You can test the above is working by using something similar to this test:

A quick and simple tip, but one that seems to be overlooked often.