Tuesday 31 May 2011

How to fix the Adobe Acrobat "Save As" error


The Problem: You attempt to save a dynamically generated pdf built from a website and get the error “The document could not be saved, a number is out of range”
The Cause: Incompatibility of settings between the version of Acrobat that created the pdf and the version of Acrobat that is being used to view the pdf
The Solution: Go to preferences, go to “General” and uncheck “Save As optimizes for Fast Web View” and see if that fixes the problem. 

How to fix the 550 #5.1.0 Address rejected email problem


he Problem: All email that you send get’s bounced back with the following message:
Subject Line: Delivery Status Notification (Failure)
Message: Delivery to the following recipient failed permanently:
user@domain.com
Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the recipient domain. We recommend contacting the other email provider for further information about the cause of this error. The error that the other server returned was: 550 550 #5.1.0 Address rejected user@domain.com (state 14).
The Cause: There is no “mail.domain.com” in the dns system.  In my case I was sending the mail via an alias (it was a notification email from the web server).  The receiving mail server sees the email as forged and bounces it.
The Solution: Go to the dns system and create a mail.domain.com and point your MX records to that.  It’s a bit silly, but it has to be done that way.

Monday 30 May 2011

How to install PECL uploadprogress


On Linux server:
  1. # cd /usr/local/src/
  2. get the latest version http://pecl.php.net/package/uploadprogress
  3. # tar xvfz uploadprogress-VERSION.tgz
  4. # cd uploadprogress-VERSION

  5. # export PHP_PREFIX="/usr/local"
    # $PHP_PREFIX/bin/phpize
    # ./configure
    # make
    # make install
  6. open your php.ini
    e.g.

    # vi /usr/local/lib/php.ini

    add the line you received followed by "uploadprogress.so":

    ; PECL uploadprogress
    extension_dir="/usr/local/lib/php/extensions/no-debug-non-zts-20060613/"
    extension=uploadprogress.so
  7. # service httpd restart

Saturday 28 May 2011

How To Optimize Your Site With GZIP Compression


ompression is a simple, effective way to save bandwidth and speed up your site. I hesitated when recommending gzip compression when speeding up your javascriptbecause of problems in older browsers.
But it's the 21st century. Most of my traffic comes from modern browsers, and quite frankly, most of my users are fairly tech-savvy. I don't want to slow everyone else down because somebody is chugging along on IE 4.0 on Windows 95. Google and Yahoo use gzip compression. A modern browser is needed to enjoy modern web content and modern web speed -- so gzip encoding it is. Here's how to set it up.

Wait, wait, wait: Why are we doing this?

Before we start I should explain what content encoding is. When you request a file likehttp://www.yahoo.com/index.html, your browser talks to a web server. The conversation goes a little like this:
HTTP_request.png
1. Browser: Hey, GET me /index.html
2. Server: Ok, let me see if index.html is lying around...
3. Server: Found it! Here's your response code (200 OK) and I'm sending the file.
4. Browser: 100KB? Ouch... waiting, waiting... ok, it's loaded.

Of course, the actual headers and protocols are much more formal (monitor them withLive HTTP Headers if you're so inclined).
But it worked, and you got your file.

So what's the problem?

Well, the system works, but it's not that efficient. 100KB is a lot of text, and frankly,HTML is redundant. Every , and
 tag has a closing tag that's almost the same. Words are repeated throughout the document. Any way you slice it,HTML (and its beefy cousin, XML) is not lean.
And what's the plan when a file's too big? Zip it!
If we could send a .zip file to the browser (index.html.zip) instead of plain old index.html, we'd save on bandwidth and download time. The browser could download the zipped file, extract it, and then show it to user, who's in a good mood because the page loaded quickly. The browser-server conversation might look like this:
HTTP_request_compressed.png
1. Browser: Hey, can I GET index.html? I'll take a compressed version if you've got it.
2. Server: Let me find the file... yep, it's here. And you'll take a compressed version? Awesome.
3. Server: Ok, I've found index.html (200 OK), am zipping it and sending it over.
4. Browser: Great! It's only 10KB. I'll unzip it and show the user.

The formula is simple: Smaller file = faster download = happy user.
Don't believe me? The HTML portion of the yahoo home page goes from 101kb to 15kb after compression:
yahoo_compression.PNG

The (not so) hairy details

The tricky part of this exchange is the browser and server knowing it's ok to send a zipped file over. The agreement has two parts
  • The browser sends a header telling the server it accepts compressed content (gzip and deflate are two compression schemes): Accept-Encoding: gzip, deflate
  • The server sends a response if the content is actually compressed: Content-Encoding: gzip
If the server doesn't send the content-encoding response header, it means the file is not compressed (the default on many servers). The "Accept-encoding" header is just a request by the browser, not a demand. If the server doesn't want to send back compressed content, the browser has to make do with the heavy regular version.

Setting up the server

The "good news" is that we can't control the browser. It either sends the Accept-encoding: gzip, deflate header or it doesn't.
Our job is to configure the server so it returns zipped content if the browser can handle it, saving bandwidth for everyone (and giving us a happy user).
For IIS, enable compression in the settings.
In Apache, enabling output compression is fairly straightforward. Add the following to your .htaccess file:

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# Or, compress certain file types by extension:

SetOutputFilter DEFLATE


Apache actually has two compression options:
  • mod_deflate is easier to set up and is standard.
  • mod_gzip seems more powerful: you can pre-compress content.
Deflate is quick and works, so I use it; use mod_gzip if that floats your boat. In either case, Apache checks if the browser sent the "Accept-encoding" header and returns the compressed or regular version of the file. However, some older browsers may have trouble (more below) and there are special directives you can add to correct this.
If you can't change your .htaccess file, you can use PHP to return compressed content. Give your HTML file a .php extension and add this code to the top:
In PHP:

We check the "Accept-encoding" header and return a gzipped version of the file (otherwise the regular version). This is almost like building your own webserver (what fun!). But really, try to use Apache to compress your output if you can help it. You don't want to monkey with your files.

Verify Your Compression

Once you've configured your server, check to make sure you're actually serving up compressed content.
  • Online: Use the online gzip test to check whether your page is compressed.
  • In your browser: Use Web Developer Toolbar > Information > View Document Size (like I did for Yahoo, above) to see whether the page is compressed.
  • View the headers: Use Live HTTP Headers to examine the response. Look for a line that says "Content-encoding: gzip".
Be prepared to marvel at the results. The instacalc homepage shrunk from 36k to 10k, a 75% reduction in size.

Try Some Examples

I've set up some pages and a downloadable example:
  • index.html - No explicit compression (on this server, I am using compression by default :) ).
  • index.htm - Explicitly compressed with Apache .htaccess using *.htm as a rule
  • index.php - Explicitly compressed using the PHP header
Feel free to download the files, put them on your server and tweak the settings.

Caveats

As exciting as it may appear, HTTP Compression isn't all fun and games. Here's what to watch out for:
  • Older browsers: Yes, some browsers still may have trouble with compressed content (they say they can accept it, but really they can't). If your site absolutely must work with Netscape 1.0 on Windows 95, you may not want to use HTTPCompression. Apache mod_deflate has some rules to avoid compression for older browsers.
  • Already-compressed content: Most images, music and videos are already compressed. Don't waste time compressing them again. In fact, you probably only need to compress the "big 3" (HTML, CSS and Javascript).
  • CPU-load: Compressing content on-the-fly uses CPU time and saves bandwidth. Usually this is a great tradeoff given the speed of compression. There are ways to pre-compress static content and send over the compressed versions. This requires more configuration; even if it's not possible, compressing output may still be a net win. Using CPU cycles for a faster user experience is well worth it, given the short attention spans on the web.
Enabling compression is one of the fastest ways to improve your site's performance. Go forth, set it up, and let your users enjoy the benefits.

Sending email or mail with attachment from command or shell prompt


If you are looking to send email with attachment via shell script or at shell prompt/command line (read as bash prompt), use mutt command.
Mutt is a small but very powerful text based program for reading electronic mail under UNIX /Linux operating systems, including support for color terminals, MIME, and a threaded sorting mode.
Please note that mutt is a pure MUA and cannot send e-mail without proper email server . You need a working Mail Transfer Agent (MTA) such as sendmail or postfix. I am assuming that you have configured email server.

Install mutt

If mutt is not installed, use apt-get or yum or up2date command as follows (login as a root user):
(A) Debian Linux / Ubuntu Linux user use following command to install mutt:
# apt-get install mutt
B) Fedora / CentOS or Red Hat Linux (RHEL) user can use following command to install mutt:
# yum install mutt
OR
# up2date mutt
C) FreeBSD user use following command to install mutt via pkg_add command:
# pkg_add -v -r mutt

How do I send email attachments from a command prompt?

1) Use mutt command as follows to send an email with attachment:
$ mutt -s "Test mail" -a /tmp/file.tar.gz vivek@nixcraft.co.in < /tmp/mailmessage.txt
Where,
  • vivek@nixcraft.co.in – is the recipient
  • /tmp/mailmessage.txt – is the main body of the e-mail (read message from the file “mailmessage.txt”)
  • /tmp/file.tar.gz – is an attachment (with option -a)
  • “Test mail” – is a subject line (option -s)

SEND MAIL BASH SCRIPT

put in a shell script:

#!/bin/bash
# script to send simple email
# email subject
SUBJECT="SET-EMAIL-SUBJECT"
# Email To ?
EMAIL="admin@somewhere.com"
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE

Thursday 26 May 2011

Magento Optimization

By default Magento comes with enabled caching thus avoiding repetition of some of the heaviest operations. However, this is not always enough for Magento to run fast.

Speeding up Magento is not always an easy task and commercial extensions for this purpose are expensive. That's why we will offer you two easy to follow steps which can significantly increase Magento Performance:

1. Enable the compiler which comes with Magento by default. You can find it in Magento admin panel,  System, Tools, Compilation. Just click on Enable and Run Compilation Process after that.

This option compiles all Magento installation files and creates a single include path. It will speed up pages 25-50% according to the official documentation.

However, enabling the compiler may cause some issues such as reporting missing php files which cannot be included. This may force you to disable the compiler. This can be done similarly to enabling it - go to admin panel, System, Tools, Compilation.

2. If the above improvement is not enough next step is to install a third party extension. We will use the freely available Fooman Speedster. Its extension key is:

magento-community/Fooman_Speedster

To install it follow these steps:

First, from Magento admin panel go to System, Magento Connect, Magento Connect Manager. There paste the above key and click on Install.

Next, add the following line to your Magento .htaccess:

RewriteRule ^(index.php/)?minify/([^/]+)(/.*.(js|css))$ lib/minify/m.php?f=$3&d=$2

The above will force all requests to be processed through the extension frontend called m.php. In order this processor to work properly please do the following:

a. Change the permissions for the directory lib/minify/ to 755 recursively. These are the correct permissions if your webserver runs under your user and php is in suexec as in most shared hosting environments. Alternatively, you can leave the default 777 permissions.

b. Ensure that the caching directory 'var/minifycache/' is writable. In most cases 777 permissions are sufficient. Then open a few times your Magento and check if files such as minify_67fe988157635b14d2f1e076727899d2 have appeared in the directory in question.

The above optimization steps are the fastest and easiest way to an optimized Magento.

Magento - Configure/Move site to new domain


Configure Magento to new Domain or Move Magento to New Domain by just editing 2 fields of database. You can open your Magento Database and follow the below steps.
1) Open Magento Database
2) Click on core_config_data table
3) Edit web/unsecure/base_url and web/secure/base_url fields
4) Update these fields with New Domain name
5) Clear Magento Cache
6) You are done.

How to clear the cache in Magento?


If you have made any modifications to your Magento store, they will not appear immediately unless you clear the cache.

Magento keeps its cache in /var/cache located inside the Magento installation directory. So, for example, if your Magento is installed in your main public_html folder, the cache will be in public_html/var/cache.

To clear the cache, simply delete everything from the /var/cache directory and then reload your website in your browser.

To clear all sessions, you can also delete everything from the /var/session folder within your Magento installation directory.

Wednesday 25 May 2011

Host Images of WordPress Blog in a Subdomain for Better Speed

In some previous articles, I’ve described about how to reduce the page load time of your WordPress blog [ 1. Speed Up Your WordPress Blog By Improving Page Load Time 2. Install Contact Page in WordPress Blog Without Any Plugin 3. Reduce Page Load Time Installing Tweetmeme Retweet Button Manually ] .  Another issue is still yet to discuss that effectively participate in your page performance. By default the images of your site are hosted in the same domain. This slow downs your page speed. Also read:How to Add Extra Widget Section In WordPress Blog. Because, almost all the browsers create maximum two-four connections when downloading a page from the web server. So if your pages contain more than one images then it is wise to host those images in another domain so that the browser can download the images in parallel with your main domain. WordPress does not support hosting images in different domain. But fortunately, it supports and allows you to host images in a subdomain. This article is about how to host your website post images in a subdomain along with the old images that were hosted in the main domain.


Create a Subdomain for your site

In order to get your subdomain you’ve to log-in to your domain control panel.Point to Subdomains and create your subdoamain, provided your domain resides under /public_html/.Note: The facility depends on your hosting provider. So if you are unable to create a subdomain then contact your hosting provider.

Change default image  uploading folder in WordPress

This step involves in setting WordPress to change the default uploading folder for the post images. log-in to your WordPress dashboard. Click on 
“Miscellaneous”
 “Media” under “Settings” from left side of the dashboard.
Fill up the fields as follows: Store uploads in this folder : images Full URL path to files : http://images.yourdomain.com
Click on “Save Changes”. Now whenever you will upload any image to your post, the images will be uploaded in the subdomain http://images.yourdomain.com.

Update the old post images location

You’ve just changed the upload location of your post images. So the images of the new posts will be uploaded in the subdomain. But what about the old post images? Changing the location of all the old images one by one is a stupid job. So at first download all the folders containing the images under /public_html/wp-content/uploads/ from your server.Upload all those folders in the folder /public_html/images/. Now you have to execute a simple SQL query on your database. You can do this from the phpMyAdmin in your domain control panel.Click on phpMyAdmin > select your database from the left side > click on the “SQL” tab.Now put the following query in the box
UPDATE wp_posts SET post_content = REPLACE(post_content,'http://www.yourdomain.com/wp-content/uploads/','http://images.yourdomain.com/')
Click on “GO”. This query will replace “http://www.yourdomain.com/wp-content/uploads/”  with “http://images.yourdomain.com/” in all the image location url. To update the images links in the media library run the following sql command
UPDATE wp_posts SET guid = REPLACE(guid,'http://www.yourdomain.com/wp-content/uploads/','http://images.yourdomain.com/')

Redirect the old images link to to subdomain

You have completed all the task with your site and database. But Google has crawled and indexed your old images. So redirect the old image urls to the new image urls to let Google know that those images are same. To do so ad the following line in your .htaccess file
RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://images.yourdomain.com/$1
Reminder: Backup your .htaccess file before any modification. That’s all to set your subdomain as post-images upload location. Any question is always well come. Put your feedback in the comment section.

This connection is untrusted


Certificates and identification

When you visit a website whose web address starts with https, your communication with the site is encrypted to help ensure your privacy. Before starting the encrypted communication, the website will present Firefox with a "certificate" to identify itself.
The certificate helps Firefox determine whether the site you're visiting is actually the site that it claims to be. If there is a problem with the certificate, you will see the This Connection Is Untrusted alert page.
84d36543f8c73c50c63238baf79bf4e3-1253375797-145-1.png ::
Seeing the alert does not necessarily mean that the website you're visiting is trying to trick you into believing it is a different website - it means that Firefox isn't able to verify the identity of the website, and that you should proceed carefully.
There are several problems that can cause Firefox to reject a certificate. Some of them are described in detail in theTechnical information section below.

Get out of there!

The safest thing to do is to click Get me out of here!, or to go to a different website. Unless you know and understand the technical reason why the website presented incorrect identification, and are willing to risk communicating over a connection that could be vulnerable to an eavesdropper, you should not proceed to the website.
If possible, you should contact the owners of the website and inform them of the error.

Technical information

Click on Technical Details for more information on why the website's identity information is invalid. Some common errors are described below.

Certificate is only valid for (site name)

(site name) uses an invalid security certificate. The certificate is only valid for (site name). (Error code: ssl_error_bad_cert_domain)
This error is telling you that the identification sent to you by the site is actually for another site. While anything you send would be safe from eavesdroppers, the recipient may not be who you think it is.
A common situation is when the certificate is actually for a different part of the same site. For example, you may have visited https://example.com, but the certificate is for https://www.example.com. In this case, if you access https://www.example.com directly, you should not receive the warning.

The certificate is not trusted because it is self-signed

(site name) uses an invalid security certificate. The certificate is not trusted because it is self-signed. (Error code: sec_error_untrusted_issuer)
Self-signed certificates make your data safe from eavesdroppers, but say nothing about who the recipient of the data is. This is common for intranet websites that aren't available publicly.

Certificate will not be valid until (date)

(site name) uses an invalid security certificate. The certificate will not be valid until (date). (Error code: sec_error_expired_issuer_certificate)
This error can occur if your computer clock has the wrong date. To fix the problem, set your system clock to the correct date and time.

The certificate expired on (date)

(site name) uses an invalid security certificate. The certificate expired on (date). (Error code: sec_error_expired_issuer_certificate)
This error occurs when a website's identity certification has expired.
This error can also occur if your computer clock has the wrong date. To fix the problem, set your system clock to the correct date and time.

Bypassing the warning

You should only bypass the warning if you're confident in both the identity of the website and the integrity of your connection - even if you trust the site, someone could be tampering with your connection. Legitimate public sites will not ask you to add connection rule exceptions - an invalid certificate can be an indication of a web page that will defraud you or steal your identity.
  1. On the warning page, click I Understand the Risks.
  2. Click Add Exception.... The Add Security Exception dialog will appear.
  3. Read the text describing the problems with this site.
  4. Click Confirm Security Exception if you want to trust the site.

What is an addon domain?


An addon domain is a fully functional domain that can be created from within your control panel. Think of it as having multiple hosting packages all sharing the same control panel. You can give them email addresses, forwarders, and more the same way you do for your main domain on the account.

The addon domain will appear as a totally separate domain from your primary domain. There should be no evidence that your domain is an addon domain to incoming traffic when they visit your addon domain.

Monday 23 May 2011

VPN via the TUN/TAP device


I had a client contact me earlier this morning because one of their clients was receiving the following error on their VPS when trying to run OpenVPN.
Note: Cannot open TUN/TAP dev /dev/net/tun: Permission denied (errno=13)
Note: Attempting fallback to kernel 2.2 TUN/TAP interface
Cannot open TUN/TAP dev /dev/tun0: No such file or directory (errno=2)
I’ve never run into this issue before, but was able to find an awesome tutorial on the OpenVZ website.
First, make sure the tun module has been already loaded on the hardware node:
1# lsmod | grep tun
If it is not there, use the following command to load tun module:
1# modprobe tun
To make sure that tun module will be automatically loaded on every reboot you can also add it or into /etc/modules.conf (on RHEL see /etc/sysconfig/modules/ directory) or into /etc/sysconfig/vz-scripts/VEID.mount.
1echo 'modprobe tun' /etc/sysconfig/vz-scripts/VEID.mount
Allow your container to use the tun/tap device by running the following commands on the host node:
1vzctl set VEID --devices c:10:200:rw --save
2vzctl set VEID --capability net_admin:on --save
And create the character device file inside the container (execute the following on the host node):
1vzctl exec VEID mkdir -p /dev/net
2vzctl exec VEID mknod /dev/net/tun c 10 200
3vzctl exec VEID chmod 600 /dev/net/tun
Enter cat /dev/net/tun to test whether the TUN/TAP device is available:
  • If you receive the message cat: /dev/net/tun: File descriptor in bad state your TUN/TAP device is ready for use.
  • If you receive the message cat: /dev/net/tun: No such device the TUN/TAP device was not successfully created.