Entries Tagged 'Linux' ↓
August 19th, 2007 — Linux, Programming, Web Development
You Americans (and British, Australians and any other English speakers) have it easy. When you need to create a web application, all you need to use for your text is the basic English alphabet, only 26 different characters and 10 digits. The rest of the world, myself included, aren’t so lucky. Our languages are damn complicated, with additional letters, along with such grammatical ‘features’ such as accents to see where the pronunciation is at its strongest.
Seeing that I was born in Chicago, my first language is English. Although my parents are both from Puerto Rico, they never enforced the usage of Spanish upon me. When I moved to Puerto Rico when I was 8 years old, the only word in Spanish I knew was “Gracias”. Unfortunately, I didn’t have Dora The Explorer to help me learn the language when I was a boy. It’s taken years, but I finally consider myself fully bilingual in both English and Spanish, and am usually very careful as far as spelling and grammar go.
However, I’ve been wracking my brain for a long time now when making web applications in Spanish. Sometimes the additional characters, like the letter “ñ“, or words like “presentación” are a pain to get working immediately. It’s like I have to jump through hoops to get those characters working right.
In case anyone else shares my pain (or in case I forget in the next couple of months), I’ve compiled a short list with the things you should first look for when these Unicode characters are appearing incorrectly.
Don’t forget the <meta> tag
One common mistake web developers make is forgetting to set the default character set of the page they’re working on. Without this tag, the browser will automatically set the character set to the browser’s default, usually ISO-8859-1, which does not show Unicode characters. To set the character set of the page to UTF-8, which correctly displays Unicode characters, you simply need to add the following meta tag as the first line in the <head> section:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
This should enforce your browser to use UTF-8 when displaying the page’s characters. Remember to set this first, before any other tags in the head section, or else it won’t work at all.
Check your web server configuration
I remember once working with a PHP application, and pulling my hair out because the characters simply wouldn’t display correctly, no matter what I did. After hours of searching through Google, I found out my problem. The Apache Web Server, which was responsible for serving the website, had its default character set set to ISO-8859-1. If you control your own server and can change Apache’s configuration, just go to the configuration file named httpd.conf (this name can vary, depending on your Linux distribution) and make sure the AddDefaultCharset option is correctly set:
AddDefaultCharset UTF-8
After reloading the Apache Web Server, your pages should be displaying Unicode characters correctly. With the Lighttpd Web Server, which I’m using now, I haven’t had to set any option for correct Unicode support. However, in case someone needs it, just go to your Lighttpd configuration file, go to the mimetype.assign section, search for the .html assignment, and add the following at the end:
".html" => "text/html; charset=utf-8"
Another file to verify, although not necessary in most cases, is the PHP configuration file, named php.ini. PHP is responsible enough to use the encoding set in the page by the meta tag mentioned above, but sometimes some joker decides to change the default character set in the configuration file. In this case, simply comment out the default_charset option, and reload your web server.
The database has data too, you know…
With those two fixes above, your static text should be displaying correctly. However, you notice all Unicode characters stored and retrieved from the database are still being incorrectly displayed. This is due to your database character set not being set to UTF-8. In my app, I’m using MySQL, and the database server’s default character set is set to latin1_general_cl, which apparently doesn’t display Unicode at all. If you don’t explicitly indicate which character set you want to use for your database, the default will be used for not only the database, but the rest of the tables (unless explicitly defined, as well). What we want is the utf8_bin character set, which will display the Unicode correctly.
There are different ways to change this default behavior, from starting the database server with an option to change the default character set, to recompiling the entire program (providing it’s Open Source). But I find it much easier to just remember to make your database use the correct character set. In the MySQL prompt on the command line, it’s as simple as this:
CREATE DATABASE database_name CHARACTER SET utf8;
If you have an existing database not using the UTF-8 character set, the easiest way is to use a program like PHPMyAdmin for MySQL, or your preferred GUI for your database server, and change it there. You can also do it through the command line, but I won’t go into those details here. Search Google and you’ll get a ton of information.
Your text editor has a hand in this too
Don’t forget the tool you’re using to create your web pages. They could be the ones giving you major headaches. In my case, I’m testing out Intype, which is still in alpha, but very usable. Intype has the nasty habit (which I wish is fixed soon) to automatically set the file’s character set to ANSI by default. Once you save the file with this character set, it stays that way, wreaking havoc on what you want to see.
To fix this problem, just make sure your text editor, whether it’s Intype, e, Textmate, Vim or any other text editor in vogue right now, is saving your file using the adequate character set. In my case, I’m using UTF-8 Plain with Intype, and my characters are showing up correctly.
These tips should save you a ton of headaches down the road if you’re doing web development for a non-English audience. If you have any to add, feel free to do so.
August 8th, 2007 — Linux, Open Source
If you’ve been to this site before, you’ll notice a whole lot has changed since the past week. I decided to make some changes, not only to the site, but to the entire architecture running the site as well.
The first major change I made was to switch from a regular hosting service to a VPS. It’s made a world of difference. I don’t want to name my previous hosting company, since the service is pretty good, especially for what I paid for it (not too much). However, I felt it was a bit too slow for my tastes. Also, I’m sort of a control freak when it comes to controlling my work. So I scoured the web, and found a company that offers cheap VPS service, so I signed on.
While I do have system administration experience in Linux and am very comfortable working from the command line, it took a while for me to learn how to set up a domain to resolve in your own DNS, how to set up E-Mail accounts with different domains, and other random things. I’ve learned a lot this past week, and for now, my domains are working correctly. It’s fun when you have to bust your ass to get something working, and it finally does. The hard work makes you appreciate it more.
Since my VPS service is limited to 128 MB of RAM (this is just a test VPS to see how it’ll work for my needs, so maybe I’ll spring for more RAM later on), I immediately shut down the Apache Web Server that’s automatically run by default, and grabbed a copy of Lighttpd. After compiling it, learning how to configure it, and making it run, it’s also made a world of difference, as far as speed and ease of administration goes. Although it has some quirks to get some software working (especially Wordpress), it’s not to difficult to figure out on your own.
FInally, my old site ran on Rails. After running it here, I noticed that it consumed too much RAM for my tastes. So I set out on rewriting the page again using PHP, but saw that my Wordpress installation is more than adequate to run the few pages I’ve had for now. I was also convinced to use this because I fell in love with this theme, called Hemingway. So I decided to make it easy on myself and just drop everything in Wordpress. I know Wordpress is used for blogging, but for a simple site as I have now, it’s more than okay to have a few additional non-blog pages around. It just looks good and it was quick to do, and that’s what I wanted all along, since I need to focus my energy on another task that I’ve been doing for the past two weeks.
So, after this switch to a VPS and the redesign, I’m happy with what I have for now. Not only do I have a good-looking site, I not only learned a lot more about Linux, I also have a nice little virtual server running smoothly. Right now, I’m running the server with a web server (Lighttpd), mail server (Postfix + Dovecot), a database server (MySQL) and it’s only consuming 57 MB of RAM. Go Linux!
If you’ve been here before, or even if you haven’t, tell me what you think about the site now, about his it looks, how it runs, whatever you want to comment about. I’ll appreciate any feedback.
February 14th, 2007 — Linux, Open Source, Programming, Ruby On Rails
It’s been a while since I last used any Linux operating system full-time in my own computer. Back when I was in college and still had tons of free time, I would always try to get the latest and great Linux distribution just to try it out. That’s how I really got familiar with Linux. I always recommend to co-workers and other people interested in Linux to just grab a distribution, even if it’s a Live CD, and just play around with it. If they get stuck, there’s tons of help on the Internet, along with my own help, so any fears they have should disappear.
Anyway, I’m heading off topic with that, and I’ll maybe write about it some other time. For now, I wanted to write about my recent experience. I do use Linux every single day at work, but only at servers, where the command line rules them all. However, I hadn’t used Linux for the desktop in a while. I guess I didn’t want to fiddle around with installing and configuring the OS to my needs. But a friend at work told me he started using Ubuntu, and that basically got me into the Linux mood again.
I had already tried Ubuntu, ever since version 4.10, and I liked it. Still, I thought it was too “user friendly” for me. I know user friendliness is a great thing. But come on - this is Linux! It’s meant to be difficult, right? That was my previous point of view on the subject. But after installing Ubuntu once again, I’m totally hooked. The last version, 6.10, really makes a great name for itself. It has all the user friendliness you can give new users, but it also allows those power users do whatever they can do with other Linux distributions.
I obviously installed Linux to work with Ruby on Rails. I have to tell you, Rails on Windows is a bit of a pain. It just doesn’t feel right to work with Ruby or Rails in a Windows environment. I’ll also save that for some other time. But after installing Ruby and Rails here, I’ve been pretty damn productive with my Rails learnings. It’s been a really great tool.
For now, Ubuntu stands as the leader of the Linux world, at least in my option. This is the distribution that will most likely propel Linux into mainstream usage, not just for geeks like myself who just love to tinker around with these things. Other companies have been doing great on other fronts, such as Novell (with SuSE and OpenSuSE) and Red Hat (with Fedora Core and its own Enterprise Server). But to me, Ubuntu is the distribution that will help get Linux into many homes that have only seen Windows stuff before. And with Windows Vista’s apparent shortcomings (I haven’t tried the OS yet, so I may be misinformed), along with Apple’s very excellent Mac OS X (with increased Apple hardware sales), I think these systems that are in the minority will finally gain some market share that Microsoft has been hogging for years. Look out, Vista.
January 30th, 2007 — Linux, Programming, Ruby, Ruby On Rails
I remember when I first started using Linux back in the day - “back in the day” referring to about the year 2000 - it was a total pain to work with. From not-so-great hardware detection, to installation and partitioning pains, to the ever-lasting fight against making a Winmodem work, it surely wasn’t for the weak-minded. However, something I sort of enjoyed during that period was downloading and compiling the programs myself. Well, I didn’t enjoy it much when dependency problems arose. But just the fact that I was taking this free and accessible source code, compiling it myself, then having fully functional software made me have a sense of accomplishment.
Nowadays most people have it easy. With friendly and easy-to-use Linux distributions, such as Ubuntu and OpenSUSE, all you need is to just click on a checkmark in a GUI interface and your programs, along with all dependencies, are immediately installed. Nowadays no one even has to use the command-line at all if they wish to do so. So as Linux gets easier to use, less and less people learn how to really use the operating system to its fullest.
Unfortunately, I too have fallen into that trap as well. I remember I used to compile the kernel every single time a new one was announced. Now, I barely do it. If the operating system I’m using at the time doesn’t have a current update, I don’t install it. Every time I see a new program I was to try out, I check first if there are already pre-compiled binaries for my distribution, and only compile the source code if all else fails. It’s kinda sad how much I’ve lost during these past few years.
That will probably change from now on. Last night, I took a spare computer in my apartment (1.0 GHz Athlon with 768 MB of RAM and a 20 GB hard drive) and decided to put it to good use. Seeing that I’m trying to learn Ruby and Rails, I wanted to install an easy-to-use distribution to save me some time with installation and configuration duties. So I chose Ubuntu, and it all installed just fine, until it came time to install Ruby and Rails afterwards. With Ubuntu, installing Ruby is just as easy as doing this:
sudo apt-get install ruby
Ubuntu did its magic, even though I didn’t have a good feeling when I saw it was installing version 1.8.4 (Ruby is now at 1.8.5). Oh well, I thought. It was just a minor revision, no big deal. I then went on to install RubyGems, and it installed okay, until I started getting some warnings. Since it finished the installation, I just kept on going. When it came time to install Rails, This time one of the gems didn’t install (I believe is was Action Web Service). I had installed Rails in other distributions without warnings, even on Windows. Since I had a couple of spare minutes at night, I decided to go the long route, and install everything from scratch, and make sure it’s up-to-date.
I’ll skip the entire process, as I’ll probably cover it in another, more formal, post. But I grabbed the source code of Ruby and after uninstalling all the mess the Ubuntu binaries caused, I compiled everything and I had absolutely no errors at all! I was even able to install the Mongrel gem without any problems.
So, that taught me a lesson as far as relying on pre-compiled binaries goes. Besides the obvious reasons why you should try to compile your own software (if the code is available), such as optimizing the compiled binary for your system and making sure you have the latest versions, you can avoid problems from the beginning, even if package managers such as Ubuntu’s apt are supposed to help you there. Also, it brought back that sense of accomplishment I used to previously have. So from now on, as long as time and skill allows me, I’ll be compiling my own code.
Time to pay a visit to the Linux Kernel Archives. Long time I haven’t been there.
Testing