Tuesday, December 13, 2005

Basics of Using Categories

Categories are important. They're really important. You need them - but how the hell do you use them?

What are categories? Since we're talking about CMSs and blog software, your categories are just a group of words that you pre-defined, and that you choose to apply to each post or page. (Don't bother looking for them here - one of the big failings of Blogger is that it doesn't support categories.)

That description makes them sound like the sort of organisation tool that would only be used by people who kept their colouring pencils in strict order of the spectrum. But on a website, categories have an unexpected power.

Take a look at localization-news.com. On this website, I created around ten categories such as "software localization", "localization tools" etc. Each day I wrote a new post, and on the writing-a-post page, selected one or more appropriate categories from a menu. You can see my chosen categories at the bottom-right corner of each post, for example ( categories: software | tools ).

Now if you, the reader, click on one of those category labels, you'll be brought to a page listing all posts in that category. Presumably you clicked "software localization" because you were interested in that topic - so now you can instantly see everything I've written on the subject, without skipping through all my posts on other topics.

The benefit to the reader is that they get to find the info they are interested in, quickly and easily. One benefit to the website publisher might be to offer more directed advertising on that page (e.g. Adsense will tend to offer more subject-specific adverts).

Of course not every reader is familiar with clicking those little tags at the end of each post. I decided to put links to those category pages, in the form of a menu at the top of the webpage. This was trivial to do. But the result is something that looks less like a one-page scrolling blog, and more like a fully organized and professional website.

As it happens, this position has additional benefits for SEO (Search Engine Optimization). But that's another story.

Monday, December 05, 2005

Phuket-live.com - another Drupal website

Okay, so 3 months on, I'm back playing at making a profitable website. This latest attempt came about because I booked a couple of domain names about Phuket, for someone who didn't need them at all. Hey, I spent a few dollars on those domain names, let's see if I can win back my $8.95 paid to Godaddy.

So a quick check on Google confirms the obvious; there are a million and one professional websites on the subject of Phuket. Doesn't sound too good. On the other hand, there are 4 million tourists ...
(That's actually the year before last - last year we had the tsunami, which apart from the traigc loss of life, wasn't great for anyone with a job in the tourist industry - if you're wondering whether it's safe to take your tropical beach holiday in Phuket, please do, we need your cash!)

So Phuket-live.com is up and running, sort of, and currently has around 10 posts covering the major beaches. Each post will be about a destination or activity that visitors are likely to be interested in; if/when I run out of covering those, then I'll switch to keep up with local news on the island.

Monday, August 29, 2005

Setting up a Drupal site, day two - Cron jobs

Aaaaaargh! Cron jobs! They are so basic, and I spent most of a day getting one Cron job to run. What the hell is a cron job, anyway? It's an alarm clock with all the ease of use of an 80's VCR timer. "Cron" as in chronograph (with bad spelling). A Cron job says stuff like "do this every 5 minutes" or "run this program on Saturday afternoon, around about teatime." Basic stuff, right? You might already use Windows Scheduler or similar software to do these things on your own computer.

But for our purposes, we want to do things on our website, and the best way to do that is by running a scheduler on the webserver. That usually means setting up something in cPanel *, which will continue to run on your hosting company's computer after you've switched off and gone to sleep, and will keep running when your house is flattened in a flood, or you take a few week's holiday. Cron jobs, when they work, are the first step towards making your website autonomous. One obvious but boring use is to do daily backups. Another use, which is a little bit more interesting, is running your own News Aggregator service on your webserver. In practice that means that your website can display the latest news headlines from, say, Yahoo Asia, and can check for updates every 30 minutes so it will always have something new to show to visitors. Drupal has a News Aggregator built in

CPanel users set up Cron jobs from the main screen of CPanel, by scrolling down to the icon named, er, Cron jobs. From there you are offered two options, Standard or Advanced. Frankly, this is a bit of a letdown from cPanel, because they are both as clear as mud unless you are already familiar with the original Linux text version. But go to the Standard anyway. Enter an email address - hint, set up a new mail folder and rule in your mail reader to hold these messages, as you tend to get a lot of them while troubleshooting. Now look inside the box "Entry 1". There are multiple selection menus, and a single line "Command to run:". The selection menus are your timers, and they are all running. If you click the top line of each one, you would be saying "I want you to do this thing every minute of every hour, of every day, on all days of the week, in every month."

Normal people would just say "do it once a minute". I suppose programmers don't like ambiguity; there's no chance to say "do it once a minute, for a while".

So the idea is, you choose options from this menu that combined together, say how frequently your task will happen. Remember, this isn't really a video timer, that was just my metaphor; you can't program a task to happen only once. Once a year, minimum. To do something on every Feb 21st, 5:19pm, you set Minutes to "19", Hours to "17 = 5pm", Days to "21", leave Weekdays at "Every day", and set Months to "February".

Just to clarify some of those selections:
- the Minutes menu lets you choose a frequency, but the second part of the list is the actual minute. If you knew that Yahoo Asia updates its own news headlines exactly on the hour (e.g. 9:00pm), you might want to update yours at 3 minutes past the hour (e.g. 9:03pm) to ensure you don't miss them. So you would select the number 3.
- Days is of course the Day of the month, e.g. 1st of every month would be 1.
- Weekdays menu is strangely titled. Apparently Unix programmers don't know what weekends are (that explains a lot). Anyway, yes, you can choose weekend days as well as weekday.
- Weekdays vs Days. Choose the one that you want to define, and leave the other at "every day". Choosing "Sunday" and "10" will mean "do it on all days that are Sunday, as well as all days that are the 10th.
- On all menus, hold down the CTRL key to select multiple choices (e.g. 9:03, 9:17, 9:31 and 9:46).

Now for the difficult part.... what task is it going to do?

Well, first of all, the answer is going in that single line textbox above the menus. So you only have the chance to tell it one thing. The idea is, you enter your line there, set it to run every 5 minutes, click Save, and wait to see if it works. Once it's working, you can go back and change the timing to something sensible. So what line do you enter to make Drupal's News Aggregator do its stuff?

On the Drupal forum, they talk about Linux commands such as Wget and Curl. Now this is fine for people running their own private webserver, but most of us don't, and at this point you'll probably become familiar with an emailed error message telling you that you don't have permission to do that. (You can comfort yourself with the fact that your web host is not completely careless about security.)

Keep trying.

Drupal has grouped all the necessary tasks into a single file, so that if you just look at that file in your browser, that will trigger those things to happen. Clever. However you don't want to look at a blank page every 30 minutes for the rest of your life. Apparently it's sometimes possible to just enter the address of that page, e.g. "mywebsite.com/cron.php". More likely, you will again be told you don't have permission.

In Drupal's "scripts" folder there are two files called cron-lynx.sh and cron-curl.sh. These scripts can be "executed" directly by your webserver. If you look at them in a text editor, they are just one line; but you can't run that line yourself using Cron; you have to run the script! Confusing? Yes. But I gather it's necessary for security reasons.

One of these is the one you want. Try both. Chances are, you'll be told you don't have permission.

Have you put the correct "path" in front of the script name, on that line in Cron? For a typical cPanel Drupal admin, the correct version looks like this:
/home/username/public_html/scripts/cron-curl.sh
Username is your cPanel login. Yes, you don't normally see the first few folders in your browser, but they are there, hidden, on your webserver.

By this stage, I was tearing my hair out. If I still smoked, I would have gone through several packs at this point. For me, the final answer was this:

In your ftp or cPanel File Manager, select cron-lynx.sh and cron-curl.sh, and change their permissions, to 755. Don't know what that means? The short version is, it says who can or can't use them. In some ftp software, you set permissions by right-clicking on the file. In File Manager, you select the file then click Change Permissions on the right.

I've tried to cover all the mistakes I made today before I got Cron working for the first time. In the end there was nothing particularly difficult, except knowing the correct line, and ignoring all the irrelevant advice about Wget, etc. But it really did take me most of a day to it working. If you've had a similar battle with Cron, and got caught out by something else, please drop a note in the Comments so that others have a chance to avoid it.

* The Cron program is for Unix or Linux webservers only. Remember, your PC is probably Windows and your webserver is probably Linux. Sometimes there are (less standard) alternatives for Windows servers, but I can't help you there.

 Previously:    Basics of Using Categories    Phuket-live.com - another Drupal website    Setting up a Drupal site, day two - Cron jobs    Setting up a Drupal site, day one    Drupal vs Xoops, a personal battle.    Colour-matched Google Adsense    Finding a good web host    Hosting your own website    Getting your domain name    The Story So Far   

Rate Me on BlogHop.com!
the best pretty good okay pretty bad the worst help?

This page is powered by Blogger. Isn't yours?