How to replace an Amazon EC2 instance running CentOS and Plesk
In this video I will show you how you can replace a running EC2 instance with a larger one. You may want to do this if you find that you need bigger and better hardware to serve your website, or to move from a development system to a more powerful production system. In this example my EC2 instance is an M1 Small which hosts a single WordPress website with about 500-700 hits per day. In the screencast I’m replacing it with an M3 Medium instance which really isn’t big enough to cope with the traffic. I have since found that a C3...
read moreHow to log into MySQL as root user in Plesk
You may have noticed that there is no MySQL root user on servers running Plesk. That’s because Plesk renames this user into “admin” by default – for security reasons. The password for the admin MySQL account is the same as for the Plesk Panel admin account. Even so, when you try to login to MySQL – remotely or locally – you may be puzzled to find that your admin password doesn’t seem to work. Let me assure you of your sanity and your keyboard skills: it’s because Plesk encrypts the password in...
read moreHow to remove the Jetpack admin menu from subscribers
The Jetpack admin menu is visible to everybody, including subscribers. This may not be what you want. You may even want to hide it from other admins, perhaps once you’ve given a site over o a client and you don’t want him to switch off vital functionality by accident. Here’s how you can hide the Jetpack admin menu in your WordPress back end. Hide Jetpack from Non-Admins (including Subscribers) If you would like your admin users to see Jetpack and hide it from everyone else, add this to your theme’s function.php file:...
read moreHow to replace and add HTML text elements with CSS
In some circumstances you may can replace HTML text elements via CSS. This is useful if you don’t have access to the source files, or if you want to override text in a Child Theme’s stylesheet. There are several approaches to this conundrum, I’ll show you two of them. Both require that you have a class, ID or element that you can target. You then either amend more text to it, or replace the existing text completely via the CSS pseudo-elements before and after. This isn’t always successful though as the original styling...
read moreHow to switch between several PHP versions in MAMP 2.x
Sometimes you need to test your projects against multiple versions of PHP. If you’re using MAMP that’s fairly easy to do: head over to the MAMP Start Screen, select Preferences and see two versions to choose from. Here I’m using MAMP 2.2 (even though 3.x has been released already) and I have PHP 5.2.17 and PHP 5.5.3. When I switch to the other version MAMP restarts and I can refresh my browser to see my project running on the other PHP version. That’s all good if I actually needed either version – but sadly 5.2.x...
read moreHow to check the size of a file in PHP
PHP has a handy function called filesize() which can help us display how big a file is. It does this in bytes by default, but with a bit of tinkering we can easily convert this into kilobytes or megabytes. Let’s first see how this works in bytes: $file = '/path/to/your/file'; $filesize = filesize($file); echo "The size of your file is $filesize bytes."; Converting bytes into kilobytes works by dividing the value by 1024. PHP is very accurate and will give you 12 decimal digits – perhaps a little overkill. To...
read moreHow to list a directory in PHP and only show ZIP files
I wanted to list a directory in PHP. At the same time, I wanted to make sure only files are listed – not subdirectories or dot directories. More specifically, I only wanted to include files with the ending .zip. Two tools come to the rescue here: scandir() to list the directory and give us an array and the super handy pathinfo() to check a file extension Here’s how I did it function list_zipfiles($mydirectory) { // directory we want to scan $dircontents = scandir($mydirectory); // list the contents echo '<ul>';...
read moreHow to test which HTML form button was pressed in PHP
Imagine you have a HTML form with several values and two buttons at the bottom. One could say “Do This” and the other “Do That”. How do you know which one was pressed by the user? It’s fairly easy – but I keep forgetting this time and time again. We do this by accessing the name attribute of the HTML button in PHP. Consider this HTML form: <form> <input type="submit" name="button1" class="button-primary" value="Do This" /> <input type="submit"...
read moreHow to create a recursive ZIP Archive from a directory in PHP
I’ve just realised how (relatively) easy it is to make PHP create a ZIP Archive from a directory and its sub directories. Previously I had relied on the Linux Shell Command zip or tar to do this which is a convenient one liner. I had assumed that in PHP we had to go through each directory and add the files manually – until I’ve discovered the RecursiveIterator class variants. In this example I’m defining a root path and a file name for my archive (change at will), then iterate through each file in each directory (and...
read moreHow to use ZEN DASH for WordPress
I’ve just released Version 1.3 of ZEN DASH and thought a quick video demonstration is in order – and here it is: In this podcast I will show you how to use ZEN DASH for WordPress and explain how you can easily hide menu options, dashboard widgets, admin footer links and suppress Update Notifications (for WordPress core, plugins and themes). This plugin comes in handy if you’d like to hide functionality before giving the site over to a client. For example, you may not want your client to have access to plugins so he can...
read more