Hosting Magento Images on an External Web Server

I’ve been interested to know for some time if it might be possible to host the product images of a magento website on an external server. The server I’m using to host a magento site (acting as both web and database server) is coming under ever increasing load, despite having some upgrades, and putting plenty of caching in place.

The medium/long term solution is to upgrade the infrastructure, but I’m interested as an interim step whether it might be possible to move the hosting of the imagery to a 3rd party cloud solution (like Amazon web services) to take some of the load/traffic off the magento server, and improve the performance and experience for customers visiting the site.

Signing up to AWS (Amazon Web Services) is a pretty straight forward affair. The EC2 Service (Amazon Elastic Compute Cloud) allows you to create a server instance in various locations around the world (Dublin being the closest to the UK). You can choose from different Amazon Machine Images (AMIs), which offer different performance levels and operating systems.

As part of the set-up of the instance you create ssh certificates which allow you to ssh/scp/rsync to/from the server. There are also a few other settings to adjust:

Security groups – these allow you to choose which ports are open (and from where)

Elastic ips – these allow you to create a static ip, which can then be pointed at your server instance (when you stop/terminate an instance its hostname and ip address changes each time it’s started again).

I tarred up the /media directory of the magento site, and scp’d it across to the new server instance…

scp -i **location of key file** media.tar ec2-user@**ipaddress of AWS instance**:**location to place file**

I started apache on the new server instance, and untarred the media directory into the web root, so it has a /media directory with all the various sub directories.

When a customer requested a product image from the live web server I want apache to tell them to go off to the AWS server to download the image. This is achieved by editing the .htaccess file on the live server within the media directory, and adding this entry…

RewriteCond %{HTTPS} !on
RewriteRule ^(.*)\.(jpg)$ http://**AWS IP Address here**/media/$1.jpg

Basically this says that if a jpg file within the media directory is requested (on a non https request) then redirect the browser to get the image from the AWS server instance. The $1 contains any sub directory location path. I wanted to only redirect http requests because the AWS instance doesn’t have a SSL certificate and this might cause alerts when customers were using a secure connection to the site.

To keep the AWS server instance imagery up-to-date I set up a cron job on the magento server to regularly update any changes using rsync…

rsync -vazOe "ssh -i **path to key**" **path to media directory on magento server** ec2-user@**ip of AWS Server**:**path to media directory on AWS server** -u --exclude ".htaccess"

I monitored the apache access and error logs on the AWS server instance to make sure all the images were getting requested ok, and all looked good. Amazon charges using a credit system based on use, so I’ll have to keep an eye on the bills – but so far so good.

ebizmarts Sage Pay Suite PRO, Error: MALFORMED. 3055 : The CardType field is required.

Having recently introduced the ebizmarts Sage Pay Suite PRO integration to hook a magento website up to Sagepay, using the direct method I was periodically getting the error “Error: MALFORMED. 3055 : The CardType field is required”.

After a bit of detective work, I believe this error is getting caused by:

a) The customer going through the onepage checkout, entering their payment details and checking out. They are then passed to their providers 3D secure page. They somehow get back to the website (possibly back button) because the page hasn’t loaded or an error. When they go through the checkout for the second time the payment method is already selected (on the radio button) but the details have cleared (and the form is hidden). They can click continue (probably assuming the details have been stored), but they won’t get passed to the 3D secure page, and instead get the error “MALFORMED. 3055 : The CardType field is required”.

b) They’ve almost completed the checkout (including the payment details), but then exited the checkout perhaps to edit the basket. When they go back to checkout, again the payment method is now pre-selected but the details have cleared (and the form is hidden). They click continue (again probably assuming the details have been stored) but they won’t get passed to the 3D secure page and instead get the error “MALFORMED. 3055 : The CardType field is required”.

I’ve fixed it by removing the default checked status of the radio button in:

Basically removing: checked="checked", so if the customer returns to the payment screen no payment method is pre-selected, and they then must select a method to continue. The payment form appears and it must be filled in, and so the error shouldn’t occur.

Chartwell Visit

We visited Chartwell in Kent at the weekend, the house where Winston Churchill lived with his family for most of his adult life. It’s now a National Trust property, and the house, studio, gardens and estate are open to the public for part of the year to visit. The layout of the house was how it would have looked during the 1920s, and the studio has a display of many pictures painted by Churchill himself. I can definitely recommend it as somewhere to visit, and hope we can go back in the summer when it will be a better time to see the gardens.

2014-10-18 15.28.03

2014-10-18 15.30.35

2014-10-18 15.54.14