Web and application development


Getting trusted HTTPS on your site with letsencrypt

NOTICE The new script for Lets encrypt has been release which simplifies install and getting a cert, check out

If you haven't heard about Let's Encrypt yet, read up on their site. It is a new, free and automated Certificate Authority. This can easily be used to get HTTPS support on your site for free and with  a small amount of work.

Note! The cert from lets encrypt is only valid for 90 days and needs to be renewed again after that.

Installing the lets encrypt wrapper script

Start with getting the lets encrypt script that will automate most of the process for us. Clone from github and show the command help:

sudo git clone
cd letsencrypt
sudo -H ./letsencrypt-auto --help # will check and download all dependencies

Setup SSL with trusted Cert on Apache

Full Apache virtual host config files

Automatic (did not work for me)

  1. Run the automatic script
    sudo -H ./letsencrypt-auto --apache
  2. Follow the onscreen guide to enter email, agree to terms of service and select domains
  3. Done!

Manual steps (worked for me)

  1. Stop your apache server, to free up port 80
    sudo service apache2 stop

  2. Run letsencrypt script which starts a standalone server and authorizes cert, set all domains that is going to be secured with this cert.
    sudo -H ./letsencrypt-auto certonly --standalone -d -d

  3. First time you are prompted to enter your email and agree to the terms of service

  4. Edit apache virtual host config to include the cert created in previous step, the path to the files was outputted after successful creation. Mine was to /etc/letsencrypt/live/ Add this to your SSL virtual host config file (running on port 443):

    SSLEngine on
    SSLCertificateFile /path/to/file/fullchain.pem
    SSLCertificateKeyFile /path/to/file/privkey.pem
  5. Make sure that apache is listening to port 443

  6. Start apache
    sudo service apache2 start

  7. Done!

Redirecting traffic from http to https


If you want to redirect all traffic from http to https, which is a good thing to do if its possible for you. Then this can easily be achieved with apache Redirect directive. Add this to your HTTP virtual host: (but use your full https url)

Redirect permanent /

Other good links to read


Unit testing models in Laravel 5 with SQLite in Memory

So you want to run Unit tests with PHPUnit on your Laravel 5 application, and do some actual database interaction instead of mocking data?

I do that for one of my applications and I'm using SQLite with in memory database to increase performance event more. I'll quickly show how i have set it up.

Config and environment in Laravel 5

Laravel 5 uses the DotEnv library for environment configuration. That means that you have .env file in the project root, to define variables specific to your enviroment, and also one .env in the production to specify the environment.

Your local .env file could look something like this:



It's just key-value pairs. They are used by the different config files.

The config/database.php file (rows not related to this text is removed):

return [
    'default' => env('DB_CONNECTION', 'mysql'),
    'connections' => [
        'testing' => [
            'driver'   => 'sqlite',
            'database' => ':memory:',
            'prefix'   => '',
        'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE'),
            'username'  => env('DB_USERNAME'),
            'password'  => env('DB_PASSWORD'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,

As you see, the config/database.php has references to the variables in the .env file using the env() function, with looks like env(key, default). that functions get the corresponding value from the .env file. And one that is particular interesting in this post is DB_CONNECTION. As you saw in the .env file that was set to mysql. Laravel will be using the mysql connection with the host, database and credentials configured in the .env file.

Testing environment

But when we run phpunit we want to use the testing connection from the config/database.php with uses in-memory sqlite database.

This is done by setting php environment variables in the phpunit.xml file:

<?xml version="1.0" encoding="UTF-8"?>
        <env name="APP_ENV" value="testing"/>
        <env name="DB_CONNECTION" value="testing"/>

This will set the environment to testing with `APP_ENV (if you use that in config/app.php) and also select the testing connection in the database config when you run phpunit.


Updated portfolio

Update portfolio with page about Hillsong Kids checkin