Colocation Services



             


Friday, April 24, 2009

What Is A Data Center?

Why is it important to have a data center for that matter? A data center is a facility that will house a good amount of the electronic equipment (and information) that a business or group has and needs. There will be computers and communication elements in this area as well as a number of other vital components to keeping the business running smoothly. What is essential about a data center is security and maintenance.

Companies may have more than one data center as well. Most mid size or higher companies will have at least one data center though. There are many types of data that can be stored in these centers. For example, a financial institution will maintain their clients accounts, numbers and activities in the data center. Businesses will keep client names, accounts, and projects in a data center as well. Because the data a business has is so very important to their existence and their performance, turning to a data center is an excellent option for this type of storage need.

Inside of a data center you are likely to find various types of computers, internet servers as well as many other items. To keep these items safe, data centers are often built and secured physically as well as logistically to protect them. Security is extremely high. They can be one of the safest environments in the city. The main job of a data center is to maintain and run applications to allow businesses to access and manage their files effectively.

There are many information portals now devoted to the subject and we recommend reading about it at one of these. Try googling for “data center info” and you will be surprised by the abundance of information on the subject. Alternatively you may try looking on Yahoo, MSN or even a decent directory site, all are good sources of this information

Get more info at Data center site.

Labels: , , , , ,

Tuesday, April 14, 2009

Four Power System Problems Common in Colocation Facilities

The primary factor that determines uptime for servers in a colocation facility is power. Power outages will knock a network offline and even damage hardware such as motherboards, memory, and hard drives. Despite how intrinsic power is to keeping businesses connected to their networks, only 2% to 3% of colocation facilities have the right power systems in place. The other 97% of facilities most commonly lack redundancy, multiple units carry the energy load even if one unit fails, or have units that are running above capacity, so a unit failure will cause the other units to overload and fail. Every part of the power system – uninterruptible power supplies (UPS), transfer switches or circuit breakers, generators, and power distribution units (PDU) – should be redundant and running below capacity.

Problem 1: Non-redundant Power Grids
Multiple PDUs connected to separate power grids and multiple UPSs should be designed into the colocation facility to offset a power grid failure. Colocation facilities with redundant power grids can connect customer servers to different grids at the same time, so that even if one goes offline, the other will work, keeping the network running without interruption.

Problem 2: Non-redundant UPSs
The UPSs supply power during an outage until the generator can come online; if the UPSs do not turn on immediately at the time of failure, then the network will go down. Even with high quality UPSs, failures are common, so it is critical for there to be multiple redundant UPS units in an “n+1” configuration – all of the necessary UPSs, plus an extra. Functionally, this means that each UPS runs sufficiently below capacity to handle a unit failure without the other units overloading. If there are two UPSs, then each unit must run below 50%, so that if one fails, the other can continue without overloading. If there are three units, each must run below 66%; four units, below 75%. The current load is shown on the display on the front of the UPS.

Problem 3: Transfer Switch Failures
Most colocation facilities use mechanical transfer switches, which are not as dependable as circuit breakers, to switch power from the electric utility to the generator. These switches are one of the most common places the power system fails. Without redundant switches to transfer power at the same point, a transfer switch failure will mean that a network goes down.

Problem 4: Insufficient Generator Capacity
Generators supply power during an outage. To run without overloading, the generator must have capacity to run 1.5 times the total building load. Ideally, a colocation facility should have a redundant backup generator in case the primary generator fails, and the facility should have a process in place for switching power between generators. Having multiple generators is not the same as having redundant generators. One of the most common generator problems with colocation facilities is that the facility started out with a small generator and added generators as it grew. This creates multiple points where power has to be transferred during an outage, increasing the likelihood that a network will go down. As a practical consideration, the generators must be well-maintained, tested monthly, and fully supplied with fuel.

Points to Consider
Fewer than one in twenty colocation facilities have the best power systems in place despite the fact that power systems have the most impact on network uptime. Without well-maintained and redundant components running below capacity at every part of the system, network performance as well as server performance and equipment lifetime will suffer. To make sure that the power system at a colocation facility is robust enough to handle power and equipment failures, two words should be remembered: capacity and redundancy.

American Internet Services is the premier San Diego colocation service provider with state-of-the-art Internet data center technology. http://www.colocation.ccccom.com

Labels: , , ,

Thursday, April 2, 2009

Setting up a Web Server - An Easy, yet Misunderstood Step to Hosting your Website from Home

You might be trying to decide whether you want to host your website yourself rather than pay a hosting company. Maybe you just want to learn how it is done, or you want to save some money by doing it yourself. In this article I'll discuss the most important part of hosting your website from home, the web server.

The word "server" sounds scary and because of this many people think only a professional hosting company can host a website. This is not true. A server is nothing more than software that runs in the background listening to requests from "clients." The client in our case is an internet browser, like Internet Explorer.

How do you get a web server? Most Windows operating sytems come with a web server that just needs to be installed. There are also web servers than can be downloaded for free, like Apache. I'm not going to go over how to do this. In this article I'll discuss the concepts and what's needed to get your web server up and running and serving your site to the public after it's been installed. Every web server is different but the concepts are the same. By going over the general concepts that are true for any web server, you'll know what to look for regardless of the software you are using.

Like I mentioned before, a server is just software that runs in the background. A web server is a server that listens to requests from internet browsers for a specific page, finds that page in the computer it is running on and then sends it to the browser that requested it. Keeping this in mind, can you believe there are actually just two things you need to do to have your web server configured?

1) Tell your web server where to find your web site. Your website probably consists of multiple pages. You need to tell the web server the path of the folder where you keep your pages. For example, when someone types www.yourdomain.com/main.html, the server will look in the folder where all your pages live, and look for file main.html.

2) Tell your web server about your default page. This is the page that is displayed when someone types www.yourdomain.com in their browser without specifying a page. The web server already has some default page names like "index.html" so if you have a page with this name it will be displayed by default when no document is specified in the request. You may also add some more default file names to your web server. If you don't want to name your file "index.html" you can tell your web server that your default page's name is "mainpage.htm."

This is basically all there is to configuring your web server. Actually, there is more, but these two steps will allow your web server to start serving your website. Of course, there is also more to hosting your website from home, like getting a domain name, dealing with your router if you have one, but these topics are beyond the scope of this article.

I hope I've convinced you of how easy it is to set up a web server, which happens to be the most important step to hosting your website from home.

For more information on hosting your website from home please visit Setting up a Web Server and Getting your Own Domain Name

Labels: , , , , , ,

Wednesday, March 25, 2009

Hosting Your Own Web Server: Things to Consider

p>Are you disgusted or disappointed with your current web host? Have you switched web hosting companies too many times? Have you thought of hosting your own website(s)? Do you have the ambition to control and manage your own web server?

If you answered 'yes' to the questions above, then you may be ready to host your own sites. This article will give you things to consider while making the switch.

When being your own web host you should be technically inclined and have basic knowledge of operating systems, understand technical terms, understand how to setup a server environment (such as: DNS, IIS, Apache, etc.) have basic knowledge of scripting languages and databases (PHP, Perl, MySQL, etc.), be familiar with current technologies, and have a basic understanding of hardware and server components.

You should realize the pros & cons. It is one thing to say, you want to host your own web server and it is another thing to actually do it.

Pros:

Own sense of responsibility
Awareness level raised (you are at the frontline of all server happenings)
No monthly hosting fees/accounts
Incompetence no longer exist
Non-shared environment (dedicated server)
Unlimited websites, databases, content, storage, etc.
More bandwidth
No more waiting on someone else time
Complete control

Cons:

Exhausting at times
Faced with server/hardware problems
ISP business account (monthly business/broadband expense)
If server goes down then the website is offline
No technical support team
Software, hardware, and network expenses

There could be many more pros & cons but I’ve pointed out some of the major ones. Managing a web server starts as a full time job, you must constantly monitor its performance and security. This can sometimes be an exhausting task, especially if you currently have other responsibilities. Though, the control you will have over your website and its performance is rewarding enough. You no longer have to wait for technical support or approval to install a script onto the server. You can have as many websites and databases you want, as long as your hardware can handle it. You no longer have to go into the discussion forums and search for the best web host or rant about how much you hate your current host. You can even begin hosting family & friends personal websites.

Ask yourself, how technically advanced are you? Many times you do not have to be a tech guru or anything of the sort, but you must be very resourceful. You must know how to find resolutions and answers to problems, quickly and efficiently. This means you must be internet savvy. Not just the average surfer, who surfs aimlessly, but you must be the surfer who can always find what they are looking for. This is key, because with any server environment you are going to run into problems and finding the answers are most accomplished online, using multiple resources, search techniques, and engines. Sure you can hire someone to fix your problems, but as we should have learned from the "web hosting", having someone do it for you isn't always the best option. Here is a test to see if you are ready to find solutions. I need a solution to a Microsoft Windows 2003 Server Event Error - "Event ID: 1056” it’s a DHCP Server Error. How would you search? Go ahead find the solution.

Did you first go to Google? If you did, that was a nice effort and common for most, plus a good place to start, but usually it is best to start at the developers' website. In this case "microsoft.com" would have been the first option. Why? Google would more than likely provide you with the answer from Microsoft and other sources, but you don't want to get inaccurate information from other sources. It is common to get information from Microsoft that would not specifically resolve your problem, but the developer should always be your first place to search for the answers. Now search the error again and go to the Microsoft site and find the solution.

You should had found this link: http://support.microsoft.com/default.aspx?scid=kb;en-us;282001 (Event ID 1056 is Logged after installing DHCP)

What search phrase did you use? It should have been Event ID: 1056, because the Event ID is the exact error, it pinpoints your exact problem without broadening your search. Sometimes the error description is also appropriate to search, just the error description by itself or in combination with the Event ID. It depends on your error, your search feedback, your ability, and technique. For this example I did not include the error description.

Google or Yahoo! should have been your second option (the two largest search engines). Then search other smaller and niche search engines. A good search site which makes use of Google’s operator tags is www.soople.com. Next you should search within forums and discussion groups. If you are pretty internet savvy and have a plentiful or few forums and discussion groups which you frequent then you might actually visit those places before visiting Google or Yahoo!. You can even visit those before visiting the developer site since it is a trusted source, but I wouldn't recommend it, I still would go to the developers' site first. Okay, so now we have planted our feet and have familiarized ourselves with being internet (search) savvy. We are ready to purchase a server!

When making a server purchase you need to consider a few things before doing so. What to buy? A top of the line, quadruple processor, and super fast turbo server is always ideal, but many times it is not logical or affordable. Therefore, you need to weigh your options (sensibly).

What to buy?

First determine your budget. Be realistic and expect to spend at least $2,500 for a low-end server. For a low-end, quality server with other needed equipment and services I spent a little over $4,500 easily.

Determine your ISP (broadband) provider. Research and speak with several different vendors before deciding which broadband solution best suit your needs. Each provider plan is different and has different benefits, determine the best one which fits your needs. Bandwidth should be put into consideration when choosing your ISP.

A backup device should be purchased before implementing a server install. The backup device should be double the server storage space. This could be a standalone unit like an external hard drive or network storage device or the backup device could be multiple devices such as: backup tapes, disc, etc. The reason the backup device should be larger is because you want to be able to have months worth of backups and not just weekly or monthly backups. You should have at least 24 weeks of backups without the concern of storage space. The backup device or safe deposits should also be external, removable, and portable. This is so the backups can be stored in a remote location. Usually for safe-keeping, in event of a theft or disaster.

Determine your daily traffic goal (the daily traffic which you hope to see within 1 year – be realistic), divide that number by the daily traffic you currently receive, and then multiply that number by 5. That is the total number of GB space you need. Example:

Daily Traffic Goal: 10,000 (Divided by) Current Daily Traffic: 500 (Times X) 5 = 100GB

In the example you should purchase a 100GB Hard Drive, it is best to buy 2 or more drives oppose to 1. In this case, since 50GB drives do not exist or harder to find, you would buy two 60GB drives giving you a total of 120GB. 2 or more drives are usually needed in a server to configure the proper RAID option, in some cases 3 or more are needed. Your backup storage space should be a minimum capacity of 200GB (or 240GB, optional).

Determine your memory. If your web server daily traffic goal is 500,000 then I would recommend at least 2GB worth of memory. If it is a shared server, meaning it also has other server services running on the machine, especially a mail server or database server (which is not recommended) then your memory should at least be 3GB or more. Otherwise you can think small and upgrade as needed, a 1GB memory stick should be fine for starters.

Determine your network components, which NIC card best performs under high traffic levels and which router best performs for your LAN / web server. It is best to get a router which has a built-in firewall (commonly known as a “hardware firewall”). Your ISP may provide you with a router or hardware firewall, this is how they are able to authorize your traffic on their network. Like a cable box does for cable television. The router also shares your IP address with other clients on your network. This enables you to share your internet connection without having to get a different IP from your ISP. The hardware firewall is simply a router with a built-in firewall, which means it shares your IP address as well as provides added protection to your network. It blocks bad addresses and ports at the forefront, before it can even make it to your computer. It is not recommended to rely only on a hardware firewall for security, this is just the first step. It is recommended to also include a software firewall (firewall software which installs on your computer) and it is recommended to continue timely security practices, such as updating and patching your system on a scheduled routine.

Determine your processor speed and power. Regardless of the amount of traffic you are expecting I would recommend a dual processor or greater. A dual processor or greater is best because if your website unexpectedly take off then you will be well prepared and if you host other server options or websites on the same server then you will have better performance. At the time of this writing the 64-bit platform is the processor direction. 3.8GHz is the most available speed. If your pockets can afford the latest technologies then that is ideal, but keep in mind at this particular time a 64-bit compatible processor is not necessary, without having many applications that require or deliver on that platform. That is a lot of speed going no where fast. Also, remember the power of the 64-bit platform and the greater the processor speed the more heat it produces, therefore it must be cooled much more rapidly and efficiently. At this time a dual 32-bit, 2.8GHz – 3.2GHz processor will suffice (even that is way more than enough). Though, if your pockets can afford it then the latest and greatest would be fine, you will be well prepared. Otherwise, do like most people and upgrade when the time comes.

Make sure you have a CD/RW drive. A floppy disk drive is not needed, but I do recommend it for making system restore disk. The CD/RW drive is needed because you need some type of removable storage device. You never know when you need to install a driver from a different location…like a ethernet driver. An external CD/RW drive is the best option, especially if you have multiple machines.

Choose your operating system carefully. Choose the vendor which you are most comfortable with. Do not choose a MAC if you never used a MAC before. Just because your friend suggests it and says it is a piece of cake does not mean it will be for you. You are trying to get a web server online not re-learn a whole new system. Stay focused and grounded. If you are comfortable with Microsoft then go with Microsoft, regardless if the IT person at your job says Microsoft products are unsecure, Linux or Unix is more secure and much better for a web server. If you have never used Linux or (especially) Unix then you will be in for a ride of your life. Your web server experience will soon become a nightmare and you will have wasted thousands of dollars on equipment. Go with what you know, not what you are told. Each platform has its pros and cons: Microsoft is the user-friendly of them all; Mac is the web/graphic developer of them all; Linux is the open-source/developers paradise of them all; Unix is the most secure of them all. Each of them can be tweaked in ways to provide a solid, quality platform, it is best to stick with what you already know.

You should install on your system all the web services (such as: Apache, IIS, etc.), applications (such as: backup device software, RAID (Array) Manager), scripting languages (such as: PHP, Perl, etc.), CGI, Database (such as: MySQL, Microsoft SQL, etc.), and a web log analyzer (such as: weblog expert, nihuo, etc.). It is also recommended to perform system updates, security patches, and firewall installs and configurations. It is sometimes best to leave the security installs and configurations for after you have the system functioning properly to avoid any uncalculated problems. This way when you install the firewall and something stops working properly like connecting to your website from outside your network, you can troubleshoot assuming that it is the firewall, therefore you would begin by opening port 80 on the firewall. This method can save you a lot of hassle, but can sometimes be considered the unsecure method, especially if you don’t have a hardware firewall already in place.

Next, there are a few things to consider before installing and configuring a server. Where to put it? A secluded, cool location is ideal, but if this cannot be accomplished then adjustments can be made.

Where to put it?

Locate a location within your home that is static-free, we do not want to put the server on the carpet, near curtains, or anything else that can produce a static reaction. The reason for this is that you do not want the server internal components to receive a static charge and short circuit.

The location should be a cool environment, preferably below room temperature. The reason for a cool area is because servers (as well as desktop computers) produce large amounts of heat, the more heat it produces the more it needs to cool off. If the server is not kept cool, then this can lead to the server hanging and then eventually crashing. It's the same result of when a car overheats, it stops running. You can keep a server internal components cool by keeping the room cool, additionally you can add more fans to the server which cools the server internal components, you can also position a standalone fan directly at the server back panel and constantly have the fan cool the server internal components. Depending on how cool your room is and how much heat your server produces, getting more fans for your server may be a must and not an option.

It is suggested that the server is at a higher level within your house (mid-floor), because if it is in the basement and a flood occurs it could ruin it. If it is in the attic and the sun beams on the attic for hours the server could overheat. Mid-floor level is usually the cooler place within the home, but these recommendations is optional and you should put the server in the most comfortable and convenient space following the rest of the guidelines.

Be sure the area you choose is not damp or wet (no leaks, moisture, near any liquids, or near a window “especially open”). We all know what can happen when electrical components get wet.

The server should sit at least 4” inches from the ground

Be sure a working electrical outlet is near. It is an important to have a power supply, a good brand is APC. Having a power supply can save you from electrical outages, blackouts, and brownouts. Having a power supply helps the server keep its power, remain stable, and unaffected when there is an outage, as well it protects your server against electrical shock. If your outage remains more than 5 minutes it is recommended to begin backing up anything deemed important and shut the computer down voluntarily as well as any other electrical attached devices.

Have a LAN line near and also a phone jack (if you plan on using the server for any dial-up services). It is not recommended to use your web service with a dial-up connection. A broadband connection or greater is recommend for optimal performance. The LAN line should never come from your wall and plug directly into your server, it should plug into a hardware firewall (usually a router with a built-in firewall).

Depending on the size of the server and the internal components the server may be extremely noisy and loud, especially with the fans going. It is suggested to have the server in a secluded location which is not near any peaceful area of the house, such as: bedroom.

Those are all some basic things to consider before hosting your own server. Hosting your own server is not an easy task, but once you have had some time and experience with it, it becomes a breeze. You will have a better web hosting experience, you will be more in tune and reliant to your customers, and you will gain greater technical aptitude. Hosting your own web server is rewarding, useful, and gives you the opportunity to host unlimited websites, databases, services, etc.

If your web traffic becomes too great for your server then it is recommended to choose an offsite web host. It is recommend to purchase a dedicated server with a quality web host. If you choose a server with the above recommendations then your server traffic should be fine for at least up to 25,000,000 page views per month. It could be greater or less depending on your operating system, your server configuration, performance, applications, and services. The point is you should be well in a position to purchase dedicated server space by the time your traffic gets too high, because if you are getting anything close to 1,000,000 page views a month you should have some competitive advertising or ecommerce income. And plus, with the knowledge you will gain from the experience you will be able to support your own server at a dedicated server (remote) location, thus cutting more overhead.

The biggest disadvantage of hosting your own web server is the uptime reliability. If your web server powers down for any reason then your website is offline. Usually web hosting companies have methods and networks to prevent this failure from affecting your website. Usually if the system goes down they have a mirror location where your site is rejuvenated and doesn’t experience much downtime. Some web hosts do not practice this method or any other fault tolerance. Imagine if a blackout or power outage occurs, then your web server could be down for hours or even days, this can affect your business greatly. There are some hosting companies who provide mirror web hosting for a small fee, I haven’t found one that is reliable yet. Or you could cross your fingers and hope for the best, until you are able to host your server outside your home on a larger network.

Hosting your own server usually is not a money-saving experience. It sometimes cost more to host your own server, when you total the up keep and maintenance. The benefit of hosting your own server is usually a better platform for your customers, because it is no longer a shared server and it gives you the ability to make global changes almost instantaneously. When your customers request more performance or specific applications, then you will be able to implement this immediately. Customers like to know that you are in control. If you tell your customers that the server will be down for maintenance from 6 a.m. – 7 a.m. then it would be best if that is when your server is down, not from 5 a.m. – 10 a.m. You know how your web host will tell you one thing and then you have to try explaining it to your customer. In the end it will benefit you to host your own web server as a web business, this helps you and your customers.

About The Author

Ant Onaf is the owner and founder of http://www.JournalHome.com He is an online internet marketer, content writer, and IT consultant. Ant Onaf has years of IT-related experience and Internet-related experience. His ingenuity, dedication, and passion for technology, internet marketing, & writing have made him a monumental icon in the World Wide Web. His blog can be visited at http://www.journalhome.com/AntOnaf

Labels: , , , , ,

Thursday, March 19, 2009

Select a Web Server Dedicated to Your Success

If you have a successful online business, you might want to consider looking for dedicated web hosting. The dedicated web hosting gives you the opportunity of having an entire server at your disposal, and that server is not shared with anybody else.

Even for a person who doesn't know too much about servers, the advantages are clear right from the start: you, as the webmaster, have full control over YOUR OWN server, including options of what operating system to use, the type of hardware, etc. You can customize everything according to your own personal desires, while the administration is handled by the hosting company.

The most important advantage of using an online dedicated web hosting is that your website performance (like loading time, which is an important factor for your visitors) will not be affected by the traffic of the other websites with which you would have been sharing your server's bandwidth.

The online dedicated web hosting environment provides you with an exclusive server or servers devoted to the sole purpose of serving yourself and your business only. You do not share hard disk space with other customers, and you avoid shared hosting.

Before dedicated web hosting existed, a web site developer used to have two hosting options, the low-priced shared hosting model and the premium-priced dedicated web hosting. A person who bought space on a shared host would get a certain amount of disk space and monthly transfer, and would have the web site served from a common web server.

The hosting company, in its' attempt to increase the popularity of their products, would provide a wide range of options for the web site developer. But, limitations would still be there. For example, if a customer needed a non-standard program installed or maybe wanted to use a privileged account in order for a particular utility to run, he would be completely not be able to achieve these goals.

A good example would be a web site which required a database to store the precious information in. Many hosting companies provide the standard MySQL database to use on their servers. If your application requires another type of database though, then it could prove to be incompatible with the shared hosting account. And trust me, databases are a very important element in the success of your internet business.

A dedicated web server can be customized anyway you want. But, there's also a catch. Because it can handle much more traffic than a shared hosting account, the far better performance doesn't come cheap. On average, dedicated web hosting can cost the savvy webmaster hundreds of dollars per month depending on the size of the server, network connectivity and the amount of management required from the hosting company.

Webmasters who don't quite fit into the standard shared hosting model and find that it doesn't work for them, or whose sites grow very popular and require a large amount of resources have the alternative of dedicated web hosting.

Reliable, affordable dedicated web hosting service
Dediated web hosting.
http://www.dedicatedwebhostings.com
More tips and advice on web server selection

http://www.webhostingbin.com

Labels: , , , , , , , ,

Tuesday, March 17, 2009

Dedicated Server vs. Co-location Web Hosting

So - you know shared hosting no longer cuts it, and your single office connection is not enough to host a web server - so which is best, leasing a dedicated server or buying your own server and co-locating it someone's data center?

Difference

For those that are unsure of the difference, here it is in a nutshell. When you co-locate, you are simply renting space within someone else's facility to store your own server or servers. It's like a high tech gym locker that you are renting all or part of to house your servers. You either ship or deliver your server to your provider. Additional services provided with co-location vary from host to host but it certainly won't include the actual server. With a dedicated server you are getting all the features of co-location, plus the actual web server itself.

Which is better?

While it certainly depends on your particular needs, and there are excellent situations for both the dedicated server option is quickly becoming a better choice in more and more cases. If you already own a web server, or cluster that you prefer to use, then obviously co-location may be your best choice. If you are considering buying new equipment and shipping it off for co-location - please reconsider. The prices and equipment available in dedicated hosting these days are outstanding plus relieve you of the burden of hardware. Most hosts keep identical spare parts on hand for the types of servers used and are quick to react if something fails. Depending on your arrangement with a colocation deal hardware failure could mean paying to have a server shipped back (or you drive to get it), having it fixed yourself then sending it back to the data center.

Labels: , , , , ,

Monday, March 9, 2009

Running a CGI Script on a Web Server

For many years I have been writing Perl scripts to process ASCII files of one sort or another on my computer. I typically do this when I need to reformat or tidy up a series of HTML pages, for example.

To run a Perl script that is installed on your computer, which needs to process one or more files on your computer, and where the Perl interpreter is also installed on your computer, is very simple - you just need to double-click the perl script and it does the business - assuming that everything is set up correctly of course, for example, the location of the perl.exe program is defined in your path. You can also open a DOS window and type perl perlfile.pl to run a script (where perlfile.pl is the name of the Perl script you want to run).

However, when it comes to running a Perl script, or CGI script, on a web server, things can be a bit trickier - not too tricky, but a bit trickier.

In this article I'll look at two versions of the same script: one that will run quite happily on a local machine (by double-clicking the script, for example), and one that will run on a web server.

The script itself is very simple - it opens a file, changes some text inside the file, and then saves the file under a different name.

Version 1 - the local version

Here is version 1 of the script. This is the version that will run locally on a computer, without a web server is sight. Note that I've inserted spaces at appropriate places to prevent the code from being processed by your browser. I've done this wherever necessary in this article.

localScript.pl

$name = "before.htm" or die "cannot assign to variable: $!";
rename $name, "$name.bak" or die "cannot rename: $!";
open (IN, "<$name.bak") or die "cannot open: $!";
open (OUT, ">$name") or die "cannot create: $!";
undef $/;
while ($line = < IN >) {
$line =~ s/hello world/goodbye cruel world/s;
(print OUT $line);
}
close (OUT);
close (IN);
rename "before.htm", "after.htm";
rename "before.htm.bak", "before.htm";
 

This script opens a file called before.htm, uses a regular expression to change the string 'hello world' to 'goodbye cruel world', and writes the contents to a file called after.htm. If after.htm does not exist, it is created.

The file before.htm simply contains one line - hello world. So it's not even a proper HTML file in fact, but that doesn't matter for this exercise as it's the script that's important, not the file that's being processed.

Version 2 - the web server version

Here's the web server version of the script. It contains everything that's in version 1, plus a bit more. Again, I've inserted spaces where appropriate to ensure that the code displays correctly in your browser.

webScript.cgi

#!/usr/bin/perl -w
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
warningsToBrowser(1);
use strict;
print header;
my $name = "before.htm" or die "cannot assign to variable: $!";
rename $name, "$name.bak" or die "cannot rename: $!";
open (IN, "<$name.bak") or die "cannot open: $!";
open (OUT, ">$name") or die "cannot create: $!";
undef $/;
my $line;
while ($line = < IN >) {
$line =~ s/hello world/goodbye cruel world/s;
(print OUT $line);
}
close (OUT);
close (IN);
rename "before.htm", "after.htm";
rename "before.htm.bak", "before.htm";
 

A couple of initial points to note:

1. Why does the script have a .cgi extension instead of a .pl extension? CGI is an abbreviation for Common Gateway Interface, which is a specification for transferring information between a web server and a CGI script. So CGI iteself is not a language, but CGI scripts can be written in a number of languages of which Perl is one. If you write a Perl script with a .pl extension, and then change that extension to .cgi, the script becomes a CGI script, and providing it conforms to the CGI specification, it will run on a web server.

2. If you call this script webScript.pl it will run without any problems on a local disk - just as version 1 did. That's to say, all the extra code will not prevent it from running locally.

Ok, lets go through the script line by line to see what's going on.

Running the script

To run the script you need to first upload the script and the file before.htm into the cgi-bin directory on your web server. On your web server the cgi-bin directory might be called something else, but it will probably be recognizable as the place where cgi scripts need to be located.

By default, when you upload a file onto your web server it will probably have permissions of 644. You need to change these to 755 so that the script can be run by anyone. Your ISP should provide you with a way to do this. If not, contact me at john@dixondevelopment.co.uk and I'll send you a script to change the permissions for you.

Once you have uploaded the files and changed the permissions, all you need to do is browse to the script in your favorite browser. If the browser window is blank, then everything has probably worked OK. Check in your cgi-bin directory to see if the file after.htm has been created and that it contains the words 'goodbye cruel world'.

About the Author: John Dixon is a web developer and technical author. He enjoys developing database-driven websites using PHP, Perl, and MySQL. John is also interested in anything to do with computer history. Visit http://www.computernostalgia.net/listDocumentsOutline.htm to see the current list of computer history articles on his site. To find out more about John, visit http://www.dixondevelopment.co.uk.

Labels: , , , ,