Installing OpenCart on Windows 2008 server

After deciding not to go ahead with NopCommerce, I was left with 2 choices – either I host the eCommerce website on a Linux server or get it to run on my Windows server. I thought it would be a waste of money to buy separate hosting and therefore I tried to install OpenCart on my Windows 2008 box. Although I managed to install it successfully, there were a few problems I encountered along the way.

The Basics First

OpenCart requires MySql database and PHP to work. If you don’t have MySql installed on your Windows server, then just download the latest version of the MySql Server and run the wizard. PHP was already installed in IIS 7.5 for me as a FastCGI extension. I checked that it was working properly by trying to install WordPress (the popular blogging platform) on the Windows server and it worked flawlessly and the SEO Urls in the htaccess file was automatically translated to Web.Config equivalent (more on that later).

The Install Process

I downloaded the zip file for OpenCart directly on my server and extracted the files there instead of doing FTP as the later was faster. If your domain (for the eCommerce shop) has not been added to your DNS yet, it might be the time to do it now. Then configure the domain in IIS and copy the files from the “upload” folder for OpenCart to the physical directory you want your website to be run from in IIS. Now all you have to do is visit your shop’s url (eg myshop.com) and it will direct you to the installation wizard. If you don’t see the installation wizard, your PHP configuration is not done properly in IIS.

You will need to tick the accept terms for OpenCart and the following screen will show you what dependencies you need and what files/folders need to be written to. I found that I was missing a PHP extension (mcrypt) and I went on installing this before I proceeded. I refresh the page after mcrypt was installed and I was given the green light to proceed. The 3rd and final screen is a form where you need to enter database information like (db name, user and password) and admin details (email/password). Once you hit submit, the installation process begins and it tells you that you need to delete the “Install” folder as soon as possible, otherwise someone might trigger the installation again and overwrite your files and database.

However although it seemed that the installation went through fine, when I tried going to the shop homepage, I was redirected back to the installation screen. This was because the files which were shown as writeable was actually not writeable. The config.php file was zero bytes which means there were no configuration written to it and therefore the index.php file redirects you to the installation page.

To overcome this problem, you will need to give read/write/modify/execute access to the IUSR group and the IIS AppPool\YourAppPoolName to the files/folders mentioned during the installation wizard. I gave the parent directory (the folder where I uploaded all the OpenCart files) these access to see whether it works first. Once it was working, then I deleted the directory, recreated it and assigned the privileges needed only to those specific files/folders. It was good to see the open source ecommerce software working properly on a Windows machine.

Configuring Friendly Urls for SEO

On a Windows box, htacsess does not have any meaning. You would need to translate the rules to what windows understand and for that you will need to make use of the UrlRewrite module and the Web.Config file.


<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 <system.webServer>
 <rewrite>
 <rules>
 <rule name="OpenCart" patternSyntax="Wildcard">
 <match url="*"/>
 <conditions>
 <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
 <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
 </conditions>
 <action type="Rewrite" url="index.php"/>
 </rule></rules>
 </rewrite>
 </system.webServer>
</configuration>

The above web.config is generated for WordPress to use friendly urls. You just need to edit the rules to get OpenCart to have search engine friendly urls. Don’t forget to choose the “Use SEO Url’s” in OpenCart administrative area (System -> Settings -> Edit -> Server).

Say you wanted products to be available at myshop.com/products/product-1. You would need a rule like this:


<rule name="Products">
<match url="^products/[w+]-d+"/>
<action type="Rewrite" url="product/product&amp;product_id={R:3}"/>
</rule>

UPDATE
Scrap what I said above regarding the configuration of seo links. You can just put the following in your Web.Config file:

</pre>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 <system.webServer>
 <rewrite>
 <rules>
 <rule name="opencart" stopProcessing="true">
 <match url="^([^?]*)" />
 <conditions>
 <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
 <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
 <add input="{REQUEST_URI}" pattern=".*\.(ico|gif|jpg|jpeg|png|js|css)" negate="true"/>
 </conditions>
 <action type="Rewrite" url="index.php?_route_={R:1}" appendQueryString="true"/>
 </rule>
 </rules>
 </rewrite>
 </system.webServer>
</configuration>

Then, when you have set OpenCart to use SEO Links, you can get products/categories/information pages displayed in friendly URLs. It’s exactly the rules they have in the htaccess file.