RaspberryPi up and running

This guide will help you set up a Raspberry Pi with Rasbian. Ready to do pretty much whatever you want.

What hardware do you need?

  • First off a Raspberry Pi of course, this tutorial should work on a Model 2B and on a 3B. The only difference for this tutorial is the wifi (which I don’t use)
  • Second I have a network cable, wifi on a 3B will work but a wire is always more stable. But of course you need to get the network cable to the right location in the house.
  • A micro USB power source. This can get a bit tricky. Recommended is at least 2A with 5V. A normal smartphone adapter won’t give that. Using less will slow down your raspberry.
  • a micro SD card, at least class 10 for speed and with 8GB or more. The SD card will serve as the main harddrive for the pi. An micro SD adapter is also needed to install the image on the SD card.

Installing Rasbian

First off download Raspbian Stretch Lite from the Raspberry pi website. When It’s done flash the image on the SD card. There is an official guide that explains it better then what I could do.

Flashing the image can take a while. You could set up all the wires and put things in place.

After the SD card is done

When the writing of the SD card is done. Put a file with the name (of empty folder) named ssh in the root of the boot partition. If you need wifi place a file named wpa_supplicant.conf also in the boot partition. And add the following:


I haven’t tried this myself so more information here

Then plug in the SD card and powerup. Check the IP address guide to get the ip-address of the pi. Do wait 2~5minutes before actually trying. The raspberry has to setup stuff for the first time. If after 20max you still can’t find an IP. The flashing of the SD card has gone wrong and you’ll have to restart.

Go to your own computer and open the terminal (or Putty for the windows users) Login with the command ssh pi@192.168.*.* Use the IP address you noted before. If it asks if you want to continue choose yes. and use the default password: raspberry Putty again will work a bit different.

You should see something like this:
Login in on a raspberry pi by a terminal

Now you are logged-in remote on the raspberry pi. Time to configure some stuff with the command sudo raspi-config.
On this menu we can configure some basic settings. Let’s change some settings. the start screen of raspi-config tool

  1. Change User Password CHANGE THE PASSWORD. Longer is better and safer
  2. Network options
    N1 Hostname the name of your Raspberry in your network. I named mine pi-webserver. Not required. It’s just a label. But usefull if you got multiple Raspberry’s running.
  3. Boot options
    B1 Desktop / CLI Chose the ‘Console Autologin’ of ‘Console’ option. Don’t choose auto login if someone else might have physical access to the pi. Desktop will just waste power.
    Wait for Network at Boot Just turn this off to be safe.
  4. Localisation Options Here you can change the timezone to your current one. You could change the language of the PI and the keyboard layout if you need to. Keep in mind I will be using English.
  5. Interfacing Options we don’t need this
  6. Overclock Set this to the highest setting. It won’t hurt and will make the Pi a faster. This might not be available. If it gives an error just ignore it.
  7. Advanced Options This will be a bit more. A1 Expend Filesystem Run this. No need to reboot immediately. A3 Memory Split Set this to 16. Because we don’t have a interface we won’t need memory for that.
  8. Update Run this is should not hurt. It’s only to update the raspi-config tool.

When this is finished the pi might download some language packs. It it doesn’t reboot. you have to do it yourself. sudo reboot now.

Wait about a minute and login in again like before.


This might take a while but first we are going to update.

sudo apt update && sudo apt upgrade -y

Now we update all default installed software. If the image is old or hasn’t been updated in a while it might take a long time. The date of the image is in the file name of the downloaded image.
At times It might appear to hang. It Unless it’s stuck on one thing 15 minutes it’s probably fine. Give it an 15 to 30 minutes. Else pull the plug.

When it’s done reboot again just to be sure.

You now have a Raspberry Pi ready for use.

Migrate one site out a multisite.

We where asked to host a site. But then it turned out that site was part of a bigger multisite. So after I got all files & db of the complete site I needed to clean it up and only keep the requested site left.

The quick and dirty steps:

  • Don’t change the DNS until you’re done testing.

Webhosting settings

  • Import all files on the server
  • Import the database and change the db settings in wp-config.php.
  • Locally add the domain to the hosts file So I didn’t need to change urls
  • delete all sites using wp site delete SITE_ID
  • Only keep site 1 (the primary you can’t delete) and site 12 (the site ID I needed)

Rename the tables

  • Rename the site 1 tables in mysql RENAME TABLE `amsterda_db`.`wp_links` TO `amsterda_db`.`wp_BACKUP_links`;
  • Rename the site 12 tables to the normal tables RENAME TABLE `amsterda_db`.`wp_12_links` TO `amsterda_db`.`wp_links`;
  • Make sure you only rename the site tables, don’t rename wp_blogs and other multisite tables

Update the url

  • In wp_blogs delete the record of site 12 and change the name to the new main site in wp_blogs.domain. And rename the url inside wp_site.
  • Also cleanup the wp_blog_versions.
  • In wp-config.php change the constant DOMAIN_CURRENT_SITE
  • Search the database for all mentions of the old mainsite. This is a per case check what should be done.
    Links in posts are probably fine. The old url in the wp_options maybe not.

Permissions and roles

  • In the wp_options table search for wp_user_roles as option_name. If this record is not present. Search it in the wp_BACKUP_options and create the record manually.
  • Permissions are still set for site 12 fix that using wp search-replace wp_12_ wp_ wp_usermeta


  • Test your site. At least test uploads, permalinks, creating/updating pages
  • The normal steps usually when deploying a new site.
  • Think about things that might differ on this inherent setup.


  • switch DNS
  • SSL

After the first week

  • Delete all wp_BACKUP_* tables
  • Check for unneeded plugins
  • Check for unneeded users.
  • Possible you should cleanup the uploads folder of old sites, although there may be links to those uploads.

Of course it would be even better to remove the multisite setup. But I was out of time. And I still would have done these steps first.

Posted in TIL

PHP interface type hinting

In interfaces you can force the return type

interface InterfaceTest {
    function GetSingleEntity(): Entity;
    function GetEntitySet() : Entity[];

GetEntitySet should return a array containing Entities. But this kind of syntax is not allowed.
You could just change it to only return an array, but the forcing of the class is the most powerful.
The best is to create a wrapper class for the entities, best would be to use an Iterator.

sed command line tool

sed is not new for me. But it’s such a versatile tool. And I always have trouble finding the precice syntax I need. So here is a collection of examples. It probably will grow in the years.

Replace the home dir with ~.

COMPACT=$(echo ${HOME} | sed "s#${HOME}#~#g")

Replace %SALT% with the variable $SALT in the file wp-config.php

sed -i -E "s/%SALT%/$SALT/g"  "wp-config.php"

.gitignore recursively

Today -after a very frustrating hour- I found out git checks for .gitignore inside folders.

Folder tree example

  • .git (the root)
  • .gitignore
  • wp-content
    • themes
      • project
      • .gitignore (git also checks this one)
Posted in TIL

VVV provision single site

For the last month and a half I’ve started using vvv, and it works like a charm.
As I’m setting up a lot of sites I have to run provision a lot.
And that is quite a heavy operation in vvv because it pretty much checks every thing.

Luckily there is also a way to provision a single site.

vagrant provision --provision-with=site-example

Where site-example is the same as the site key in vvv-custom.yml.

wp cli output format with –porcelain

wp db export

Will output something like Succes: Exported to 'dbname-2018-09-16-2790c11.sql'
Often you need the filename.

--porcelain flag to the rescue!

wp db export --porcelain

This will work on a lot of commands that have one item output.
Stuff like wp post create ....
Here is a complete list of commands that have the –porcelain flag

Commands that output more items usually have a --format flag to handle output.

Declare a variable to a bash script runtime

In the past I’ve did a post about checking if a bash argument is set.
This is different, This way you can pass through a named variable.

    TEST='pass it on' ./testscript.sh

If you do this $TEST will be set inside the ./testscript.sh bash script.
Like the normal arguments you probably would like to validate them inside the bash script.
The main plus side is that you can put arguments in any order and exclude arguments.
It might also be easier to read as you can see the arguments name.

A bit more advanced. You can override global variables for that script run.
Variables like $PWD and $PATH, be careful.

Example script: ./testscript.sh

#!/usr/bin/env bash

if [ ! -z $TEST ]; then
    echo "var is set to '$TEST'";
    echo "var is unset";
Posted in TIL

Global git ignore

A new laptop a new change to optimize stuff. And this is one I should have done years ago.
There are files you always want to avoid. The infamous .DS_Store file comes to mind.

On ubuntu just add whatever you want to exclude to ~/.config/git/ignore

Posted in TIL