Running WordPress on MobileMe / dot Mac pt. deux

January 25th, 2009

Previously, I wrote about getting WordPress working on MobileMe. Thanks for all who wished me luck, it must have worked!

Along with luck, here are the other ingredients I used to get my WordPress blog published on MobileMe.

I first setup Mac and Windows portable web server environments to run my WordPress install locally. You could also use another web server, such as free hosting (I have 2 recommendations of non-ad supported free hosting providers). If you have already paid for other web hosting, I guess you’d be better to stick with that unless you also have a MobileMe / .Mac account with free hosting, in which case this method could save you some money.

After installing WordPress, I changed the options to display my permalinks as blog_title.html, directly after the root of my blog. eg localhost/wp/blog_title.html.

I am just using the default WordPress theme at the moment, and I tweaked a few settings in there to resolve path problems. WordPress by default uses absolute paths in the html it outputs. For example, I changed the CSS link in the header.php file to point it’s relative path as opposed to using WordPress’s tag for the same purpose.

The hardest links to modify were the links to the URLs of each individual post. Where WordPress by default uses the the_permalink(), this hardcodes the absolute path into the link. If I didnt change that before uploading, it would try to link to http://localhost/wp/blog_title.html for any user who views the page. This would create all sorts of security or other errors in the person’s browser. To get around this, I used the get_permalink tag which just gets the absolute URL as a variable without displaying it on screen. This was still containing the leading http://localhost/blahblah, so I passed it to PHP’s strlen function and stripped the first 16 characters which provided me with the relative link to my posts. Nifty, eh!

I modified a few more chunks of code in the index.php, header.php, footer.php and single.php WordPress default theme pagesĀ  to remove category, page, comment and feed links which would otherwise have resulted in path errors.

Now that my local WordPress site was ready link-wise, I had to ouput the pages as real html files. I used a different tool on Windows and Mac. The Mac was easy, using the SiteSucker program, I simply typed in my local WordPress address and it captured the whole site staticly starting with an index.html for the WordPress homepage. I then uploaded the captued files to my iDisk underĀ  Web > Sites > wp. Now, you are seeing the results live on this site! (note, I have the www.leonstafford.com domain redirected to my MobileMe hosting, but you can see the regular MobileMe link here: http://web.me.com/leon.stafford/wp/).

For the same thing on Windows, I’ve been playing with the port of wget for Windows. I haven’t looked into it enough to find out how to capture the whole site the way I want it, but will have a another look next week at work.

That’s the gist of how I got WordPress “running” on my MobileMe hosting, for more details, I also installed a free comments bit of JavaScript at the bottom of each post you can e-mail me, so feel free to ask away or share your ideas.