Category Archives: Useful scripts

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):
  • 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:

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:

To use the code: