Archive for the ‘eTeanga’ category

Creating automatic PDFs with PHP, MySQL

January 18th, 2010

My collaborative Irish dictionary, Irishionary.com, creates a nightly PDF version of the dictionary. A cron job calls a PHP script that generates the PDF. There are examples of great looking PDF publications and mine isn’t one of them ;) All the same, it’s not that hard to create your own PDF files though PHP scripts pulling information from your database if you wish. If you figure out how to make them look nice, let me know!

An example of a PDF created through my PHP script:

This is the automated PDF of the Irishionary.com dictionary.

This is the automated PDF of the Irishionary.com dictionary.

mPDF is the PHP library to use for creating this PDF. There are lots of other libraries available, but it’s hard to find one that instantly suits. mPDF seemed to be good in several ways, especially given that you can style the PDF using CSS (Disclaimer: not all CSS tags are supported. Each sold separately. Batteries not included.) Another good reason to use it is that there are a range of fonts that you can use.

The official PDF to show off what mPDF is below. However, I will not allow you to see a full size version of it in the likely chance that it would negatively affect your view of humanity.

Official show-off PDF by mPDF.

Official show-off PDF by mPDF.

Stop messing around, let’s get coding. Download the mPDF library above, and put it somewhere in your web directory. Start editing a new script called mypdf.php.

Step 1

Include the library in your script.

define('_MPDF_PATH','./mpdf/');
include('./mpdf/mpdf.php');

Step 2

Initiate the object that will output the PDF for you.

$mpdf=new mPDF();

Step 3

Write some HTML to the PDF. This is where your literary prowess comes in handy.

$mpdf->WriteHTML('<h1>My PDF</h1><p>Yes, this ebook was totally
worth $29.95 of your hard-earned cash.</p>', 2);
$mpdf->SetFooter('Copyright: me.');

Step 4

Write the PDF to your file system. This step may require some permissions setting magic that your Auntie Maggy definitely couldn’t do. Check out the documentation for more pointers.

$file_path = $_SERVER['DOCUMENT_ROOT'].'/pdf/mypdf.pdf';
$mpdf->Output($file_path,'F');

Step 5

Either a) give away your PDF for the sake of humanity, or, b) charge a $29.95 price for your Amazing New York Times and Life changing My Mammy” PHP-generated PDF.

Web development on Ubuntu

January 11th, 2010

I get it. You’re a Windows person, always have been and always will be. Ok, you’re not a total n00b either. You’ll use the latest Firefox (even Chrome, but you’re a little suspicious about its privacy implications). For LAMP coding you’ve set up XAMPP and code with Notepad++. You’ll use TortoiseSVN to commit coding changes, and you’ll load up Putty to finally update your product web site. And you’re actually pretty happy with your Windows 7 setup (hey, I like it too).

But I’ve made the switch, and you and your pet dog Pudgie could too. Given that you’re not a total n00b, you should consider using Ubuntu for your daily life, and particularly for coding that amaaaazing web site idea you have that lets users schedule their coffee breaks with long lost school friends. Oh, and it has an AJAX-y frond end with widgets and lots of buttons. Ubuntu is nicely set up for this, whatever your online project. Actually, you’ll even come to like that you can SSH and SVN directly through the terminal.

Apache and MySQL feel more at home here, while XAMPP on Windows has always acted a bit like a shady character that you’re never too sure what it’s going to do next. I was sick of the start-stop services of XAMPP. It’s like trying to use Safari under Windows, it just doesn’t feel right. And try letting Apache start with the rest of your crawling Windows installation, haha no thanks!

To give you a flavour, here’s what my Ubuntu desktop could look like if I was doing web development and happened to keep my windows nice and orderly:

An (orderly) view of my LAMP development on Ubuntu.

An (orderly) view of my LAMP development on Ubuntu.

Still a bit unsure about this Linux thing? It’s easier than it used to be. Just set up a virtual machine with a copy of Ubuntu running on it. No need to do a nasty dual-boot setup. (Later on, I bet you’ll be installing Ubuntu and virtualising Windows).

Ok, you’re almost there.You’ll need to install some extra components (although if you install Ubuntu server edition I think a lot of these are already set up for you).

Coding editor. Ubuntu already comes with a text editor called gEdit. Change the colour scheme to Oblivion, show the File Browser menu on the left and you’ll have an instant coding environment:

Gedit text editing program that's shipped with Ubuntu.

Gedit text editing program that's shipped with Ubuntu.

Apache, MySQL, phpmyadmin: With Ubuntu, you don’t have to trawl the web for software downloads of supported packages. Just install them directly through the system’s package manager.

Subversion: In the same manner as above, install SVN. You’ll be able to update/commit directly in the terminal. Now that you can use the Synaptic Package Manager, grab yourself a copy of Firefox too.

That wasn’t so bad, was it? Now you’re running on a free operating system that’s being constantly updated. If you’ve gotten this far, I now declare you an Ubuntu fanboy :P The only reason I still use Windows 7 is when I need to use Lightroom for my photo collection, but that’s a different (virtualisation) story!

Multiple operating systems – Virtualisation

November 16th, 2009

The era of dual-booting my desktop PC may have come to an end. Using Ubuntu as my primary operating system, I can now just run other operating systems on top of it using virtualisation. The idea has been around for a few years, and is matured enough to use reliably one your home computer.

I’m still relatively uneducated about virtualisation. As I understand it, it allows you to boot up your PC as usual, but then you can run other operating systems ‘within’ it, as if they were normal applications running on your PC. As far as I understand, with the normal virtualisation setup will need you to run at least one primary operating system normally (while enterprise-level tools may break away from this requirement).

So let’s jump straight in to how you can set this up on your system. This is the “host” operating system. Any virtualised machine running on top of it will be called the “guest”.

How to get virtualised

It’s this easy to run other operating systems on top of your normal one:

  1. Install Sun’s VirtualBox. It’s an open source virtualisation platform (very complex programming underneath the hood). It’s easy to use!
  2. Create a new virtual machine. This is the machine on which you’ll install an operating system.
  3. Boot up your virtual machine!

Pics or it didn’t happen!

Ubuntu is the operating system that I used as normal before any virtualisation setup.

I installed the VirtualBox application on Ubuntu, which then looked like this (you can see I already installed one virtual machine):

VirtualBox virtualisation application running on Ubuntu.

VirtualBox virtualisation application running on Ubuntu.

I then created a new virtual machine using the simple menus. Using an ISO image of Ubuntu Netbook Remix operating system, I installed it on the virtual machine. After booting up the virtual machine, that Ubuntu Netbook is then running as a guest its own window on the host. If you have the licenses, you could also run Windows XP and Windows 7 as guests in other windows in parallel, for example.

Here’s Ubuntu Netbook running as a guest on my desktop, on top of standard Ubuntu:

Ubuntu Netbook Remix running within VirtualBox.

Ubuntu Netbook Remix running within VirtualBox.

Bonuses

Each virtual machine created in VirtualBox is just a file on your actual hard drive. This means that the file can be backed up to store a “snapshot” of your guest operating system. If you make too many message installations on the virtual machine, you can just roll back to a previous snapshot you took.

Virtualised web hosting: The server which served you this web page is also coming from a virtualised operating system, offered by Servint. This feature allows me to rent a server running as a virtual machine (a “virtual private server”), which is cheaper because I’m sharing the hardware with other virtual servers, but it also has good performance as it has guaranteed minimum RAM and processor usage. It’s reliable too, as any other virtual server that crashes on the same hardware will never affect the reliability of my own virtual private server. Read more about eTeanga’s VPS hosting experience.

A glimpse into the early Web

November 3rd, 2009

We take a lot of the Web for granted. Things “just are”, but it’s not really that long ago that HTML and HTTP standards were being discussed and were still “under construction”.

Mark Pilgrim shows quotes from a mailing list including Marc Andreessen and Tim Berners-Lee. The discussion is about introducing a new IMG tag to be used in HTML documents to be able to include images in the page.

What seems like such an arbitrary discussion affects coding structures that are directly used still, about 20 years later.

Hosting with a Virtual Private Server

August 8th, 2009
Servint VPS

Servint VPS

You can get web site hosting dirt cheap these days. Most of these hosting companies just offer you plain old shared hosting. Your account can host mutiple sites, you can FTP in to upload your pages, and you’re on the same server as thousands of other sites.

VPS (Virtual Private Server)

If you’re a bit nerdier like me, though, you’ll probably have fun running your own VPS. This is a whole step up from shared hosting – you basically run your own server.

The only catch is that your virtual “server” is sharing the same hardware with a few other virtual “servers”. This virtualisation allows you to run a fully self-contained server, while not paying for using all the hardware.

When I say you get a server, I mean that with a VPS you can:

  • Log in to your Linux server through the command line
  • Install any program you like to customise the site. Need a special image manipulation library for PHP, just install it.
  • Fully configure Apache, MySQL through config files, log files, custom timeouts – whatever you want.
  • Guaranteed RAM and CPU cycles for a fast site load.
  • Install SVN and forget about FTPing files.

What I went for

I’m not a Linux command line pro. Actually, I felt a bit lost there at the beginning. Instead of going for a blank canvas approach such as Slicehost, I opted for Servint which is a fully managed VPS solution. This means that if something goes wrong, if I mess up Linux or Apache, their 24/7 support guys will fix it.

Try out Servint if you want more than just shared hosting. All my sites are hosted on my VPS, the busient being IrishGaelicTranslator.com with over 500,000 page views per month. The page you’re reading right now was served by that VPS. It takes a bit of server juice to serve all those dynamic pages, especially at peak times.

Get hosted with Servint VPS hosting!

Fail cat at a totally new level

July 24th, 2009


Catcerto.

Film a cat playing the piano, and write an concerto to accompany it.

http://www.youtube.com/watch?v=zeoT66v4EHg&

Sweet. CMS+Blog on Wordpress

July 17th, 2009

To set up Wordpress for both CMS and Blog:

  1. Create a Page and call it “Home”. This is your default home page.
  2. Create a Page and call it “Blog”. This will show in /blog/.
  3. In Settings -> Reading, choose to show “Home” as the static page for Pages, and “Blog” as the static page for Posts.
  4. In Settings -> Permalinks, change the “Common” rule to /blog/%postname%.
  5. Ta da! Your pages will be created as mysite.com/page/ and your blog posts will appear inmysite.com/blog/post/.

After 7 years of using handmade PHP pages on LearnIrishGaelic.com, I finally moved the site over to a Wordpress installation.

What this means is that I have one of the most mature web application at my fingertips. Adding a new page no longer means creating a new PHP page, and worrying about how to update my navigation menus.

What’s better, I read Brian Yerkes writing about how to use Wordpress both as a CMS and Blog. This means that the main part of your site can be static pages, while Wordpress still handles /blog/ as a blogging application. Follow the settings above to get your own CMS powered by Wordpress, while having a blog section.

Taking doubt out of the checkout process

July 1st, 2009

learn-irish-gaelic

Handing your hard-earned cash to to an online vendor can be hard to decide on, especially if it’s a small site you’re not familiar with. I’m always highly suspect of a site promising to ship something out to me.

So I was thinking about how to optimise the visitor’s process on LearnIrishGaelic.com where I sell some language learning software.

I’ve made a small change online. Instead of guessing when you’ll receive your order (”within 10 days”), I’ve added “Next dispatch date” and “Your order will be delivered by…” date to the shipping information.

Hopefully just another small bit of information that will help you decide to splash out on a learn-at-home Irish language product ;)

Newstalk.ie not coping with news traffic

June 7th, 2009

croppercapture1

Yesterday was the first day of counting in Ireland’s 2009 Local and European elections.

There will always be some spike in traffic to a news website around a big event such as an election. These are the most crucial times for a news site.

This is why a news site’s server should be prepared for unexpected traffic spikes. Unfortunately, Newstalk.ie (a good radio station) is down, presumably because of people trying to get up to date on the latest election news.

Tip to Newstalk: beef up your server and check your Apache settings ;)

Install Google Chrome on Ubuntu – Early Access Release

June 6th, 2009

chrome-on-ubuntu

At the time of writing, Google have released the very first Chrome-branded browser on Linux (in my case Ubuntu).

To install Google Chrome on Ubuntu, follow this download information link.

As the Chromium blog states:

… whatever you do, please DON’T DOWNLOAD THEM!

From what I understand, this current release of Google Chrome on Ubuntu is basically a branded version of the Chromium browser which is in pre-alpha stage for the Linux platform.

Go ahead and install it for the fun of it. You won’t even have a Flash plugin for the browser yet, but it’s being constantly updated.