A blend of programming and seo

Successfully Backing up and Restoring your websites on IIS 6.0

There comes a time in every system administrator’s life when they must face a harsh reality. Your company’s webserver has had a major harddrive failure and it needs to be running again as quickly as possible. I came up with a solution that is fairly simple to execute and is hardware independent.

Disclaimer: I have tried the following and it has worked successfully for me, but use it at your own risk.

Steps for backing up (These steps will be done on the original server)

Step 1: Download and Install the iis 6.0 resource kit (link here)

Step 2: We are first going to backup the metabase files for your server. This is a sort of internal registry designed specifically for IIS.

  • Launch the program called “Metabase Explorer” that came with the resource kit
  • Two items can be seen on the left-hand pane. “Lm” and “Schema”. Both of these need to be saved. To do this, right-click on each one individually and then go to “export to file”. To make it easier for restoring, I prefer to use the exact names of each key: “Lm.mbk” and “Schema.mbk”. If you don’t use this naming convention, just remember the file that is associated with the proper key.
  • Now, the actual websites can be backed up. There is nothing special that needs to be done here. The entire website directory just needs to be copied to your desired location. Also worth noting: remember the exact path of your websites directory. IE: “C:\websites” or “c:\wwwroot”. You will need this when restoring.

Steps for Restoring (These steps will be done on the new/target server)

Step 1: Copy all website files from the backup to the exact filepath as the original server (from step 2 part c from above)
Step 2: install the iis 6.0 resource kit
Step 3: launch the metabase explorer
Step 4: left-click on “LM” on the left-hand pane and go to metabase->import key. Then point it to the LM key file that has been backed up.
Step 5: Follow step 4 for “schema”.
Step 6: This step is important, because without it, your websites will be inaccessible. If this step is forgotton, you will see a username/password authentication box whenever someone tries to visit any of your websites.

  • Open up the IIS manager
  • In the left-hand pane, right-click websites and go to properties.
  • Go to the tab that says “directory security”and under “authentication and access control” click on “edit”.
  • The restore process clears these settings, so make sure “enable anonymous access” is checked and an username/password is set. It will not allow a blank password, so a password will need to be set for the anonymous user account on the system username: IUSER_*MACHINE NAME*. This can be done through the administrative user control panel.

You should now have an exact copy of your websites.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

July 10, 2009   No Comments

Using smarty templates

Why use smarty templates?

One of Smartys primary design goals is to facilitate the separation of application code from presentation. Typically, the application code contains the business logic of your application, written and maintained in PHP code. This code is maintained by programmers. The presentation is the way your content is presented to the end user, which is written and maintained in template files. The templates are maintained by template designers.

At its most basic function, the application code collects content, assigns it to the template engine and displays it. The content might be something like the headline, tagline, author and body of a newspaper article. The application code has no concern how this content will be presented in the template. The template designer is responsible for the presentation. They edit the template files, adding markup and bringing it to completion. This typically involves things like HTML tags, cascading style sheets and other tools provided by the template engine.

This paradigm serves several purposes:

1) Designers can’t break application code. They can mess with the templates all they want, but the code stays intact. The code will be tighter, more secure and easier to maintain.

2) Errors in the templates are confined to the Smartys error handling routines, making them as simple and intuitive as possible for the designer.

3) With presentation on its own layer, designers can modify or completely redesign it from scratch, all without intervention from the programmer.

4) Programmers aren’t messing with templates. They can go about maintaining the application code, changing the way content is acquired, making new business rules, etc. without disturbing the presentation layer.

5) Templates are a close representation of what the final output will be, which is an intuitive approach. Designers don’t care how the content got to the template. If you have extraneous data in the template such as an SQL statement, this opens the risk of breaking application code by accidental deletion or alteration by the designer.

6) You are not opening your server to the execution of arbitrary PHP code. Smarty has many security features built in so designers won’t breach security, whether intentional or accidental. They can only do what they are confined to in the templates.

Although application code is separated from presentation, this does not necessarily mean that logic is separated. The application code obviously has logic, but the templates may have logic based on the condition that it is for presentation only. For example, if the designer wants to alternate table row colors or upper-case some assigned content, they can. This is presentation logic, something the programmer should not be concerned with. How often have you had some presentation displayed in a single column and then you wanted it in two or three columns, so the application code needs adjusting to accomodate this? A better approach is to assign the content in one single array and let the template handle the presentation. This will simplify your application and keep your templates flexible. Smarty supplies the tools to handle this kind of situation.

Getting Started with smarty

The first step is to download the smarty template engine Here

1. copy the following to a new file named “smartywrapper.php”

// require the Smarty class
require_once('Smarty.class.php');

// extend the Smarty class
class smartywrapper extends Smarty {

//this will only work with php 5.X
function function __construct() {

// create the Smarty object
$this->Smarty();

// make sure these folders exist and the permissions are set accordingly
$this->template_dir = '/www/example.com/webapp/template/';
$this->compile_dir = '/www/example.com/webapp/compile/';
$this->config_dir = '/www/example.com/webapp/config/';
$this->cache_dir = '/www/example.com/webapp/cache/';
}
}

2. copy the following to a file named “smartytest.php”

// require the new wrapper class we just created from above
require_once('smartywrapper.php');

// create the Smarty_WebApp object
$smarty = new smartywrapper();

// assign a variable, first parameter is the var name, second is the value
$smarty->assign('test_var_1','this is a test');

//display the template file (all html can now be placed here instead of in your php files)
$smarty->display('my_template.tpl');

create a file called my_template.tpl and place it in the directory in $this->template_dir = ‘/www/example.com/webapp/template/’; from above:

This is a test page from smarty, my variable is: {$test_var_1}

launch smartytest.php from your browser and if it is successful, you should see the following

Output

This is a test page from smarty, my variable is: this is a test

Conclusion

Smarty templates can not only be used to increase the overall speed of your php scripts through caching (more about caching can be found Here), but make it easier to develop large-scale applications through the separation of HTML code and php script.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

July 9, 2009   2 Comments

How to get listed in google products

What is google products?

Many people don’t know that google has a search engine designed for products called google products. This service can be used to get more traffic to products on your website.

gproduct logo How to get listed in google products

The first step is to signup with google base. Next, You can start adding your products.

There are a few ways to doing this:


1) one at a time

gproduct one How to get listed in google products

This is the easiest way to add a product. Google provides a step-by-step interface for adding individual products. This works well if you only have a couple of products.

2) Data feed

This format makes it easier to update large amounts of products at one time. Your feed file can be in a variety of different formats: text, XML, or shopping.com/shopzilla feeds.

Here is an example feed (all of these fields are required):

<feed>
<g:condition>refurbished</g:condition>
<g:description>test description</g:description>
<g:id>01</g:id>
<g:link>http://www.mysite.com/product1</g:link>
<g:price>10.00</g:price>
<g:title>my new product</g:title>
</feed>

More information about this can be found here.

After your feed is setup, you can schedule when you want google to retrieve it (daily,monthly, or weekly) by clicking “create” under the schedule column. You just need to specify a link to the xml file (on your webserver).

gproduct schedule How to get listed in google products

3) google base data api

This is an XML based api that allows you to add, update, edit, and remove product information from your feed. More information about this can be found here.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

July 2, 2009   No Comments

5 reasons why oscommerce is a nightmare

What is Open Commerce?

From oscommerce.com: “osCommerce is the leading Open Source online shop e-commerce solution that is available for free under the GNU General Public License. It features a rich set of out-of-the-box online shopping cart functionality that allows store owners to setup, run, and maintain their online stores with minimum effort and with no costs, license fees, or limitations involved.

The goal of the osCommerce project is to continually evolve by attracting a community that supports the ongoing development of the project at its core level and extensively through contributions to provide additional functionality to the already existing rich feature set.”

Why Shouldn’t I use it?

1) no separation of logic and presentation

Smaller applications can be created without separating logic and presentation, but when an application gets as large as oscommerce, there needs to be some kind of templating system in place.
A templating system can also be used to cache dynamic pages and improve the overall performance.A good, scalable system needs to be engineered from the ground up. It looks to me like it was hacked together with pieces of code here and there

2) difficult to integrate into an existing design

out of the box, the cart works fairly well. If you want to make any drastic design changes, you will run into major issues.

Although it is free, and this may be intising to many companies, the time and labor cost of updating the cart to suit your needs ends up being more than many of the commerical carts available.

3) security

a) Although it is updated, #1 makes it very difficult to make updates without having to manually open up each .php file and make the changes yourself.

b) By default, there is no password protection in the admin section. If you are not familiar with apache or basic authentication (which isn’t that secure), anyone can edit/remove/delete your product information.

c) When oscommerce was first built, the latest version of PHP was 3.0. Because of this, old and insecure practices were used to build the core of the system. An example is register_globals. I found a great guide here to run oscommerce without register_globals.

4) cannot have multiple sizes of image previews

5) admin navigation issues

a) hard to do shipping cost per item (with different items having different costs) per country
b) editing product descriptions seems a little awkward. overall, it looks like it was developed for a programmer, rather than a store owner.

commercial

cubecart – http://www.cubecart.com/
sunshop – http://www.turnkeywebtools.com/
miva mercant – http://www.miva.com

open source

interchange – http://www.icdevgroup.com/
magento – http://www.magentocommerce.com/

Another alternative to Oscommerce is a fork of the original project called Zen Cart.

Although it is based on Oscommerce, Zen cart fixes some of the issues above:

  • The admin interface is secured with a username/password, which is encrypted in the database (SSL can also be used for further security)
  • It runs without register_globals by default (no modifications necessary)
  • XHTML template system
  • A more advanced product management system

It is freely available and can be downloaded here: http://www.zen-cart.com/.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

June 29, 2009   9 Comments

Better ways to improve php application performance

Google recently released a document on how to improve PHP performance here. Most of the tips listed here will not help you improve performance by any significant amount. The following is a list of things that you can do that will improve the performance of your web apps significantly.

1) object code caching

Each time a request comes to your server for a php script, it has to go through the compiler and then execute the object code. If this is cached, the 1st step is skipped and you end up with a faster and more responsive script.

There are many object code caching packages available on the Internet:

A) Ioncube: http://www.ioncube.com/

B) Zend Encoder: http://www.zend.com/products/zend_safeguard

2) Template systems

Template systems provide a different type of caching. Content caching. Template systems work well in a situation where there is static data on one or many of your pages that doesn’t have to be reloaded. Caching systems also provide a separation of code and html, which will not only improve completion time of the overall project, but make it easier for future improvments. Most template systems for php are available for free:

A) Smarty Templates: http://smarty.php.net/

B) Pear Templates: http://pear.php.net/package/html_template_it/redirected

C) PHP savant: http://phpsavant.com/yawiki/

3) Distributed object caching systems

The most widely used system of this type is memcached (http://www.danga.com/memcached/).

This type of system makes your overall site faster by caching the majority of your database data into a large memory pool.

more on memcached:

Danga Interactive developed memcached to enhance the speed of LiveJournal.com, a site which was already doing 20 million+ dynamic page views per day for 1 million users with a bunch of webservers and a bunch of database servers. memcached dropped the database load to almost nothing, yielding faster page load times for users, better resource utilization, and faster access to the databases on a memcache miss.”

4) PHP variables that can be set

variables_order = ‘GPC’
register_argc_argv = ‘Off’
register_globals = ‘Off’ (this is a good idea to keep off for security purposes as well)
always_populate_raw_post_data = ‘Off’
magic_quotes_gpc = ‘Off’

Disable Error Logging. This is a good idea to keep on when you are developing your scripts, but it has been known to decrease overall performance.

Use IP addresses, rather than host names to access your database. Although this is sometimes not possible, you will get a slight boost in lookup speed if the IP address is used to access your database rather than its hostname.

5) Output Compression

Almost all browsers these days support something called gzip compression. Gzip compression can decrease the overall size of your output by up to 80%, but with a tradeoff: cpu usage will go up by around 10%. The benefit of using this compression type is the fact that not only will your bandwidth be decreased, but your pages will load faster.

enabling it in php (add the following lines to php.ini):

zlib.output_compression = On
zlib.output_compression_level = (level) (where level is 1-9. Youy may want to try different values to see what is best for your system).

if you are using apache, you can also enable the mod_gzip module. It is highly configurable, with the ability to modify output based on MIME types, files, or browser settings.

6) Other things that may help

when using a database, only retrieve the data that you are actually going to use. This may sound like a no-brainer, but I have often times worked on projects where the original programmer used (select * from mytable) when they could have used (select fieldIneed from mytable).

index database tables whenever possible

Learn more about this Here

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

June 25, 2009   13 Comments