WordPress in Ubuntu

A Local WordPress Install and the Windows Refugee Experience: chownED by Ubuntu!

Ubuntu: sudo /what/the/hell?This isn’t a tutorial per se, unlike these posts on setting up a local WordPress installation under Windows using WampServer. There are several comprehensive tutorials or sets of instructions out there on the Web about setting up LAMP – Linux-Apache-MySQL-PHP – along with WordPress on Ubuntu.

Furthermore, while I can’t say I’m a Linux noobert, per se, I would still consider myself a de facto noob. I find it easier to tinker under the hood in Windows, simply because I’ve been doing it for so long. I’ve only been using Ubuntu for the past year or so, however; prior to that the last time I saw anything resembling a Unix environment was 1997. Back then I installed FreeBSD alongside Windows 95, because I got tired of the latter’s constant crashing.

On the other hand, if I could successfully get FreeBSD and Windows 95 both working on a dual-boot configuration in 1997, I feel like there’s not much I can’t do. Where I lack in intelligence I compensate with considerable intuition and implacable, obdurate will; I’m stubborn to a fault – a good trait when it comes to tinkering with computer operating systems.

And it’s especially good coming to Linux from Windows. As my best computer nerd friend – he doesn’t bother using package managers; he does everything from the terminal off the top of his head – Linux is a “completely opt-in OS; Windows is the exact opposite.” I’ll get to what he means in a minute, Windows users. Just remember:

Pigheadedness prevails.

LAMP: Linux, Apache, MySQL and PHP (or Perl, or Python, etc.). And how 'bout my mad Photoshop skills? Meh. Anyway, Ubuntu’s own documentation on installing LAMP and WordPress, as well as its specific docs on installing Apache will likely get you up and running without too much problem, even if you’re a complete Linux noob. You don’t have to, but I would suggest reading the Apache docs too; particularly if you are security minded; the Apache doc will show you how to edit the ports.conf file so your Apache server is only accessible by your local machine — it will only dance with itself on Port 80, rather than looking all over the world for every type of girl in any ole’ port.

But I digress. These two docs are fairly comprehensive without telling you a bunch of stuff you don’t really need to know or care about (unlike me; I’m often wont to digress). Then there is Ubuntu Geek’s tutorial on WordPress and Ubuntu 10.4 specifically.

And if you are completely scared of a do-it-yourself install, then you probably shouldn’t be messing around with Linux. I think it’s safe to assume if you’re looking for information on how to run a local Web server on Ubuntu so you can, in turn, run a local WordPress installation for development purposes, you must be reasonably tech savvy.

But then, on the other hand, there are more and more laptops/nettops/netbooks/tablets/what-have-you gizmos running Ubuntu or some other variation of Linux these days, and consequently more and more WinD’oh!s users are finding it necessary to get familiar with it. Plus, I would guess there are probably some folks out there that just don’t want to shell out for a new Windows 7 system disk when Ubuntu is free and relatively easy (times are tough, after all).

Alert: stuff you may not need to know/care about: But then Windows 7 is actually pretty stable and much more secure than previous incarnations, and rather easy on old hardware, particularly if you turn off the Aero bells and whistles. I’ve seen it installed on a decade-old desktop with a whopping 512 megabytes of memory, a 10 gig hard drive, and a creaky-old Pentium 4 CPU, and it ran really well, barely taxing this ancient box; I wouldn’t have believed it if I hadn’t seen it myself. It even booted a lot quicker than my Win XP laptop with its 3 gigs of memory, dual-core Intel CPU and 100 gig drive – and I had my XP boot pared down to the bare essentials. So there you go.

But generally speaking, Ubuntu is lighter on the hardware than Windows – even Windows 7 – and considerably more secure (although Vista and Win 7 go a long way towards addressing Windows’ lingering security issues). Plus, did I mention it’s free? And it’s open source, and it’s been around a long time now, so there is plenty of support, third party apps and so forth out there.

Close Windows, Turn on the LAMP, Ubuntu and WordPress

So I thought I might just point out a few things for Windows users who have seen the Linux light and who also happen to work with WordPress and want to get a local installation of it up and running for Web site development purposes. Of course this reflects my own experience, and what what follows is what works for me on my hardware; your mileage may vary depending on your particular version of software and hardware.

First off – and this is one of those tangents you may not care about, particularly if you came here from Teh Google — one of the odd things for Windows converts in a Unix/Linux environment is its concept of users, rights and security. As my previously-referenced computer nerd pal puts it, “You have to tell Linux exactly what to do; it’s never going to assume anything.”

Windows User Account Control: "Your user can't help you now, little program!"Up until Vista came along, if you had a login credential on a Windows machine – a user name and password – you could easily wreak havoc at will (and often inadvertently) in Windows. You were the God of the Keyboard; you could pretty much do whatever you wanted to (and so could anyone else). With Vista came the dreaded UAC, “user account control,” however, and notifications that you had to run various and sundry programs as administrator in order to do what you were trying to do.

I remember the first time I encountered this on a Vista box and thinking “WTF is this now? Did Microsoft steal a page from Apple’s playbook and just slap a fancy GUI over Unix and call it the new Windows OS? Or did they hire the Master Control Program from Tron?” Not quite either, of course, but still it reminds one of Unix.

The idea behind this is security; ostensibly if someone were able to remotely hack into your machine with bogus credentials (or were able to purloin your actual user name and password), the damage they could do would be limited, because they couldn’t run programs as an admin. They could not aspire to be the Keyboard God, but rather a minor, malicious cherubim or seraphim at best.

sudo /phil/collins/sussudio.conf ... surely I'm not the first to make this pun.This may have been novel for Windows, but old hat for Unix, Linux and their various derivatives, of course. When you log into Ubuntu you’re a user and as such you don’t have admin or “root” privileges; you’re low man on the OS user totem pole. You can of course temporarily elevate yourself to root – using the sudo or su command – but not the Sussudio command — in conjunction with some other command in a terminal (think DOS window in Windows), for example.

Even when it comes to files and folders, you can encounter this issue; files and folders are owned by certain users and other users and groups of users are assigned various rights accordingly – a file’s owner has read and write permission, but another user may only have read permission, or perhaps not even that.

There’s mountains of more info on this out on the Intertubes; Google and Yahoo are your friends. However I would suggest this Wikipedia entry on file system permissions if this is a completely new concept for you. It’s a pretty good yet brief overview of permissions and rights for various operating systems, and details rights and permissions used in Unix – and consequently Linux – environments and their notations. You’ll be down with the 411 on the 755 in no time at all, not to mention the -rwxr-xr-x.

On the other hand, if you’re a reasonably knowledgeable Windows user who can tinker underneath Window’s hood without breaking it, then file system permissions in Linux are seemingly a pain in the ass sometimes – you’ll miss having the god-like powers that Windows entrusted with you (or at least used to). Sometimes it does feels like you’re Flynn and you have to outwit the MCP. On the other hand, it’s why Unix/Linux is so much more secure – it’s much more difficult to hack into remotely. Plus it’s difficult for your non-techie friends and family to accidentally eff up.

Um, Yeah, LAMP? WordPress? Don’t Worry, I’m Getting to the Point

This issue of users, rights, and ownership is important to keep in mind when setting up your WordPress installation in Ubuntu. If WordPress folders – let’s call them directories since this isn’t Windows – subdirectories and files don’t have the correct ownership, rights and privileges assigned to them, it won’t work, or at least not well. You may be able to navigate to your local site, but WordPress won’t be able to create new posts/pages. Or it may be able to do this, but when you try and navigate to that new page or post, you’ll get the 404-not-found error. Furthermore, you won’t be able to update WordPress automatically, install plugins, etc.

So, with this in mind, in the section in the Ubuntu installation instructions where it says this:

For automatic updates to occur, the folder and all its files and subfolders must be owned by www-data:

chown -R www-data /usr/share/wordpress


The “chown” command is shorthand for “change owner” and the -R means the change is recursive; it applies to all subdirectories and files. Who is this www-data user? It’s a system user account that your Apache Web server creates to do its thing. And since WordPress relies on Apache to do its thing, www-data needs ownership.

Apache’s Running, WordPress is Installed and Using the MySQL Database, but I Got Nothin’

I learned about www-data the hard way. I had installed WordPress a number of times on Windows, in both XP and Windows 7, so I didn’t really think there would be much to getting it up and running on Linux. I installed Apache, MySQL and PHP individually via the Synaptic Package Manger in Ubuntu on my laptop and verified it was all running correctly. So far, so good. Went to phpMyAdmin, set up my databases for the WordPress sites I’m currently working on, downloaded the WordPress files and installed them in the various directories for each site, and proceeded apace – pretty much the same process in Windows.

Only I couldn’t actually see or navigate to any page locally beyond each site’s index.php file. I could create a new page in WordPress, and it showed up in the database, but I couldn’t see it when I tried to navigate to it in the browser. I solved this by giving the whole world access to all of my WordPress directories and files – 777 – but then I noticed I still couldn’t update automatically inside WordPress. Files would download, unpack, and then the install would fail.

A little more research revealed my issue with www-data ownership. Moral of the story? When all else fails, read the effing manual.

So now WordPress works fine on my local machine under Ubuntu, and I didn’t have to invoke Keyboard God mode. Huzzah. Beyond this, installing LAMP and WordPress on Ubuntu isn’t that different than it is in Windows.

Update: Don’t Assume Ubuntu Works Like Windows

So I just learned something else about this directory ownership issue. I was setting up a new site that will use WordPress on my Ubuntu box. The theme I installed for this site comes with some dummy data – pages, posts and comments – to populate the site, allowing you to experiment with its appearance.

Everything was fine until I went to import this data in WordPress via an xml file. WordPress kept asking for ftp login credentials, which it shouldn’t have to, since www-data has ownership of this new subdirectory I made in my www folder – or does it? After some hair-pulling and cursing, I looked and nope, ownership and permissions were assigned to my user account.

WTF chownED by Ubuntu’s MCP. Again.

I'm Linux! It's funny because it's true. I copped this from Whil Wheaton's blog. Dunno where he copped it from though.See, I’m a Windows refugee — well, not really, since I run Win 7 on my desktop box, and have  no compelling reason to switch. Although the next time I order something form NewEgg or Amazon, I’ll probably order another hard drive and slap Ubuntu or Kubuntu on it. I guess you could say bi-curiOS.

Anyway, since I assigned ownership to the parent directory to www-data and made that ownership recursive, I assumed – and we all know what happens then – that any new subdirectories created in that folder would automatically inherit www-data ownership and the characteristics of the existing parent directory. In Windows, of course, you can set the characteristics of a file folder to be recursive, and any subfolders you add after that will assume – heh – those same characteristics – although there’s no ownership, per se – not in the sense that there is in Unix/Linux.

As the aformentioned friend noted, Linux never assumes; you need to tell it if you want ownership to differ from the user account used to create it – which in retrospect makes sense. But like I said, I’m a veteran Windows tinkerer, and I’m used to being the Keyboard God, and not having to outwit the MCP.

But if you’re reading this, then I hope that my frustration is your gain.

ZOMG! WordPress running locally on Ubuntu.

One thought on “WordPress in Ubuntu”

Leave a Reply

Your email address will not be published. Required fields are marked *