Switching PHP versions via the terminal

I ran composer install today, and was rather surprised to find that the intl module wasn’t installed?! Then I remembered I had installed package updates etc, and it turned out I had BOTH PHP 7.3 AND PHP 7.4 installed!

All my sites were developed on 7.3, so I had to switch back.

update-alternatives --list php

Typing that command in will output something like this:


Now you can see the available versions. To switch versions, I simply typed

sudo update-alternatives --set php /usr/bin/php7.3

Upgrade your Terminal!

If you are using the Bash terminal, or the Mac OSX Terminal, time to get rid of it! You need Zsh! (pronounced zoosh). From the Github page:

Oh My Zsh is an open source, community-driven framework for managing your zsh configuration. That sounds boring. Let's try this again.
Oh My Zsh is a way of life! Once installed, your terminal prompt will become the talk of the town or your money back! Each time you interface with your command prompt, you'll be able take advantage of the hundreds of bundled plugins and pretty themes. Strangers will come up to you in cafés and ask you, "that is amazing. are you some sort of genius?" Finally, you'll begin to get the sort of attention that you always felt that you deserved. ...or maybe you'll just use the time that you saved to start flossing more often.

So, what are you waiting for? Give it a spin!

curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh

Or using wget:

wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh

Well worth a try! https://github.com/robbyrussell/oh-my-zsh

Tail every MySQL query in your terminal

It’s nice to see what the actual queries that run are on your site. Its pretty simple to set up! In your home folder, edit your .bashrc (or equivalent) and slap in the following:

alias tmysql='mysql -u root -e '\''SET GLOBAL general_log = "ON"'\'';sudo tail -f /var/log/mysql/general.log;mysql -u root -e '\''SET GLOBAL general_log = "OFF"'\''; sudo rm /var/log/mysql/general.log; echo '\''\nExiting Tail, Log Deleted.'\'';

Tweaking paths where required, obviously. Now close and open your terminal again, and when you type tmysql, you’ll start tailing MySQL! Sample output below!

          453 Query    SELECT `main_table`.* FROM `enterprise_customersegment_segment` AS `main_table`
          453 Query    SELECT `op_imagecdn_cache`.* FROM `op_imagecdn_cache` WHERE (`op_imagecdn_cache`.`url`='http:blah.com')
          453 Query    SELECT `main_table`.* FROM `madskull_autoblocks` AS `main_table` WHERE (identifier = 'trust-banners')
          453 Query    SELECT `madskull_autoblocks_definitions`.* FROM `madskull_autoblocks_definitions` WHERE (`madskull_autoblocks_definitions`.`id`='39')

Fixing the Shellshock Vulnerability

While I was on holiday in Andalucia (Olé!) a vulnerability was found for the Bash shell, called Shellshock (or BashDoor).
So you’ll be wanting to secure yourself up then. First up, lets see if you are vulnerable:

env x='() { :;}; echo vulnerable' bash -c "echo this is a test"

If the output contains ‘vulnerable’, then you need to fix it. If not, you’re all good. To fix it:

sudo apt-get update
sudo apt-get -s upgrade
sudo apt-get  upgrade

Now get back on with your work! 😉

Setup SSH keys for login without password

Sick of being asked for your password? Set up SSH authorised keys and forget about it!

you@localmachine:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa): 
Created directory '/home/you/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/you/.ssh/id_rsa.
Your public key has been saved in /home/you/.ssh/id_rsa.pub.
The key fingerprint is:

you@localmachine:~> chmod -R go-rwx ~/.ssh

Now copy the contents of /home/you/.ssh/id_rsa.pub, and SSH in for the last time with your password to your remote machine:

you@localmachine:~> ssh user@remote.com
Last login: Tue Jan 28 14:14:51 2014 from
CentOS release 6.3 (Final)

user@remote.com:~> cd .ssh
user@remote.com:.ssh> nano authorized_keys

Paste in the contents you copied from your public key file. Make sure it is all on ONE LINE. Save and exit.

user@remote.com:.ssh> cd ..
user@remote.com:~> chmod -R go-rwx ~/.ssh
user@remote.com:.ssh> exit
you@localmachine:.ssh> ssh user@remote.com
Last login: Tue Jan 28 15:28:51 2014 from
CentOS release 6.3 (Final)


Upgrade to PHP 5.4 on Mac OS X Lion

The PHP that ships with Mac is getting rusty. Time to get PHP 5.4!

I tried several methods, and several fail failed. This one (https://gist.github.com/2721719) didn’t.

sudo port selfupdate
sudo port -u upgrade outdated

sudo port install php54 php54-apache2handler
cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n php5 mod_php54.so
sudo port install php54-curl php54-ftp php54-iconv php54-mbstring php54-mcrypt php54-mysql php54-openssl php54-soap php54-sqlite php54-xsl php54-zip php54-xdebug php54-mongo

sudo port install php53 php53-apache2handler
sudo port install php53-curl php53-ftp php53-iconv php53-mbstring php53-mcrypt php53-mysql php53-openssl php53-soap php53-sqlite php53-xsl php53-zip php53-xdebug php53-mongo

cd #
curl http://pear.php.net/go-pear.phar -o go-pear.phar
sudo php go-pear.phar

And then we can select which php the system uses by saying either of these:

sudo port select php php54
sudo port select php php53

When installing Pear:
Option 1. Installation base ($prefix) : /opt/local/lib/php54
4. Binaries directory : /opt/local/bin
Then get PHPUnit

pear info pear && rm go-pear.phar
sudo pear config-set auto_discover 1; sudo pear install pear.phpunit.de/PHPUnit

Lastly we nano /etc/apache2/httpd.conf and ctrl-w to look where php is. Comment the 5.3 one, and add the line:

#LoadModule php5_module libexec/apache2/lib_php5.so
LoadModule php5_module /opt/local/apache2/modules/mod_php54.so

So we can switch between the two by moving the comment. Finally restart apache!

sudo apachectl restart

phpinfo() and php -v both showing 5.4! Fantastico! Remember to set your default timezone now!