Tag Archives: tools

Installing WordPress via the command line

I found myself having to create more and more WordPress websites after clients would specifically ask for ‘a WordPress website’. Although WordPress is built as a blogging tool, it can be used as a very simple content management system (without too much customisation in the back end).

After installing WordPress manually for the seventh time, I thought it would be an idea to make a quick shell script that I would be able to use over SSH, as servers are able to download files via wget much quicker than I can downloading to my local machine and then uploading via FTP or copying it over via scp or rsync. Some hosting providers have automated scripts already installed within Plesk, cPanel and other web host management systems that allow you to install WordPress with a click of a button. It will install the latest version, set up the database and you’re set. The only issue here is when you’re working on dedicated or cloud servers where these tools are not readily available.

I’ve always been the one to start something from scratch so I know the exact the process, how long it should take and what to expect, as well as the ability to easily customise so it can meet my needs.

This simple shell script will:

  • download and unzip the latest version of WordPress
  • remove the sample configuration file
  • generate random salts (taken directly from the WordPress website): https://api.wordpress.org/secret-key/1.1/salt/
  • create a custom configuration file
  • define the SITE_URL and HOME_URL variables as per your handle name
  • copy over any predefined themes and plugins
  • change permissions and ownership of the installed files (otherwise, if you’re running this as root, you’ll end up with internal server errors)

I’ve added a load of comments against each part of the code so it should be easy enough to follow. Anyway, here it is:

I think the only bits I am missing, that I will eventually get round to doing is:

  • Install a new database for the WordPress website
  • Set up new database credentials and insert them into the configuration file
  • Add an environment variable (so it will use scp instead of cp for copying over files if you’re not installing locally, change the predefined URL names and other useful bits)

I hope this script helps someone installing WordPress on their server or local machine (or at least makes the process a little quicker). If there’s anything that I have missed that might be useful to you, please mention them in the comments and I will update the installation script.

This code is also available on GitHub so feel free to download or even contribute: https://github.com/olivertappin/wordpress/blob/master/wordpress.sh

Watermarking images using PHP

My girlfriend recently started a photography business. I found her uploading her photos to Facebook or her website with her logo in the bottom right of the image. She would use Photoshop to do this manually but the work really started when there were quite a few photos to do this to.

I know there are batch processes in Photoshop but this can be quite slow depending on what you’re doing. Photoshop seems to show you the running batch process which uses up a lot of CPU rending the changes on screen. As she’s lucky enough to have me for a boyfriend, I thought I would help out by writing a little script she could use to do this for her.

The class takes a predefined logo and sticks it on the image, saves it and moves on to the next one. There are two versions of the logo, one to be used on a light background, the other to be used on a dark background:

View the class on GitHub: https://github.com/olivertappin/watermark/blob/master/watermark.php

To use the code:

How to use Ack – Beyond grep

I was first introduced to ack when working for a small web agency in the south by a guy called Stuart. I remember him explaining it as “it’s much faster than grep, but that’s because it cheats”. This article will show you how to use ack as well as the useful flags available to speed up your back-end web development.

If you’re on Mac OS X using Homebrew, installation is as easy as

brew install ack

Otherwise, installation is just as easy across other packages, just visit http://beyondgrep.com/install/

Using ack is pretty simple, and super fast. It’s rather useful as it shows the line numbers within the code and you can change how many lines you want to show before and after using the -c flag like so:

ack '\.container' -C 9

The backslash stops the dot from being used as a regular expression, so we’re essentially searching for just ‘.container’. The results are as follows:

➜ resource git:(master) ✗ ack '\.wrapper' -C 9
27- height: 26px;
28- padding-left: 162px;
29- box-sizing: border-box;
30- background-repeat: no-repeat;
31- background-image: url('../img/logo.svg');
33-.content {
34- padding: 55px 0 20px 0;
36:.wrapper {
37- margin: 0 auto;
38- padding: 0 20px;
39- max-width: 1000px;
40- position: relative;
44-/* --- Page --------------------- */

If you’re a new guy taking over someone else’s work and have no idea where anything is, without having anyone to ask, ack will end up being your best friend. Looking for that horrible problematic inline styling on that div tag? Just use ack:

ack '\<div style\=\"margin-top: -27px;\">'

And there it is. No more nasty !important hacks. I know this has helped me on a number of projects on so many occasions, especially during handovers and the person of interest is off.

If you’re ever looking for something, don’t forget you always have man files. I always forget we have these to look at, it’s just a case of using them and searching for the right keyword to find what you’re looking for. Just use:

man ack