Experiences going from Apache 2.2 to 2.4.6 and PHP 5.3 to 5.5 when upgrading my local dev to Ubuntu 13.10

At Checkout 51 we’re very flexible when it comes to how you want to setup your development environment. Personally I like to run Ubuntu on my Macbook Pro using Virtualbox, others choose to use tools such as Macports. I choose to go down the Virtualbox path as it allows me to mimic our QA and Production environments fairly closely in terms of OS and the versions of the various packages available.

Recently the latest version of Ubuntu (13.10) was released and I’ve upgraded my local dev environment as in the near future we’ll do the same to our QA and Production environments. This change came with a bunch of lovely new features in PHP (my personal picks: finally blocks, imageflip built into GD and json_encode now supports a depth param) that I’ve been long awaiting such as a new version of Apache (2.4.6) and PHP (5.5.3). While the PHP upgrade causes me virtually no issues, the Apache upgrade was a little more painful.

We use a variety of languages and tools (PHP, Java, Memcache, Redis, MySQL, SQS, S3, Jenkins, Git…the list goes on) but we do really like to keep our links clean so that people can easily visit addresses http://www.checkout51.com/about without the messy .php extension (not because of the social stigma associated with PHP as a language)

Here are the key changes I had to make

1. The “Allow all” term used within your directory element of virtual host is no longer support

To do the equivalent, replace this with “Require all granted”. Until you correct this, your server will report an error much like the following in your Apache error log.

AH01630: client denied by server configuration

2. Hiding PHP was easy, now its a little different

Previously in Apache 2.2 we could include the following in our virtual host and we’re done:

<Files ~ “^[^\.]+$”>
SetHandler application/x-httpd-php
</Files>

Unfortunately this no longer does the trick on its own and you need to use a combination of the new ForceType option combined with mod_rewrite to accomplish the same behavior to avoid getting a nasty error.

<Files index>
    ForceType application/x-httpd-php
</Files>

<Directory /var/www/>
Options +FollowSymLinks -MultiViews
    RewriteEngine on
    RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*?)/?$ $1.php [L]

AllowOverride None
    Require all granted
</Directory>

I hope someone out there finds this useful :-)

A full listing of what it might take for you to upgrade to Apache 2.4 from 2.2 checkout  it might also be worth looking at the list of deprecated features in 5.5.3 and 5.4 (in case you, like me, are going from 5.3 directly to 5.5)

No Comments

I love my Mac, but this is annoying!

Every now and again, this little icon decides to jump up at me. If you own a Mac, I’m sure you’ve experienced this.


For many years I’ve not loved Adobe. Flash is highly inaccessible to people with disabilities and licensing has been less than ideal for as long as I can remember, but recently the thing that has annoyed me most of all is the fact that no other application on my Mac seems to magically launch itself and demand an update like Adobe Reader does.

I want my Mac to be clean, simple and most of all virus free. In my opinion, this behavior is what I would expect of a virus. Not shockingly, it appears Google has come to a similar conclusion.

Adobe please stop this, or at the least only ask for an update when I read a PDF. Apple, please keep my Mac virus free, after all I moved away from Windows for a reason.

 

No Comments

Understanding My Sleep

I’ve always had a love / hate relationship with sleep. I love sleeping, yet I seem to do so much to avoid getting enough of it and often end up trading it in for additional working hours.

While this post isn’t an app review, I’ve been using an app (Sleep Cycle) to track my sleep and have really enjoyed reviewing the results and seeing how I can use them to better understand myself. The period of time I’ve had the app has been a very intense time in my life. To sum it up…

  • Amanda and I Moved. Apartment hunting, packing, moving trucks, updating addresses…it’s really no fun.
  • Decided to stop working on Verelo. Fail fast right?
  • Joined forces with two of the greatest people I’ve ever worked with and founded Checkout 51.
  • Sold Verelo to Dyn.com to payback our investors. Selling a company is complicated and stressful but also very rewarding.

All of these events have been intense and required a lot of energy. I’ve had to balance the deadline of moving with goal of releasing great software, learn what it means to release an iOS app (that’s used by many thousands of people) and build / hire the best people I’ve ever worked with (We’re still hiring by the way, so drop me a note if you’re interested). Its been an exciting time that I’m sure i’ll look back on one day with a lot of mixed emotions.

During this time, i’ve been tracking my sleep and have gained a lot from the results.

1. Time in bed

I think this is probably the most interesting graph as it clearly shows some very particular events. The first dip around 12-9 to 12-16 was the release of the Checkout 51 iOS app. There was a lot of work leading up to this, and shortly there after to support scaling certain elements of the technology around it. As the graph shows, the short sleep periods lasted for a while but recovered pretty much around the 25th of December.

Just last week I was sick, while i spent a lot of time lying down, i certainly wasn’t sleeping very well and the little dip just after 1-6 shows the disruption.

The interesting part in all of this is that I’ve always felt that for me 8 hours sleep is what I need. I probably need to layer over my Github commits to confirm this, but I’m confident that my best work happens during the periods where I can sustain 7-8 hours sleep / night.

2. Time went to bed

This one really just shows a strong relationship with the total amount of sleep i get per night. Again you can see the late nights that were regularly happening to get the Checkout 51 mobile app done and a bit of a dip into pre-midnight bed times when I was sick.

3. Time in bed per week night

This is my favorite graph. I always find Monday and Tuesday to be my worst week days in general. Call it a case of the Mondays if you want, but i find myself bombarded with issues that are time sensitive at the beginning of the week. I’m not exactly sure what I’m doing wrong just yet (this is a great place for some ongoing improvement), but it always seems that I end up paying for trying to relax on weekends. By Wednesday things are always in better shape, and I’m getting the optimal amount of sleep and feel that I’m more easily making progress on my to do list.

So what?

Good question. So, other than that $0.99 can provide you with an interesting app, I think it’s fairly obvious that I’m the kind of person that needs around 8 hours of sleep / day. When I don’t get this sleep, i know my work suffers however its also clear I can make short term exceptions when needed to get things done.

The goals I’m setting myself now are:

  1. Get to bed no later than 11.30pm (Sunday-Thursday…we all need to have a little weekend fun right?) as much as possible
  2. Get between 7.5 – 8 hours of sleep every night (no more, no less)

I think if I can accomplish these two items, I’ll get more done and live a much happier / healthier life.

No Comments

Preventing Parking Tickets in Toronto

At the start of this month Amanda and I moved from our house at Keele and Annette over to our new place on Ellsworth Ave in Toronto. For us this is a great move to a nice tree filled street in an area just steps away from some great places to eat, drink and hang out with friends. Its also pretty close to the subway, so in general life is great!

The only downside to this move has been the loss of a private parking space. We used to have a garage around the back, and street parking was free at our old place. While normally I just parked in the garage, if i did park on the street, on the West side of Keele you can park any time except between 7am-9am and 4pm-6pm during week days on the East side you are only restricted at 4-6pm on week days (both sides are unrestricted on weekends).

At our new place, the street rules are insane. Seriously, they’re at the point where I feel that city is doing everything in their power to cause confusion and drive up ticket revenue.Heres a run down of the situation

  • Firstly you need a permit, no big deal, pay around $60 and you’re good for a few months. However…
  • During April 1st – November 30th, on the 1st to the 15th of the month, you have to park on the SOUTH side of the street.
  • During April 1st – November 30th, on the 16th – end of the month, you have to park on the NORTH side of the street.
  • During December 1st – March 31st, you can only park on the south side of the street.

Sounds reasonable right? Well honestly it is, but check out how its signed…

Less than clear parking rules on Ellsworth Ave Toronto

As I have a “parking permit” i can ignore the 1h parking signs, but seriously, could this not be signed in a clearer way?

So i had to do something about this! Last night I stayed up a bit late and decided to write up a simple program (that i’ve shared on Github) that tells me where I can and cannot park, and then added it to a cron that runs at 5am every morning. The output is a SMS to my phone that looks a bit like this…

I’m planing on sharing this with everyone in my street, no doube they, like me, easily forget when they need to move their car.

 

 

2 Comments

PAYPAL – AMEX- CANADA – GRRR!!!!!$@#@$$~!!!!!!

Universe, I need your help! Here’s my situation:

  • I’m in Canada
  • My customers want to pay with Amex cards
  • Paypal seems to have it in for me

In Canada, when you try pay a merchant holding a “Paypal Website Payments Pro” account…they can only accept Visa and Mastercard. This is so frustrating.

What makes it worse? I went to Paypal for support, here’s what I get…

Paypal support...looks great!

Ok…lets just click one of those links…

what the?

ALL THE LINKS DO THIS! At least call the product “Website Payments fail” so i don’t get all excited next time.

Has anyone in the world managed to solve this problem?

 

4 Comments

Need to migrate your DNS?

This is a super short post but i just wanted to share it because i’m currently doing a DNS migration and finding that validating all CNAME and A records for our domain isnt super easy. Here is how i ended up doing it (You should re-use this PHP!):

//name servers to compare against
$nameservers = array();
array_push($nameservers,"ns1.origionalnameserver.com");
array_push($nameservers,"ns2.origionalnameserver.com");
array_push($nameservers,"ns1.destinationnameserver.com");
array_push($nameservers,"ns2.destinationnameserver.com");

//hosts to compare
$hosts = array(
"hostname1.com",
"hostname2.com",
"hostname3.com",
"hostname4.com"
);

//do the compare and echo out the results
foreach($hosts as $host)
{
//get the results for each name server given the current host
$results = array();
foreach($nameservers as $ns)
{
$result = getDNS($host,$ns);
array_push($results,strtolower($result));
//echo "LOG: $host $ns - $result\n";
}

//see if all the results match
$allmatch = true;
$compare_result = $results[0];
foreach($results as $result)
{
if($result != $compare_result)
$allmatch = false;
}

//check to see if everything matched or not
if(!$allmatch)
{
echo "WARN: $host does not match on all nameservers\n";
$count = 0;
foreach($results as $result)
{
echo "[".$nameservers[$count]."] $result\n";
++$count;
}
}
else
{
echo "INFO: $host OK\n";
}
}

//getdns function to get host name given a name server
function getDNS($host,$ns)
{
$string = '';
exec("dig @$ns +short $host 2>&1", $output, $retval);
if ($retval != 0)
{
return "ERROR_NO_RESULT";
}
else
{
$x=0;
while ($x < (sizeof($output)))
{
$string.= $output[$x];
$x++;
}
}

if (empty($string))
{
return "ERROR_NO_RESULT";
}
else if($string[strlen($string)-1] == '.')
{
$string = substr($string, 0, -1);
}

return $string;
}

No Comments

Route53 – the good the bad and the great

So recently at work we’ve been looking to migrate a few services that are hosted on legacy infrastructure over to a much better set of servers at Amazon AWS. Along the way we hit a few issues, i wanted to share my experience with you so people never have to worry about these issues again…

Issue 1:
When using Amazon AWS Elastic Load balancers you get provided with a host name for the load balancer (not an IP – this is key). This is all good and well but DNS RFC 1034 states that the origin of a domain has to be a A record, but Amazon gave us a host name, so thats a CNAME? Our current DNS provider did not support host names as A records, so this isnt good.

Solution:
Use Route53 at Amazon. Amazon allows you to use their Route53 DNS service and create A records with an “AliasTarget”. These basically setup some crazy round robin DNS setup. There are a few steps to this:

1. Create the HostedZone using the Route53 API. Here is the XML required to create the hostedzone for my domain bitchasscode.com

<CreateHostedZoneRequest xmlns="https://route53.amazonaws.com/doc/2010-10-01/">
 <Name>bitchasscode.com.</Name>
 <CallerReference>dns_migration_amcgrath_20111018</CallerReference>
 <HostedZoneConfig>
 <Comment>Migrate an existing domain to Route 53</Comment>
 </HostedZoneConfig>
</CreateHostedZoneRequest>

2. Create the individual A records and Cnames for the domain using the Route53 API:

<?xml version="1.0" encoding="UTF-8"?>
<ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2011-05-05/">
 <ChangeBatch>
 <Comment>Create record for bitchasscode.com.</Comment>
 <Changes>

 <Change>
 <Action>CREATE</Action>
 <ResourceRecordSet>
 <Name>www.bitchasscode.com.</Name>
 <Type>CNAME</Type>
 <TTL>300</TTL>
 <ResourceRecords>
 <ResourceRecord>
 <Value>bitchasscode.com<Value>
 </ResourceRecord>
 </ResourceRecords>
 </ResourceRecordSet>
 </Change>
 <Change>
 <Action>CREATE</Action>
 <ResourceRecordSet>
 <Name>bitchasscode.com.</Name>
 <Type>A</Type>
 <AliasTarget>
 <HostedZoneId>YOUR LOAD BALANCERS HOSTED ZONE ID</HostedZoneId>
 <DNSName>DNS NAME OF THE LOAD BALANCER</DNSName>
 </AliasTarget>
 </ResourceRecordSet>
 </Change>

</Changes>
</ChangeBatch>
</ChangeResourceRecordSetsRequest>

This is a key step, becsause this is what lets you have a “hostname” as a A record. Sexy stuff…

3. Test your setup, it worked fine for me, however honestly its a real pain in the ass to do all of this. This created a new issue for me, i didnt really trust what I just did…so i started thinking about creating a UI for Route53 so i could easily view my edits.


Issue 2:

There is no UI for route53 provided by Amazon. (Update: There is a UI now :-)

Solution:
Use Interstate53 as your UI, you just need to provide an AWS API key & secret…then you’re done!

Honestly i dont know a lot about Interstate53, other than its very amazing. I tried a few other services which didnt do the job for me:

  • nsRoute (Doesnt do Alias records to ELB’s properly)
  • dns30 (Doesnt do Alias records to ELB’s properly)
  • easydns (They wanted me to signup, pay or something – too hard, i gave up after i couldnt work out how to get an account.)

Interstate53 were super easy to get going with (just provide an api key and secret), there is no registration or anything and their UI is great. It works perfectly with Alias records going to ELB’s and then you’re cooking!

 

2 Comments

I rotate weekly…and i like it!

Its time we all admitted that rotating our log files is something we should get our act together with and do properly. I was a bit surprised how relevant and simple examples were hard to find online the first time i had to do this, so i figured since i just had to install “logrotate” on my Ubuntu server again today that this is a good day to write about it.

Why is this important? Well if you don’t rotate your logs you will suffer from erosion. A massive problem for servers that don’t get a lot of love and attention…and honestly who wants to love a server? If you servers disk space is  filling up with logs, and you are not emptying them faster than they fill up…thats erosion.

The following example tells you how to install logrotate and configure it to rotate your Apache2 log files.

Step 1.
Install logrotate on your server.

sudo apt-get install logrotate

Step 2.
Edit the logrotate config file to tell it where your apache logs are.

sudo vi /etc/logrotate.conf

Add the following to the very bottom of the file:

/var/log/apache2/*.log {
        weekly
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
        create 640 root adm
        sharedscripts
        postrotate
                /etc/init.d/apache2 restart > /dev/null
        endscript
}

Thats great, but what does it mean?

Line by line, this is the breakdown:

1. /var/log/apache2/*.log
This is the path to the logs you want to rotate. I’ve said *.log here, because i want all logs in this directory to rotate
2. weekly
Tells log rotate to rotate these weekly
3. missingok
Prevents us from getting errors if there are no logs
4. rotate 52
How long should archived files be retained before being deleted
5. compress
duh…
6. delaycompress
Sometimes you dont want to compress the file right away, as the app is writing to the logs and will be for some period of time
7. notifempty
Only rotates logs that are not empy
8. create 640 root adm
This defines the file permissions that the archives will be created with
9. sharedscripts
Ensures any prescript or postscript elements of this log rotation are only run once
10-12. postrotate
This section defines what logrotate should do at the end of the rotation. In this case i’ve told it to restart apache, because we want to make sure new log files get created. Even although log rotate renamed the log file, apache will keep writing to the renamed file until its restarted (this is why we included the option ‘delaycompress’)
13. }
end of the log rotation config

ROTATE YOUR LOGS! SAVE YOUR DISK SPACES! OR I WILL HURT THIS RABBIT!

1 Comment

Rogers doesnt like TekSavvy…shock!

So recently (Sunday) we switched from Rogers cable to TekSavvy. TekSavvy offer the exact same deal, only with 240gb EXTRA data per month for $15 / month less (Around $35 in total)

So today (Tuesday) i came home, and Rogers have disconnected our cable…i guess they got jealous? The issue with this is, we now have no service.

From what I’ve been told by TekSavvy and the internet this isnt that uncommon. Rogers…you suck.

No Comments