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.

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.

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.

Transferring files between host servers

If you’ve ever moved websites between hosts or wanted to set up a development version of a client site then you’ll have copied files from one and made them available to the other. The basic method for doing this is to ftp into the source server, download the files to your computer, ftp to the new server and upload the files there. The problem with this is that it takes ages to do when you’ve got large websites.

Despite having been doing web development for a number of years I’ve never thought about this before as I would always follow this process. However, given that I run a number of Magento sites for clients now and that there are a lot of pressure on my time I need a quick way to do this. So, after about 20 minutes research I realised there is a really easy way.

First on the source system compress the file into a .zip or .tar.gz file. Most hosts provide tools to do this. I know CPanel and DirectAdmin do. Next, download this. As long as you’ve a fast broadband connection this won’t take long. Next upload to the new host server. This took about 45 minutes for me. However, I set it up and just left it running. Last, after checking I have shell access with my user on the new host server, I use Putty to do a SSH session and then just run the following command: tar -zxvf yourfile.tar.gz. This unzips everything into the folder you leave the file.

All done in under an hour with about 10 minutes of my actual time.

Installing Windows 7 on a Mac with Snow Leopard and Boot Camp

After a few months of waiting my copy of Windows 7 finally arrived in its shiny new box with the rounded corner yesterday morning. Since then it’s been sitting on the table waiting for me to get round to installing it onto the Mac Book Pro, which has been quivering in the corner for some time now. Last night was the backup. I’ve opted to use an ethernet connection from my MBP to my Powerbook, which serves as my backup destination these days.

With that done and my data safe it’s time for my MBP to get used to sharing.

10:20pm
I find Boot Camp Assistant, crank it up and partition my hard drive giving a healthy 48GB. This is so much easier than the toil I went through partitioning my PC when I installed XP. Thank you Apple.

10:22pm
It takes a little time to create the partition. Once done, I insert the Windows 7 CD and click Start installation.

10:23pm
My MBP reboots off the CD and I get to select my language options. After selecting them I choose the partition created by bootcamp – the one with BOOTCAMP in the title – and click Format. I was hoping to be able to select FAT32 so that I could share files with the MacHD but W7 doesn’t give you the option and automatically formats it as NTFS. Looks like VMWare Fusion is needed at some point.

10.25pm
After accepting the licence we’re away and Windows 7 starts its installation with the Install Windows dialog. First it copies the Windows files, then expands them before installing features and updates. Time for a cuppa.

10:33pm
The first of the system reboots happens. A message appears saying Starting windows services before the Install Windows dialog appears again.

10:37pm
The screen flckers black and then reappears again. This is presumably some kind of refresh that has to happen. The installation is now two-thirds complete with the green bar gradually extending to the right across the bottom of the screen.

10:39pm
A message appears saying setup will continue after the computer restarts. Predictably, the computer restarts. Ah! The chimes – some semblance of the Mac is still there. I can’t remember who produced the Windows’ notes but it doesn’t compare. I seem to remember it was a famous composer who had to do it and supplied over 100 versions to Microsoft back in the ’90s. Anyway, onwards …

10:40pm
Okay, things are happening. It’s setting up Windows for first use and checking video performance. And a (low res) dialog to enter my username and computer name. Remember to use a mouse with your MBP at this point as it’s far easier to navigate the screen due to the trackpad drivers not being installed yet.

10:42pm
It’s time to set up the password. Unlike Macs you’re forced to do this. It’s no bad thing but it would be nice to be trusted to make this kind of decision yourself. After all, I did pay good money for it. Moving on, I get the product key message next. After hunting around I find it on the inside of the plastic container W7 came in. It takes two attempts to get it right as normal with Windows product keys but then it’s off authenticating its authenticity before coming back with three options:

  • Use recommended settings
  • Install important updates
  • Ask me later

I’m tempted to take the Ask me later until I remember this is Windows so I plump for the max option and click Use recommended settings. Better safe than sorry. The time zone window appears so I leave that as it is. It’s automatically worked out where I am.

10:47pm
Next up is the wireless network. Mine appears so I click that and while performing living room gymnastics I copy the key on the underside of my router into the Security Key field. Getting it right first time is a relief as my back is starting to seize up. I then get three choices on the next page:

  • Home network
  • Work network
  • Public network

Home network it is …

… it’s thinking and connecting …

… and now finalising settings …

… and done.

10:49pm
The welcome message appears and now my desktop is being prepared for me. How sweet of it to let me know. Whoah! A huge MS icon in the middle of my screen appears like a hive of giant bees just smelled the honey I stole from them earlier today. Must sort that out soon before they get to close.

What to do next though – that’s the question. Referring to my SimpleHelp.net guide I realise I’m on a slightly different path to theirs.

10:51pm
Okay, time to use my intuition so I do a Windows Update and see if that sorts out the drivers. Start > Programs > Windows Update and I’m in a new place where it tells me there are 8 important updates. I add the IE8 one mysteriously not selected and go for the Install button. Yes, I accept the Windows Malicious Software tool. And download begins. What’s on TV … [reaches for the remote]

10:56pm
Updates done, time to restart. Chimes again – ah … and we’re off again. 20 seconds later W7 starts up and begins confuguring the updates.

10:58pm
Time to log in for the first time. And I’m in again. What next? Time to take a look at the resolution I think as it’s driving me mad – those bees are getting too damn close! Yes, right-click is still there with a direct link to screen resolution. I up it to 1440 x 900 and the bees retire into the distance.

11:00pm
Back to the SimpleHelp.net guide where in step 17 it mentions what to do if there are no sounds, something I’d been blissfully unaware of. So the next thing to do (after disabling wireless due to not having any security on the MBP for W7 at the moment) is to replace the W7 CD with my Snow Leopard one. But the eject button isn’t working yet so into Windows Explorer I go and right-click the W7 CD to eject it. This is why you need to use a mouse. In goes the SL CD.

11:04pm
The new style autoplay dialog pops up so I get to click a Run setup.exe rather than search for it in the folder. Yes, I do want to allow the following program to make changes tho this computer seeing as I put the CD into the computer in the first place – trust me, please Windows. I know what I’m doing. Kind of.

11:06pm
Here’s Boot Camp. I accept the license agreement and then click Install the Apple software update for windows. More waiting as this is installed.

While that’s going on I get to watch a bit of Nick ‘BNP’ Griffin in the Question Time bearpit. Hmm. Nope, I don’t think I’ll be voting for him in the next general election. Liberal Democrat all the way, me. Don’t knock them, they’re the only party to actually understand the current financial crisis. Admittedly, their leader looks like he’s just left school but I won’t hold that against him!

How’s the installation doing? Installing Sigmatel Audio … never heard of that one. Now on realtek Audio. Presumably, we’re nearly there as it seems to be alphabetical. Ah, no, cirrus radio is next. Oh well. Trackpad drivers – hooray! That’s going to make life easier though I imagine it won’t have the three and four finger gestures available. And no pinching either – boo!

11:14pm
It’s done and Boot Camp is as well. I click Finish and then Restart. This time when I hold the option key down during the restart I get to see my two partitions. I can go to eiether Mac OS X or W7. Cool.

And that’s in. All in all it took 55 minutes and was pretty painless. The Windows update and Snow Leopard driver update were the main bits that might throw you but the rest was straightforward. Now for the new Aero themes, sounds, loading software, sorting out the trackpad (see the bootcamp control panel – bottom right icon) … oh and to disable the automatic wireless connection as I need some antivirus protection. Norton dual looks good though it isn’t ready yet.

This is purely my experience and while you’re welcome to follow the same road I took I should just out that I’m not responsible for any mishaps you meet on the way though am more than happy to help out if you’re struggling. Be warned though, I may well say ‘Er … don’t know!’ Before doing anything like this always make sure you’ve got a backup and have the OS disks you need and can connect to the internet for the windows updates. Also, check to see that your system meets the requirements specified by the software you’re installing.

Good luck! I’m off to play with software I haven’t used for a year or two …