When mod_rewrite and .htaccess seem not to be working

Recently, I upgraded my Ubuntu server and set up a new Apache environment. As I use my personal server just for testing and nothing mission critical, it was natural that I, instead of painstakingly backing up and writing scripts that would restore my environment to its former state, just run an update and let things fall apart.

One issue I immediately encountered, .htaccess redirects through mod_rewrite didn’t work. I went into the Apache configuration and dutifully changed the “AllowOverride” setting from None to All. As is usual with configuration settings I restarted the server.

Mod_rewrite and my .htaccess settings seemed to have no effect. After some digging I found an interesting answer on the Ubuntu forum. Apparently, Ubuntu doesn’t clear the configuration cache on conventional restart. Instead of:

service apache2 restart

I had to write a more lengthier version:

sudo service /etc/init.d/apache2 restart

This forced the fresh loading of config files and allowed my changes to take effect.

The original forum post that helped me can be found here: http://ubuntuforums.org/showthread.php?t=2207932

MySQL crashing on Ubuntu

I recently experimented with setting up my own environment on Amazon AWS.

Loading an Ubuntu instance is easy enough, and installing Apache and MySQL is equally easy.

However, I ran into a problem after connecting the MySQL database to a handful of small use apps.

After some research, it seems the memory might be an issue. The best way would of course to have some type of way for MySQL to more effectively manage its memory, however, the simplest way is to set up a swap on your system. You can find instruction on how to do it here: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-12-04

NodeJS and Ubuntu

Suprisingly, NodeJS is easier to install on Windows than on Ubuntu.

Generally, I’ve found two different set of installation options.

1) Use Curl to set up and the install NodeJS

curl -sL https://deb.nodesource.com/setup | sudo bash -

sudo apt-get install nodejs

Find more info here.

2) Use Chris Lea PPA

sudo add-apt-repository ppa:chris-lea/node.js

sudo apt-get update

sudo apt-get install nodejs

Find more info here.

I suspect that the first method is for desktop and the second method for the server, but I can’t be certain.

Of course I found a better method: http://howtonode.org/how-to-install-nodejs

Composer – Wamp – Curl Issue

Recently, I tried installing an update using Composer.

As soon as I tried to run Composer from the command prompt I received an error saying:

PHP Startip: Unable to load dynamic library ‘c:/wamp/bin/php/php5.4.3/ext/php_curl.dll’ – The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more details.”

I wasn’t familiar with sxstrace.exe and chose to use Google instead. I found some answers that didn’t work – like suggestions to copy files to my system32 folder and the like. Finally, however, I saw one post in a forum(here) suggest that .dll files that Wamp came with was faulty and needed to be replaced by a fixed one – found here.

The fix that worked for me:

Simple download the fixed curl extension from one of the zip files below (I used “PHP_CURL – 5.4.3 VC9-x64″ for my 64-bit Windows running 64 bit Wamp)

PHP_CURL – 5.3.13 nts-VC9-x64

PHP_CURL – 5.3.13 VC9-x64

PHP_CURL – 5.4.3 nts-VC9-x64

PHP_CURL – 5.4.3 VC9-x64

Copy the .dll inside the zip into your “wamp/php/php[version]/ext” directory.

Restart your server.

Composer and Curl should work fine now.

Let me know if you encounter difficulties or discovered other methods – I’d like to add them to this post.

Tips to improve performance for websites

Website performance is an important part of your overall website design. For example, Drupal, a highly sophisticated and reliable CMS, can often make over 700 database queries per page request. Depending on your installation this can be detrimental. If you are on a shared hosting platform your database instance will always be on a different host (even if it is “localhost” each connection will cost you lots of time). So when picking Drupal you need be aware of how you final architecture will look like. In the next few paragraphs we will go through several steps to improve your website starting from our server side PHP code.

Improving server side PHP code

PHP has a very useful extension called ‘XDebug’. If you are running WAMP this is already installed – but if you haven’t installation is easy. All you need to do is add the extension .so (UNIX) or .dll (Windows) file to your php.ini file. You can find out more about this at XDebug’s website. Once you include it in your bootstrap script you will be able to understand how much time is consumed by each individual task that your script is doing. Below is a picture of the profile of an app I wrote. In this case we put the database on Amazon and allowed different people to maintain their own implementations.

KCache screen shot of XDebug profile

94% of execution time was spent on database queries

As you can see a bulk of the time (total time for execution was just over 22 seconds – which is insanely high) was spent on 700+ database queries. This was slowing down the app performance, and it was seen that down the road if the total data requested was more this could easily go up and slow down performance even more. Armed with this information we looked at the script and re-wrote it, drastically reducing the amount of database queries from 700+ to a static 3 (even if the data grows, the queries will only be 3). This resulted in more processing before pushing the data to the client. It is not that the database server was slow, but each new query required a network connection from my Apache PHP server to the Amazon MySQL server. This network travel of information is what slowed down the script. Re-writing the script we ended up with an execution time of 0.6 seconds – which is a 98% improvement and very acceptable for a complex app.

This is just an example of what you can do once you get a profile from XDebug – it will allow you to find the bottleneck in your script so that you can address it directly.

More on Network Connections

For better or for worse, network connections are the single biggest factor in slowing down a website. A browser will only load two files from the same web address at a time (similar to your ftp client). Does this means you can achieve simultaneous loading by distributing your files on different web addresses? Yes, and no. It is true that with 4 files distributed evenly over 2 addresses you could have them load simultaneously, but each address requires a address look up and a way of your browser establishing a path to the file. So there is no simple fix.

What do I recommend:

  • Write a script that combines and mimifies your CSS and Javascript (in the proper order that you would want the CSS or Javascript loaded). One of the biggest problems of WordPress is that with 20 plugins you end up loading 20 additional CSS files and possibly 20 or more additional Javascript files. From a maintenance perspective it would be foolish to combine all the scripts and styles and then edit huge files. It is good that files are kept separated. So either at run time, or at deployment, it would be beneficial to combine all script and style files into a single file and load that file. For this you can use something like LESS or SASS for CSS.
  • Use CDN (Content Delivery Networks) to reduce the number of hops that are required between your viewer and your server. This will often reduce overall webpage load times. A CDN keeps copies of your files at locations that are possibly closer to your intended audience. For example, your host might have their servers in Texas and your primary clients may be accessing your website from Toronto and Vancouver. By using a CDN you will be able to keep your data on servers that are close to Vancouver and Toronto respectively – thereby reducing the travel time per data packet, and the overall website load time.
  • Make sure that your Facebook “Like” domain matches the domain that you provided in the Facebook App. If your domain doesn’t match Facebook takes a long time to respond. Facebook requires an individual app registered with them for each website that is supposed to be integrated with them. Make sure to follow their instructions carefully.
  • Google Fonts are awesome but pay attention Google page speed indicator. Some fonts are huge, and always only get the fonts you will absolutely need.

Caching Results

Most PHP frameworks like yii and Laravel have caching options. WordPress has some plugins that allow for caching. Caching is a way for the server keeping pages saved and then delivering them to the client without need for processing. This reduces the load time especially when the website is either making multiple queries to compose the given page, or if a lot of processing is required. Caching results is something that will often vastly improve user experience as users can navigate through your website increasingly easier. So once they have visited one section, returning to that section to re-visit a fact would be considerably quicker.

Javascript + CSS

One important aspect with Javascript is often plugin codes. For example Facebook, Google, etc. will load scripts “asynchronously”. This means that the script loads without interfering with the loading of the remaining website. Now this is not that hard to do for your own script if it is possible. If your Javascript files hold some functionality that will only be used by some users down the road and wouldn’t be required for the presentation of the home page, it would make sense to load these scripts asynchronously and then enable that functionality after the script finishes loading.

For some this talk about load times may seem overkill – but imagine trying to load a page with 2 bars on your cellphone; or someone accessing your website without a broadband connection. In these instances a smoothly loading website – one that focuses on making sure that the user has something to look at first, before we get all the functionality set up.

CSS has become amazingly powerful but also woefully bloated with CSS3. It is a good time to now switch to CSS frameworks like LESS or SASS and use their mimified CSS. This greatly improves code usability and improves the performance of your website. It is also good to use one “sprite” for multiple icons. It is best to use one large image with all your icon graphics and then use CSS to place them, rather than have a unique file for each.


Images need to be optimized and using a program like Photoshop you can evaluate which file type and settings are right for you. Always remember that for the web 72 dpi is right – while print needs at least 300 dpi. PNG and GIF files are generally better for graphs and pictures with high amount of single color space or a lot of transparency. JPG are better for color rich pictures.


These are some of the ways to improve website performance. It makes sense to think clearly and use every tool in you chest to improve the quality of your end product. If you have any recommendations, tips, or suggestions let me know.

Wamp and Windows 8

Windows is always trying to please consumers and compete with OSX. By doing so it often hurts us developers. I’ve already migrated to Ubuntu and am slowly spending more time on Ubuntu as programming tasks are just better in a Linux environment.

But, I still need Windows because when I design websites I need to use a good design program and Ubuntu isn’t up to speed in that department , yet (there are some good options, just nothing as good as what’s on Windows).

Especially, when I design Worpdress Themes, I need Windows and I need PHP – so I had not choice but to install Wamp on Windows 8 (I did have a choice – I could have installed Apache, MySQL and PHP separately - but that’s not really a good choice).

These are some issues that I encountered:

1) Apache won’t install.

When trying to install Apache you get an error that says that MSVCR100.dll can’t be found.

To resolve this, you need to find the Microsoft VC++ redistributable package. For Windows, Apache needs this and won’t run without it.



2) 403 Forbidden

After installing and starting Apache, the first thing most of us do is to take our browser to localhost to see if it responds (I still remember 8 years ago when I was first introduced to the concept of localhost). When you do that in Windows 8 you will run into a 403 forbidden error.

Some forums on the net stated that this has something to do with the windows hosts file – that’s not true. Wamp edits that file properly and adds the localhost entry. But, the httpd.conf file in the Apache server configuration has an issue.

You need to change: Listen 80 to Listen

I don’t know why that is the case and I think that in the future Wamp will have a Windows 8 installer that takes care of this.

3) Port 80 used be IIS

This is something I found in forums, but it didn’t happen to me. But generally, if something else is using port 80 you will have to stop it to run Apache. TeamViewer and Skype are other programs that run on port 80 – and you have to watch if any programs start with Windows and occupy port 80. This is not a problem specific to Windows 8 but people may encounter it for the first time after installing Windows 8. Of course, the other option is to run Apache on a different port – this would involve editing the httpd.conf file and change the “80″ value to something like “8080″ (used by Tomcat). Keep in mind, that when you do this, the browsers won’t resolve your localhost entries without the port value. By default browsers are set to talk to port 80 – but once you change your server to 8080 you need to add that – so instead of http://localhost you’d have to write http://localhost:8080.

If you encounter any other issue please let me know and I will add them to this list.

Alternatives to Google Maps – OpenStreetMap

The way it is today, I don’t think any online mapping tool can compare to the comprehensiveness of Google Maps. However, as I mentioned in my previous post, there is something brewing at Google headquarters and as a user we need to be aware of alternatives and support them.

One such tool is OpenStreeMap. OpenStreetMap is a free, rights free, open source, collaborative mapping tool (think Wikipedia of maps). It is free to use and share and relies entirely on donations and voluntary contributions.

10 years ago we may have scoffed at such a project, but Wikipedia has shown that independent volunteers can produce reliable comprehensive information.

Personally, I think it looks a lot better than Google Maps. The colors seem more pleasant and natural.

OpenStreetMap Screenshot

OpenStreetMap is an Open Source alternative to online maps

Beyond that however, it is not really a replacement to Google Maps at the current point. It still lacks a directions engine, and the Google Eco-system that binds Google Places with Google Local, information on local transit, differentiation between one-way streets, pedestrian walk-throughs etc. make Google Maps a more useful tool.

Bay and Bloor Screenshot of Open Street Map

OpenStreetMap already has significant information about local businesses, but it still can't compare to Google Maps.

OpenStreetMap is an initiative that I will support over the coming years and I hope that they will build out the functionality as more and more volunteers and donations pour in.

Alternative to Google Business Mail – Zoho Mail

I have recently moved to Zoho Mail.

As you may be aware Google Apps is no longer free for new users – if not you can read about it here: No More Free Google Apps

As part of our journey to encounter alternatives, our choice for mail was Zoho Mail.

What I like most about Zoho Mail was that:

  1. It has a free option
  2. It promised no ads and no keyword scanning
  3. It provided an extremely simple set up (I found it was easier than Google Apps)
  4. It is part of a suite of business apps, similar to Google Apps
Zoho Mail

This is how your inbox looks with Zoho Mail

On first load Zoho mail was a pleasant experience. It is the first time after a very long time that I was able to access webmail without being overwhelmed by ads, or creeped out by the fact that Google understands the content of my email better than my recipients.

Intergrating with my mobile phone worked without a hitch – additionally, Zoho provides m.zoho.com which are all their apps, optimized for mobile. This will allow you to side step all the usual set up requirements when having to access mail on the phone, while still enjoying a mobile optimized experience.

Zoho Mail, just like Google Mail has an “IM” feature. However, there is something good and something bad about that – what’s good is that if your organization is on Zoho Mail you will be happy to know that you can only chat between Zoho Accounts; a soft way of preventing idle chatter during work hours. On the other hand, you will not be able to chat with all your gmail contacts.

There are some clear disadvantages: no voice calls, no video chat. While these are tremendous features I’ve rarely used them – Google Hangouts are better and services such Oovoo provide conferencing for organizations – which is much more relevant for multiple users. And most of my voice calls are still made with my cellphone (especially, since Google Voice phone numbers are only available in the  U.S.).

The look and feel is a little “old”. It looks a lot like a gray version of Yahoo’s old inbox (I mean the old one without Ajax – pre 2007). When it comes to functionality and response it is clearly not in the past, but the look and feel is definitely behind Yahoo, Hotmail (Outlook Online) and Gmail.

Encryption is currently not available – Zoho itself serves its websites on https, but it does not currently encrypt user data. However, they promise that this will be a service that will soon be available.

Time will tell if uptime, responsiveness and spam filters work well. We will update this post with that information as it becomes available.

While there are some clear drawbacks to switching to Zoho, if free, clean, ad-free, private email is important to your business, than Zoho Mail beats all the commonly available alternatives.

About Zoho

Their FAQ states the following:

“Zoho is a division of ZOHO Corporation A US-based company that has been creating and selling cutting edge software solutions since 1996. The company has tens of thousands of customers worldwide, is privately held and profitable.”

Additional Resources:

Zoho Privacy Policy governing all their products: https://www.zoho.com/privacy.html

Configuring for POP: https://zohomail.wiki.zoho.com/for-Outlook.html

Configuring for Outlook as IMAP: https://zohomail.wiki.zoho.com/IMAP-Access-1.html

Where is the Best of Toronto?

I was looking for an interesting project to do in order to try out Google Maps’ new “Heatmaps” feature. I figured BlogTo.com’s “Best of…” lists might be an interesting way of establishing where the “best of” Toronto is. Below is the result.

It looks like west of Yonge, south of Bloor is where all the interesting places in Toronto are. Especially, King West and Queen West seem to be lit up with good and interesting places. I wonder if real estate prices match this and whether condo developers are buying up properties in these neighbourhoods or if that opposite is true. If anyone has real estate data that I can use let me know and I can run a comparative script.

It would also be interesting to see if a heat map like this leads or lags behind real estate prices.

Read on if you want to know about my methodology.

Heat map of good places in Toronto

Heat map of good places in Toronto

The methodology I used was as follows:

  1. I wrote a Python script to scrape the contents of BlotTo.com’s “Best of List…” (hope they don’t mind). The script specifically looked for the “address” on the HTML page.
  2. The script then saved all of that in a MySQL database.
  3. A second script ran the addresses against Google’s GeoCoder to get longitude and lattitude values.
  4. Finally, a third script wrote out the javascript array and then ran the basic Google Maps Heatmap script.

If you have any additional questions let me know.

Alternatives to Google

I love Google.

For the last 10 years they have been releasing amazing and innovative products. And for  a long time they seemed to “get it” – and I used to just wonder how they made any money (aside from the obvious ad income).

But as the company is maturing they are making new choices. Once run as 10 year old start up – as if the founders believed that constant innovation would allow them to ride the wave forever – it is now falling in line, making sensible, calculated business decisions to reduce spending and improve margins.

The last years have seen an acceleration of competitiveness without the same spurts of innovation. Long time ago Apple developed (or stole) the best touch-screen and made the best touch screen phone. Since then their innovations have been incremental and focused on maintaining spending habits of their consumers not so much innovating new products; Microsoft reached the tail end of an essential computer OS monopoly when after 15 years of Windows disappointment more and more consumers switched to OSX or highly intuitive Linux distributions (like Ubuntu). Google innovated, or bought up and improved, or stole and improved a tremendous amount of products, many of which only survived several months before being discarded. Now we are at an impasse.

Technological improvement has given way to usability, design and brand loyalty. And Google is realizing that. The OS battle has become very hard fought, and being a very new thing for Google, it isn’t easy. Already, we have Android 4.1. With each iteration and with each milestone increase in users, Google is facing new difficulties, both technological and legal; both purposefully created by their competition and naturally evolving out of usage.

And in all this Google is not making a pretty penny – their profits still rely on their quickly diminishing ad sales market.

All of this leads to one conclusion: Google’s relationship with its consumer will change – and when it does, what do we do?

Over the coming days I want to suggests alternatives to Google that may allow you to stay objective as Google makes changes that you may not be happy with. The great thing about the internet is that there is always an alternative.


Part 1: Mail: Zoho Mail

Part 2: Maps: OpenStreetMap