nazly.me

Weblog of Nazly Ahmed

Nazly Ahmed

Nazly Ahmed

Web Developer. PHP Addict. Wordpress Hacker. FOSS Enthusiast. (Micro)Blogger. Photo Hobbyist. Cricket Fanatic. Husband. Dad.

WordPress is simple, yet powerful. Those are the key ingredients why it is popular among the Bloggers and Web Developers alike. WordPress will always be the first choice as a blogging platform. In the recent times it has moved far from being just a blogging engine. Most Web developers choose WordPress as their primary CMS of choice ahead of other popular Content Management Systems. Regardless of you being a Blogger or a Web Developer, the manner you maintain your WordPress files and database will play an important role in running a successful website.

Maintaining and monitoring your WordPress site requires performing certain tasks on a regular basis. The term regular will depend on how often your Website gets updated. Depending on the frequency you will need to plan this out. If you run a Website that gets updated daily (eg: news), then taking daily backups is a high priority. Performing these tasks manually can become a tedious process. There are plenty of tools and techniques available to automate them.

Monitoring a Website

You might want to use a Website Monitoring Service to check whether your website is up and running. There are plenty of services over the Internet if you Google for it. These services offer monitoring your Web Server (HTTP), FTP, Mail Server (POP & SMTP), SSL, DNS and custom TCP ports on regular intervals. If any of these don’t respond, the service will alert you via Email or SMS. Most of them offer limited options for free while you need to pay based on the additional services you require. This type of monitoring is not WordPress specific and can apply to any Wesbite.

If you are a developer you can code your own monitoring system which will be cost efficient and can be expandable according to your monitoring requirements. Using socket functions and tools like curl can assist in doing that.

In any of the case above, you will need to specify the port of the service you wish to monitor. In certain cases, the port can occasionally differ from the default port that particular service would run depending on how it is configured on your Server. So you need to specify the correct one.

There is one instance that most of the Bloggers/Web Developers fail to address. While your Web Server/Apache might run smoothly, there is a possibility that your database might not respond. This can happen when your DB gets corrupted, privileges get messed up or your MySQL Server crashes for some reason. In this case WordPress will send you this ugly message on a plain white page.

It’s not suitable to show an error message of this nature to your visitors. Most importantly the HTTP status code for this response is 200, which means Search Engines will pick it up as your content for the site. If this message hangs on for long, you will get indexed on Google with this Error Message.

Here is how you can display a custom error message with your design template and get notified at the same time when your DB doesn’t respond.

Create a file called db-error.php and store that file under the wp-contents folder.
The contents of the file should be..

header("HTTP/1.0 500 Internal Server Error");
mail("webmaster@mydomain.com", "DB fail", "Down at : ".date("Y-m-d H:i:s"));
echo "<html>Your customer error message with yout HTML template</html>";

It’s that simple..!

WordPress will execute the above script when the DB doesn’t respond. The first line will send the HTTP response code 500 (Internal Server Error) so that Search Engines won’t index it. The next line will send an email to you, notifying the time the DB went down. Third line will output the HTML of your template where you can include a custom error message. You can extend this piece of code to fit into your needs. Instead of Email, you could use SMS/Twitter to get instantly notified.

Backup

Taking regular backups of your WordPress installation and most importantly the database regularly will help to restore your Website within minutes if any data loss occurs. A hard disk crash, server failure or even a hacker wiping out all your data can be some of the reasons how a data loss could occur. While your hosting provider might do the backup for you, its always good to have your own. If you take regular backups, you are never a loser.

One of the important folders to backup is the wp-contents folder, but I would advise you to backup the whole WordPress installation directory. You will also need to backup the MySQL database. A simple MySQL dump would do. If you are the average blogger, then there are quite a lot of WordPress plugins for backup which would do the job for you. If you have shell access, I would advice you to write a shell script that would backup the files and database. Add a cron job to execute the script based on how frequent you wish to take backups. If you don’t have shell access, you can try using the options in your Web Hosting Control Panel.

Security

When it comes to security, applying the correct patches and upgrading to the newest version of the core and plugins of WordPress will prevent the hackers from trying to exploit the vulnerabilities in your Website. While this can be automated, it is advisable you do this process manually to reduce complications that may arise after an upgrade. It will depend on the plugins you use and the purpose you use it for. Golden rule before upgrade is to backup your WordPress files and DB so that you can restore it if something goes wrong.

Before choosing the right plugin to use, make sure to check the compatibility of the plugin with the version of WordPress you are running. Also make sure to check the ratings of the plugin. All these information is available on the plugin’s page.

Good luck..!!

Posted on 18th November 2010 23:06:45