Updating WordPress? Backup first!

I’m sure I’m not the only one who has been a little slack on occasion when updating their version of WordPress and not doing a backup. It sounds such a stupid thing to do, especially when you think about the time you’ve spent working on the site and the time you may well need to spend fixing it!

One of the things that I hated was doing an ftp download of the site. I never got on with backup utilities very well as I wanted to be in control. So, a few years back I realised there was a far simpler method to maintain backups using the Terminal in Mac OSX.

ssh username@yourdomain.com 
cd httpdocs // or whatever your WP root directory is
mysqldump -u username -p database > backupdatabse.sql
[Enter password]
tar -vcf backupfilename.tar .

And that’s pretty much it. It creates two files in your WordPress root. You can secure copy (scp) through the terminal if you want or download using ftp. Either way, the above takes very little time to do and gives you the opportunity to restore things to how they were if it does go horribly wrong.

Ubuntu Linux Installed

So it all started with Windows 95 back in 1996, then Windows 98, then XP. After a quick dive into Fedora, it was over to Mac OS X. After going from Panther to Leopard, with a minor foray into Windows 7 using Parallels, it was off to Snow Leopard

And then along came the Ubuntu flavour of Linux. Very quick to launch, not too hard to learn and I get to (start to) understand the inner workings of an OS. I love it.

One quick test I did was compare Moodle on Windows 7 and MySQL with Moodle on Ubuntu running PostgreSQL. 5-10 seconds per page load on W7. 0,5 or less on Ubuntu. And the Ubuntu Linux machine has a lower spec!

This is one OS I’m going to stick with.

A Coffee at Breakfast for Clarity of Thought

Nine months without posting! I hear the drum roll of the blog executioner fed up with yet more wasted space on the Internet. It really is a discipline that you need to rigidly stick to. What’s the maxim of the author? Get up. Write 100 words before breakfast irrespective of how rubbish they are. Review them after breakfast and tidy them up. After 50 days you’ll have a 40,000-60,000 word novella give or take that’s not a first take.

Of course, you would need to be a bit of a morning person, or at the very least have a restful sleep leaving your mind free of cares at the start of the next day; in addition to being able to remember what it was you had to do that morning, other than make your kids porridge, put the cat out/let the cat in, put the washing on, tidy up, remember to get dressed …

Freelance work can take over a bit as the time you would spend mulling things over and trawling huge numbers of web pages tends to be taken up trying to work out why a piece of code you added isn’t working or which one of the WordPress plugins is causing the conflict. Organising your time is one option, so that you spend a certain amount of time on one thing and then switch to another. However, this is terribly difficult as once you get into a script or are re-designing a site you get carried away with it, and it feels like you’re writing a new book. The design of the code and the pages take over and taking a couple of hours over a 100×100 pixel icon is not unknown.

One of the easier things to do (for some I admit, not for others) is strip away the distractions, the email, the tweets, the urge to check for the latest news, the need to read that latest piece on HTML5, or watching the next episode Homeland/The Waking Dead/The Killing etc. Being self-centred does have its advantages at times.

So, where am I going in this rambling thread of a post. I guess it’s about admitting a certain amount of self-discipline is necessary to not only ensure you get through many of the things you want to do but also that urges to bash away for hours on a single thing do need to be checked at times.

And doing the latter can actually provide you with the fresh hours of an author fresh from their breakfast coffee.

New counterfeiting and copyright agreement with ACTA

ACTA stands for Anti-Counterfeiting Trade Agreement. Before reading on please read it. You can find it at http://register.consilium.europa.eu/pdf/en/11/st12/st12196.en11.pdf. There’s no point talking about something unless you’ve read the original document.

So what do you make of it. Simply put, it’s defined as a trade agreement between many countries to bring about the prosecution of any person or organisation who sells  counterfeit products or infringes intellectual property rights through the reuse of digital content, thereby offering an international legal framework to deal with counterfeit trading and intellectual property infringement. The powers stated in the articles within this agreement can be exceeded by participating countries through their own legal systems.

I don’t disagree that there is a need to redefine our copyright laws, nationally and internationally but what I don’t agree with is embedding what appears to be a new international copyright law within a trade agreement. Digital content must be treated differently to physical products beacause we endanger the distribution of knowledge unless care is taken to define the framework within which content can be provided and used.

Countries who have signed up are: UK, Austria, Belgium, Bulgaria, Czech Republic, Denmark, Finland, France, Germany, Greece, Hungary, Ireland, Italy, Latvia, Lithuania, Luxemburg, Malta, Netherlands, Poland, Portugal, Romania, Slovenia, Spain and Sweden, US, Australia, Canada, Japan, Morocco, New Zealand, Singapore and South Korea.

I’ve long despised the trade in counterfeit physical goods having seen people lulled into buying knock-off goods just because the things being sold were listed at heavily discounted prices. We’ve all seen them at markets in major cities around the world. I have no objection to providing a way for the rights holder to bring about legal proceedings against someone selling fake versions. The seller of the fake products is making money out of someone else’s time and investment.

But that’s for physical products.

The part that has become a talking point is Section 5 entitled the “ENFORCEMENT OF INTELLECTUAL PROPERTY RIGHTS IN THE DIGITAL  ENVIRONMENT” (Anti-Counterfeiting Trade Agreement; p33. http://register.consilium.europa.eu/pdf/en/11/st12/st12196.en11.pdf.

At the start it outlines how anyone infringing another’s intellectual property rights in a digital environment can be prosecuted in accordance with this trade agreement. It goes on to state that any enforcement of the prosecution must not affect anyone who is not infringing the agreement, thereby protecting law-abiding bodies. The thought that is running through my head is whether there is a grey area that will come about due to the difference in interpretation of what is and what isn’t an infringement.What constitutes an infringement? Is paraphrasing a paragraph an infringement? Is copying a sentence or two an infringement? Is using a 2-3 second clip from someone else’s video an infringement?

Going on to Section 5 (4), the rights holder will be able to go to an ISP and request they provide information that identifies the account that was used for the infringement. In addition, (5) states that the ‘Party’, ie country that has signed up to the agreement, must work out ways to prevent the use of technology to deliver copyrighted works in a way that gets round security and other digital rights management processes put into place by the rights holder.

All this seems pretty sensible, be able to identify the person who has reused original content as their own and share this with the authorities and person in a different country, as well as being able to break down the means by which content can be distributed illegally. The key word though is that the account used to infringe the rights should knowingly have done so.

I see no issue with this if the rights holder clearly states that their work is copyright and they do not wish their work to be reused in any way by anyone who has not received their permission to do so. An author who wants their work to be shared, and not in its entirety, should publish it under a Creative Commons licence, which can give others the right to reuse it without express permission.

One perspective on this is to place the responsibility with the owner of the intellectual property. They must explicitly state how they will allow their work to be made available to the public. If they want their work to be shared and distributed then they should choose the appropriate copyright licence and state it clearly. If you don’t have permission then pay for it. If you don’t want to pay for it then don’t use it. Is this a bit harsh? What are the arguments against this?

The one area that worries me is how authorities will go about identifying and monitoring infringements of intellectual property and counterfeiting. ACTA appears to give carte blanche to authorities to do so as long as they can prove their techniques are in place to catch those who break copyright and counterfeit law. There are already highly sophisticated plagiarism checkers in operation and much content has been digitised and available for use within these. Will anything, including film and audio, published via iTunes, Amazon, etc be subject to processing into an immense data library that is used to monitor activity? A small body of people will have the right to limit the online rights of various people as a result of their having permitted intellectual property to be shared in such a way the author did not intend, or did not explicitly state on publication.The net they will need to cast is a wide one indeed.

I agree in principle with not making money out of someone else’s work when they expressly do not wish you to. However, if they aren’t concerned about you doing this then it shouldn’t be outlawed. Additionally, there are currently civil sanctions against this so the author has the option to sue. What happens if the ‘perpetrator’ has not made any commercial gain out of reusing content,  but instead wants to simple spread information?

As you can probably tell, I’m no lawyer and could really do with understanding copyright law better. But, and it’s a big but, creating a new international copyright law and embedding it within a trade agreement does not seem right, and it is this that I’m opposed to. It’s important to not combine the two and allocate more time to the discussion of how intellectual property can be protected where it needs to be. Providing the stick with which to beat people operating in the grey area without adequately defining what that grey area is makes little sense as the final outcome is more than likely to be stricter laws that actually infringe the rights of those who want to share information.

Install a Local PHP Manual with MAMP

I sometimes find myself offline and needing to do web development. As I work mostly with php getting access to the PHP manual can be critical. Without being online the only way to do this is to store a local copy.

Now, I had a few problems getting this to work. Little documentation and a fuzzy head were the main causes. Anyway, I got there in the end so here’s what I did. Pre-requisites are that you have a copy of MAMP (non-pro version) installed and have downloaded and unzipped the manual file.

Copy the manual file somewhere sensible in your localhost root folder. I put mine into /Sites/root/phpmanual/ giving the localhost url of http://localhost/root/phpmanual/php-chunked-xhtml/.

Next, work out which php.ini file you’re using. To do this create and open a phpinfo.php file. A phpinfo.php file just needs the following:

<?php
    phpinfo();
?>

Search for php.ini and you’ll see a line in the row with a heading of Loaded Configuration File. You’ll have a url of something like: /Applications/MAMP/conf/php5.3/php.ini. Open this file in TextWrangler and make the edits below. Make sure you make a copy of the php.ini file before doing this or have some way to restore the original version.

  1. Change display_errors to On.
  2. Change html_errors to On.
  3. Add base url to docref_root and uncomment (delete the semi-colon). In my case the base url is /root/phpmanual/php-chunked-xhtml/.
  4. Uncomment error_prepend_string.
  5. Uncomment error_append_string.
Here’s what they look like in the php.ini file. I’ve added line numbers I get. This is using MAMP Version 2.0.5 and PHP 5.3.2.
277 display_errors = On
311 html_errors = On
319 docref_root = "/ROOT/phpmanual/php-chunked-xhtml/"
320 docref_ext = .html
323 error_prepend_string = "<font color=ff0000>"
326 error_append_string = "</font>"

The final thing to do is save the file and then restart your servers. To test it create a basic php file like the one below.

<?php
include ('file.php');
?>

Launch it and you should see this

Warning: include(file.php) [function.include.html]: failed to open stream: No such file or directory in /Users/zoooj/Sites/root/mailout.php on line 2  
Warning: include() [function.include.html]: Failed opening 'file.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5.3/lib/php') in /Users/zoooj/Sites/root/mailout.php on line 2

Click on the links (in blue) and you’ll be taken to your local copy of the PHP Manual. These links point to my local copy so probably won’t work for you, unless you’ve set it up and used the same location as I have. Simply by regularly updating the manual you can now work offline whenever you want on your php development.

Create MySQL Backup

There are a number of ways to backup a MySQL database. For my local environment I like a quick way to take a backup before trying something new. Rather than go through the cumbersome process of logging into Terminal, navigating to the MAMP /bin directory and then entering a very long command, which I would easily forget, it’s simpler to create a shell script and then invoke it as an Application by using AppleScript.

First, create your shell script by opening a text editor, eg TextWrangler (and not an RTF editor), and type:

#!/bin/bash

On the next line type in the commands you would normally do in Terminal. In my case, I wanted to navigate to the MAMP /bin where mysqldump lives. Then, I wanted to use this to dump a sql file of a specific database within my sites directory.

cd /Applications/MAMP/Library/bin/
./mysqldump -a -uroot -pPASSWORD mydb1 > ../../../../Users/[username]/Sites/Backups/db1.sql;

Finally, close it with

exit

You then save this in a logical place (ie somewhere you can find it!), in my case /Users/[username]/Sites/Backups/scripts/. Next go to Application > Utilities and launch AppeScript Editor. Type the following into the edit pane.

do shell script "/Users/[username]/Sites/Backups/scripts/backup_nsdaukcom_263323_db1.sh"

Save this to either Applications or a sub-directory within Applications. When you change the File Format to Applications before saving.

Once done, all you need to do to take a backup is double-click the new application you’ve created and your previous backup is overwritten with a new one.

Remove System Mail

The other day I was in Terminal when I noticed for the first time it said You’ve got mail. at the top. Knowing I didn’t have any new mail I typed mail to see a whole load of system mail from previous web development work.  I’m no command line expert so I checked on macrumors.com and quickly found out what to do. Here’s the original post.

Go to the directory (=folder) where the system level email files for all users are stored, and list them:

cd /private/var/mail/; ls -l

Display the email(s) for the user which you fill into <username>. Either use your username (without the angle brackets) or use the character * (asterisk) if you want all emails from users listed:

cat <username> | less

Finally erase your mail file, in case you do not need it anymore.

sudo rm /private/var/mail/<username>

Obviously, seeing as you’re deleting mail from your mac make sure you’re certain before doing so. Also, the sudo rm command has no safety net. Once something’s gone it’s gone so if you’re unsure, don’t do it.

Resetting Root Password in MAMP

I struggled for a while to do this as I expected MAMP to automatically update the root password after I’d changed it in the mysql.user table. To be clear, it does not. And so, here’s a brief guide to sorting out you MAMP woes.

First, connect to mysql using Terminal. MAMP is automatically set to use root as the user account to connect to mysql. Funnily enough, root is also the password!

/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot
You’ll be logged into mysql and will see the following.
Last login: Wed Dec 28 14:48:04 on ttys001
ZoooJs-MacBook-Pro:~ zoooj$ /Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 38
Server version: 5.1.44 Source distribution

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
 The next thing to do is reset your password. Type the following replacing your-new-password with your new password. You should see the Query OK message.
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('your-new-password');
Query OK, 0 rows affected (0.00 sec)
Once that’s done you need to edit a number of files in the /Applications/MAMP/ directory. I still can’t quite believe that you have to do this in so many places. You’d think they would have a single file that has the master password set. Hey ho, maybe not.
So, find and edit these files using a plain text editor, not TextEdit, Word, OpenOffice, etc. Use TextWrangler or another decent Mac IDE. TextWrangler is free. You’ll need to find the line that has -proot and change it to read -pyour-new-password. Note that there is no space between -p (stands for password) and the password itself.

/Applications/MAMP/bin/phpMyAdmin/config.inc.php
/Applications/MAMP/bin/checkMysql.sh
/Applications/MAMP/bin/quickCheckMysqlUpgrade.sh
/Applications/MAMP/bin/repairMysql.sh
/Applications/MAMP/bin/stopMysql.sh
/Applications/MAMP/bin/upgradeMysql.sh
/Applications/MAMP/bin/MAMP/index.php

Restart MAMP and all should be well.

Need a Website? Read this.

Meeting client expectations is the key to running a successful web development business. How those expectations are set is therefore something the web developer has to consider very carefully. Set them too high and you risk annoying the client. Set them too low and you won’t get the business.

A number of freelancers on freelancers.net have compared quoting for a project akin to buying a car. One in particular wrote:

1) do you want a Ferrari
2) does it need to be 4×4
3) do you want diesel or petrol
4) do you want a maintenance plan
5) do you want extras
6) do you want free MOT
7) do you want continuous improvements (this would equate to a lease hire
where you replace the car for the newer model at the end of each year)
8) do you want free upgrades (top of the range breaks and accessories each time the car is serviced) – £5000 upfront,

Are you a Trader or are you Private Seller or are you an Independent Dealer
or are you an Authorised Dealer.

£125 – £750 per day AND full Professional days. Quote by day and if it
takes you 10 more days than quoted, you can’t ask for extra money. so don’t promise more than you can deliver and agree a continous review to make sure you’re on track.

You need to charge for project initiation (establishing your Business,
Functional and Non-Functional Requirements) this isn’t included in the
Design, Develop and Deploy phases.

Or do you want to go to a trader and buy a car from him in the ASDA parking lot and not know where he comes from, hope the the HPI check is legitimate and hope that he hasn’t thrown saw dust in the gear box as well as 1 or 2 banana skins. £10000 and make sure your buyer can’t find you or review your work and make sure you can’t build a reputation to sell so the same buyer again.

Getting the quote right means treating the project in its entirety. There’s one thing I don’t like about this comparison, though, and that’s likening web developers to car dealers. In my experience, and I use those words carefully, web developers are somewhat more honest. I’m sure there are bad ones around – I’ve obviously been fortunate to meet the honest ones. The same cannot be said for car dealers!!