Wulf's Webden

The Webden on WordPress

Up and Down

It is possible that you might have hit a blank wall when trying to visit my blog yesterday. I got an alert from my hosting service (1&1) that I needed to upgrade from PHP 5.2 before November. Upgrading is just a case of logging into their control panel and clicking on a button but unfortunately the result was that my blog stopped working. I had a look round, couldn’t track down any error logs to give me a clue and so registed a request for support with the company. And then I fiddled some more…

A series of web searches revealed that this isn’t the first time people have had issues with PHP upgrades and WordPress on 1&1. I tried some of the solutions, like re-initialising my password on the underlying database, but to no avail before I found a site that suggested looking in php.ini for problems. I am used to having a central php.ini file on the host web server but 1&1 doesn’t give this degree of control; they put one in the root of the WordPress install which overrides items in the central one. Commenting out all the entries by putting # at the start of each line allowed the site to work again and then removing the hashes one by one allowed me to figure out that the problem was:

magic_quotes_gpc = on;

This was a feature of PHP that has long been regarded as suspect and was deprecated in 5.3; that’s why trying to add a later version of PHP didn’t work.

I thought I had it figured out until I tried adding a new post, at which point I realised anything to do with site admin was also broken. Further investigation revealed the same php.ini file scattered across lots of subdirectories (possibly all of them). I have my WordPress files protected by Git, an amazing tool for keeping track of changes, so I whisked up some commandline-fu to avoid having to manually edit each and every one.

find . -name php.ini -exec sed -i.bak 's/magic_quotes_gpc = on;//' {} \;
find . -name php.ini -exec sed -i '/^$/d' {} \;

The find command is told to locate all files called php.ini in or below the current directory and hand them onto sed, a “stream editor”. The first line creates a backup copy and then replaces the references to magic_quotes_gpc. That leaves blank lines in the files but, rather than use a much more complicated expression to make sed work across multiple lines, I just run find again (no need to create a backup this time – that is already in place) and this time use sed to delete blank lines (ie. ones where the start, or ^, is right next to the $ denoting the end of the line). Then, after checking that the results are what I intended I removed all the php.ini.bak backup files. I could have relied on Git if I’d needed a rollback but two safety nets are better than one if all it takes is a few more characters of typing:

find . -name php.ini.bak -exec rm -f {} \;

Sorted, I think! I’ve certainly been able to create a post and browse round my dashboard. I’ll wait a few days before upgrading the other WordPress site I run and then perhaps a few more before I push this site from the smallest step up I could take from PHP 5.2 to the recommended 5.5.

Meanwhile, it will be interesting to see what 1&1 support say when they manage to get back to me!

  • Phil Alcock

    I have my email with 1&1 and haven’t been impressed with their support – albeit only with one problem which I eventually fixed myself, Interested to see how you get on.

    • basswulf

      They have replied, about 24 hours after my original message was sent although only to ask for further information and perhaps a screenshot. I’m surprised that they don’t have further information on things to watch for in the upgrade and glad that I’m geek enough to have apparently fixed it for myself.