Monday, 21 December 2015

Simplify Multiple Sitemaps

If you have many sitemaps, you can use a sitemaps index file as a way to submit them at once. The XML format of a sitemap index file is very similar to the XML format of a sitemap file. The sitemap index file uses the following XML tags:
  • sitemapindex - the parent tag surrounds the file.
  • sitemap - the parent tag for each sitemap listed in the file (a child of sitemapindex)
  • loc - the location of the sitemap (a child of sitemap)
  • lastmod - the last modified date of the sitemap (optional)
  • The following example shows a sitemap index in XML format that lists two sitemaps:
    <?xml version="1.0" encoding="UTF-8"?>
       <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
       <sitemap>
          <loc>http://www.example.com/sitemap1.xml.gz</loc>
          <lastmod>2004-10-01T18:23:17+00:00</lastmod>
       </sitemap>
       <sitemap>
          <loc>http://www.example.com/sitemap2.xml.gz</loc>
          <lastmod>2005-01-01</lastmod>
       </sitemap>
       </sitemapindex>
    
    Once you’ve made and saved your index file, you can submit your index file to Google as long as you upload and save all your sitemaps to the same location on your host server. You can submit up to 500 sitemap index files for each site in your account.
Source Link: https://support.google.com/webmasters/answer/75712?rd=1

Tuesday, 24 November 2015

Drupal Module - Blocks By Page Path

In Drupal,
Sometimes we would like to know the blocks which are assigned (enabled / disabled) to a particular page. This module helps us to get the block(s) information by providing the page path.
This module helps us to find the blocks which are assigned through
1. "admin/structure/block" section
2. Context module
Module Download Link Click Here

Wednesday, 18 November 2015

Syslog is not recommended in Pantheon + Drupal

Here is the statement from Pantheon with Drupal.

On Pantheon, you can technically write to syslog, but there is no mechanism for reading it. Disable syslog and enable dblog instead.

Friday, 18 September 2015

What is White Label Approach

A product or service, especially common in the in the financial sector, where the provider of the service purchases a fully supported product from another source, then applies its own brand and identity to it, and sells it as its own product. The purchaser assumes the seller is selling its own product.

Source: http://www.webopedia.com/TERM/W/white_label.html

Wednesday, 29 July 2015

SEO and H1 Tags

The header tag, or the <h1> tag in HTML, will usually be the title of a post, or other1 emphasized text on the page.  It will usually be the largest text that stands out.  There are other header tags in HTML too, like an h2, h3, h4, etc.  Each can have a lesser degree of importance on the page, but it really depends on how your HTML/CSS guy did the layout.  Sometimes, they make your logo the h1 – because it’s in the “header”, but it would be best to make the h1 the title of the page or post instead.

How you write your header, or h1 tag, is going to be similar to how you wrote your title tag.  Sometimes these can be the same, and that’s OK.  Here are a few tips:
1.  Put your header tag <h1> </h1> at the top of the page, preferably after the <body> tag.
2.  Are you targeting the keywords you wish to rank higher for?  If not, go in and modify your tags slightly to include those words.  If your h1 happens to be an image, use the image alt tag to add those juicy keywords.
3. Can I have more than 1 header tag on the page?  Google will not penalize you, but one is preferred.  If you have a need for multiple titles, then perhaps it should be broken into multiple pages, or use one h1, or multiple h2’s. 
Ref: http://pearanalytics.com/blog/2014/how-to-write-a-header-tag-h1-for-seo/

Thursday, 9 July 2015

Faster MySQL drops and imports with Drush

Since moving to a local development model, I've been doing far more database imports. I'd been doing them through phpMyAdmin until a colleague showed me how much faster they were with Drush. It's a two-step process:
  • drush sql-drop - This drops the tables on your existing database.
  • drush sqlc < path/to/filename_here.sql - This imports the file into your database.

Notes

  • Both of these commands must be run inside the structure of your Drupal site. Be careful about where you run them -- if you're in the wrong site, you'll drop the wrong database. 
  • If you're having trouble remembering which carat to use, remember that the < pointing away from the file and toward sqlc means that the filename is being dropped into your database, not that the database is being exported to a file.
  • Remember to update the path to your database relative to where you're running the command. If you store your SQL file in sites/default/databases and you're running the command from inside sites/default/databases, just drush sqlc < filename_here.sql is plenty. If you were running it from, say, sites/all/themes, you'd need to add a path so Drush could find the file you were pointing to.
Ref: http://www.webbykat.com/2012/06/faster-mysql-drops-and-imports-drush

Tuesday, 23 June 2015

Nginx Configuration Snippets

You can find useful nginx configuration snippets in below link.

Ref: https://github.com/lebinh/nginx-conf

nginx - redirect non-www to www

Configure Nginx Redirect

In order to perform the 301 redirect, you must add a new Nginx server block that points to your original server block.
Open your Nginx server block configuration in an editor. We'll add another configuration file in the Nginx include directory, /etc/nginx/conf.d called redirect.conf:
sudo vi /etc/nginx/conf.d/redirect.conf
Your original server block should already be defined. Depending on which direction you want to redirect, use one of the following options.

Option 1: Redirect www to non-www

If you want redirect users from www to a plain, non-www domain, insert this configuration:
New Server Block — www to non-www
server {
    listen 80;
    server_name www.example.com;
    return 301 $scheme://example.com$request_uri;
}
Save and exit. This configures Nginx to redirect requests to "www.example.com" to "example.com". Note that there should be another server block that defines your non-www web server.
To put the changes into effect, restart Nginx:
sudo systemctl restart nginx
Note that if you are using HTTPS, the listen directive should be set to port 443 instead of 80.
Use this curl command to ensure that the non-www domain redirects to the www domain (replace the highlighted part with your actual domain):
curl -I http://www.example.com
You should get a 301 Moved Permanently response, that shows the non-www redirect location, like this:
Output:
HTTP/1.1 301 Moved Permanently Server: nginx/1.4.6 (Ubuntu) Date: Mon, 04 May 2015 18:20:19 GMT Content-Type: text/html Content-Length: 193 Connection: keep-alive Location: http://example.com/
Of course, you should access your domain in a web browser (www and non-www) to be sure.

Option 2: Redirect non-www to www

If you want redirect users from a plain, non-www domain to a www domain, add this server block:
New Server Block — non-www to www
server {
    listen 80;
    server_name example.com;
    return 301 $scheme://www.example.com$request_uri;
}
Save and exit. This configures Nginx to redirect requests to "example.com" to "www.example.com". Note that there should be another server block that defines your www web server.
To put the changes into effect, restart Nginx:
sudo systemctl restart nginx
Note that if you are using HTTPS, the listen directive should be set to port 443 instead of 80.
Use this curl command to ensure that the non-www domain redirects to the www domain (replace the highlighted part with your actual domain):
curl -I http://example.com
You should get a 301 Moved Permanently response, that shows the www redirect location, like this:
Output:
HTTP/1.1 301 Moved Permanently Server: nginx/1.4.6 (Ubuntu) Date: Mon, 04 May 2015 18:20:19 GMT Content-Type: text/html Content-Length: 193 Connection: keep-alive Location: http://www.example.com/
Of course, you should access your domain in a web browser (www and non-www) to be sure.
Ref: https://www.digitalocean.com/community/tutorials/how-to-redirect-www-to-non-www-with-nginx-on-centos-7

Saturday, 13 June 2015

HOWTO Cache S3 Objects with Varnish

Many startups these days are using Amazon S3 to serve directly their static assets. S3 is being used as a simple CDN instead of more professional (and expensive) solutions (including Amazon’s own CloudFront) because it is very simple and cheap to use. Still if you have a high traffic site, this will no longer be so cheap since you will be paying for all those requests and the bandwidth. In such cases if you still want to use S3 for the storage advantage (like storing millions of files and see it as an unlimited storage space) but not have your bill go up like crazy, you can use a reverse proxy or web accelerator to cache your assets locally and reduce the number of direct hits on S3. We could use Squid or Varnish for this, and in this article I will show how we can configure Varnish for this. We are using varnish with S3 on various projects and it works very well, simplifying the setup and saving a lot of money in the Amazon S3 bill.


Varnish is a state-of-the-art, high-performance HTTP accelerator. It uses the advanced features in Linux 2.6, FreeBSD 6/7 and Solaris 10 to achieve its high performance. I will not go over the installation of varnish here, but I would highly recommend to use the latest version available at this time 2.0.4 as older versions have various issues.
This article was taken from:
http://www.ducea.com/2009/08/04/using-varnish-in-front-of-your-amazon-s3-static-content/
We could try to use something simple like this in a varnish vcl
A complete varnish vcl configuration to use with the Amazon S3 backend might look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
backend s3 {
  .host = "s3.amazonaws.com";
  .port = "80";
}

sub vcl_recv {
  if (req.url ~ "\.(css|gif|ico|jpg|jpeg|js|png|swf|txt)$") {
      unset req.http.cookie;
      unset req.http.cache-control;
      unset req.http.pragma;
      unset req.http.expires;
      unset req.http.etag;
      unset req.http.X-Forwarded-For;

      set req.backend = s3;
      set req.http.host = "my_bucket.s3.amazonaws.com";

      lookup;
  }
}

sub vcl_fetch {
  unset obj.http.X-Amz-Id-2;
  unset obj.http.X-Amz-Meta-Group;
  unset obj.http.X-Amz-Meta-Owner;
  unset obj.http.X-Amz-Meta-Permissions;
  unset obj.http.X-Amz-Request-Id;

  set obj.ttl = 1w;
  set obj.grace = 30s;
}

Friday, 24 April 2015

Why can't we use PHP filter in Drupal?

Some reasons:
  • Code in your database can not be version controlled and is also harder to find in general later on.
  • Eval()'d code is much slower than something hardcoded in a file.
  • If there is an error somewhere in that code, you will get a very unhelpful error message (error in eval()'d code at line 3) and you might even have go through your database manually to find and fix the error. If it is inside a block that is displayed on all pages and results in a fatal error all the time for example.
  • The above is also true when upgrading from Drupal 6 to 7 and whatever API's you used were changed. So you will have to port your code while migrating. If the code is in a module, you can port it in advance, test it, and only deploy it on the new site. Inside a node or block, it will only work with either Drupal 6 or 7.
  • Writing and maintaing that code is also harder, because you are working in a textfield inside your browser. Having it in a module allows you to use an editor/IDE with syntax highlighting, autocomplete and so on.
  • There is always the possibility of a misconfiguration that gives people access to a text format/block/whatever with php execution enabled. If php.module (in D7, D6 is not so strict, for example for block access rules) isn't even enabled, that risk is much lower already.
  • If your CMS allows execution of PHP then an attacker who finds a security vulnerability of XSS or privilege escalation can now use your server for enormously malicious things (as part of a DDOS, sending spam, hosting malware, hacking into other sites/databases on the server, hacking into other servers on the network that might be behind firewalls). In addition to making small vulnerabilities more painful, this makes the site a more likely target of attack if its known that it can be used to execute php.
Ref: http://drupal.stackexchange.com/questions/2509/what-are-the-downsides-of-using-custom-php-code-in-blocks-nodes-views-args

Thursday, 19 March 2015

Create symlink file in Drupal sub-directory multisite concept

We need to create a symlink file if we making the drupal as multisite with single code base.

If you are attempting to get Drupal multi-site working using subdirectory URLs rather than subdomain or different domain URLs, you may encounter problems. You'll start out by making a directory such as sites/example.com.subdir, and putting a settings.php file there. If this works for you, great! But it probably will not, until you make a symbolic link that tells your web server that the document root for http://example.com/subdir is the same as the document root for http://example.com. To do this, go to the example.com document root and type:

ln -s . subdir

If your codebase itself is in a subdirectory, then link your new site to the directory:

ln -s drupaldir subdir

Ref: https://www.drupal.org/documentation/install/multi-site

Friday, 13 February 2015

Drush - Sql Dump Command

To take sql dump using drush command,

drush sql-dump > /path/to/backup_dir/database-backup.sql

Friday, 23 January 2015

Know git clone URL

To know the GIT clone URL from your repo

git remote -v

isset() function not working as expected in PHP 5.3.3

I had experienced this issue in array items.

when I try to check the particular array key existed in provided array, the isset function always returns true.

PHP Codesniffer - Ignore warning errors

 Use below command to ignore warnings while generating report. phpcs -n /path_to_directory/ The above command will result only errors and ig...