Category Archives: Web tools

How to import an SQL file using command line in MySQL?

Import MySQL database using command line

 

If you have a very large SQL dump file to import and you know very well that it is not very easy to import using phpMyAdmin, even if you split it in many pieces, it is also be hard using PHP script as it will time out after a particular time.

 

In this case there is only one acceptable and easy solution is import the file directly from MySQL command line.
As command Line will always be the most efficient, though not the most user-friendly way to accomplish a database export and import.

 

Follow the below easy steps to make your life easy.

 

The below example I am showing is executed on my local server(local host) and using XAMPP, but same will also work on Linux if you are using Linux for your application but you need to make sure that the file you want to import is of a .sql(.gz, .gzip) format.

 

The below method is perfect if

 

  • You do not have phpMyAdmin installed.
  • You do not have remote web access to the database server.
  • You do have SSH/Putty access.
  • The database file size is very large.
  • You want total control over the process.

Let’s start

 

1. Open a command prompt (or shell in Linux) with administrative privileges.

 

2. If you are in Windows set character set to Unicode. Linux is using UTF-8 by default.

chcp 65001

 

3. Connect to a MySQL instance using command line (If your MySQL path is different rather than drive D: as I have, you should be in that folder only)


D:\xampp\mysql\bin\mysql -h 192.168.1.1 --port=3306 -u root -p

If you are in local host you do not need host and port


D:\xampp\mysql\bin\mysql -u root -p

 

4. It will now ask for password: enter the password
—> <your-password>

 

5. You are now in MySQL shell. Set network buffer length to a large byte number. The default value may throw errors for such large data files


set global net_buffer_length=1000000;

 

6. Set maximum allowed packet size to a large byte number. The default value may throw errors for such large data files.


set global max_allowed_packet=1000000000;

 

7. Disable foreign key checking to avoid delays, errors and unwanted behavior


SET foreign_key_checks = 0;
SET UNIQUE_CHECKS = 0;
SET AUTOCOMMIT = 0;

 

8.  Select your database as below


use <your-db-name>;

 

If you have not created the database yet, in which you want to import the database then below the above you can created the database using the below MySQL command


create database <your-db-name>; and after then run use <your=db-name>;

 

9. Provide your dump file full path name


source <DbName.sql>

If your file is not is the location you are currently in then provide the complete path of the file as below


source C:\scriptarticledotcom_db\dbdump150404.sql

 

It’s DONE!!

Remember to enable foreign key checks when process is complete else it will set for all of your databases as well and it will work improper!

 

Run the below MySQL commands for reset the global MySQL settings


SET foreign_key_checks = 1;
SET UNIQUE_CHECKS = 1;
SET AUTOCOMMIT = 1;

 

Hope the above will work, share you feedback or comments if you face any issue or have more suggestion to make the article more useful for developers.

 

 

CDN: Content Delivery Network Overview

Content Delivery Networks (CDN)

 

Hi Everybody, I think you all aware about the CDN (Content Delivery Networks).

 

If not, don’t worry I am going to explain you what is CDN and how it works and how to know whether you site need CDN or not.

 

In Short: A content delivery network (CDN) places files in different locations so that the person using your webpage can receive the nearest copy.

 

Let’s discuss more about CDN?
A CDN (content delivery network) is a system of distributed servers (network) located in different parts of the globe that stores files to be used by your website visitors, It deliver web pages and other Web content to a user based on the geographic locations of the user, the origin of the webpage and a content delivery server may differ.

 

The reason why it used is, there is a measurable amount of waiting time (webpage load) for a website user who is visiting a page that may be hosted thousands of miles away. There are also routing issues that can occur when a user is visiting such a webpage. If someone in Jaipur is using a webpage that is hosted in London they are seeing a slower version of that webpage because of the above mentioned routing issues and sheer distance the files have to travel.

 

By having your files on several servers across a geographical area you can make sure the user is loading files that are near them, not all the way across the country or ocean.

This service is effective in speeding the delivery of content of websites with high traffic and websites that have global reach. The closer the CDN server is to the user geographically, the faster the content will be delivered to the user. CDNs also provide protection from large surges in traffic.

 

How it works?
In a CDN, content exists as multiple copies on strategically dispersed servers. A large CDN can have thousands of servers around the globe, making it possible for the provider to send the same content to many requesting client computing devices efficiently and reliably even when bandwidth is limited or there are sudden spikes in demand.

 

Whenever a visitor request a webpage to open, the CDN will redirect the request from the originating site’s server to a server in the CDN that is closest to the user and deliver the cached content. The CDN will also communicate with the originating server to deliver any content that has not been previously cached.

 

CDN management software dynamically calculates which server is located nearest to the requesting visiter and delivers content based on those calculations. This not only eliminates the distance that content travels, but also reduces the number of hops a data packet must make. The result is less packet loss, optimized bandwidth and faster performance which minimizes time-outs, while improving overall user experience (UX) and site health. In the event of an Internet attack or malfunction at a junction of the Internet, content that’s hosted on a CDN server will remain available to at least some users.

 

The process of bouncing through a CDN is nearly transparent to the user. The only way a user would know if a CDN has been accessed is if the delivered URL is different than the URL that has been requested.

 

Why the CDN is so much popular now a days?
The real reason that so many businesses and webmasters are now using CDNs is because Google has started using page speed as a ranking factor. Content delivery networks however provide a faster experience for users, and that means happier users who buy more things and click more ads. An additional reason for CDN use is the explosion of tablet and mobile users who depend on speed more so than desktop users who have stable internet connections.

 

Does your site need a CDN?
Content delivery networks are used for B2B interactions and in serving content to consumers. CDN is well suited for delivering large streaming audio, video, and Internet television (IPTV) programming, although an Internet service provider (ISP) may also use one to deliver static or dynamic Web pages.

 

You can also host your site on CDN, below are some outstanding improvement if CDN used:

  1. Improvement the page speed
  2. Amazing site performance for your users
  3. Make your site mobile ready and available for some geographical user even server is going down or slow.

 

Some types of websites I not recommend for CDN:

  • Local business sites (DJ, restaurants, city hair salon, city shops etc.)
  • Websites that have their main visitors or traffic in only one geographic region.

 

How much it costs for you?
CDN is a paid service provided by many hosting providers and just like every web service offered, there are almost levels of cost for content delivery networks from free to thousands of dollars depends on the service they provides.

 

Below are the list of some CDN provided listed according to popularity (visit their website for more information, cost and configuration/setup along with customer service).

  1. Akamai
  2. Max CDN
  3. Amazon CloudFront
  4. CloudFlare CDN (this has free option as well)
  5. CDNetworks

 

How do you set a CDN up?

Whenever you buy a CDN it provide a complete guide and customer service for setting it up. However below are some steps that generally followed.

 

Sign up for a service

 

Know what files you are using :
In many cases you are using a CDN to serve things like your images, CSS, and JavaScript files. Such files cause many problems for your users visiting your website from far off places. Having these assets on servers closer to your users is the entire point of having a content delivery network. There are different offerings from different CDNS, but in most scenarios your HTML will come from your webhost and your assets will come from the CDN.

 

Getting your files to the CDN servers:
You will need to get the files you want to serve to the CDN web servers. Some places will have options to do it for you almost automatically, some won’t.

Many have automatic setups if you are using WordPress, Joomla, Drupal or other common CMSs (content management systems). The basic premise however is the same across all CDNs. You will need to have your files hosted by the network and this is usually a one step process of loading those files somewhere once and the content delivery network will then replicate those files across their network.

 

Decide on how to name your URLs (CNAME):
Once your files are on the CDN servers they will have a different URL than they once did. Let’s take an CSS fill as an example. Your old CSS file was at “examplesite.com/css/style.css”, well now that you are using a CDN your CSS file is located at a URL that may look as ugly as this “dfg23345678449dhhty74/style.css” 🙁

 

Instead that name you can choose to use a name of our own choosing (the most common being “cdn.examplesite.com”) and then use something called CNAME to make sure it looks correct and nice to our users. This is a simple step that will result in our CSS file coming from “cdn.examplesite.com/style.css”.

 

Ensuring your web pages are calling (using) the files you sent to the CDN:
You can basically just tell your CMS to swap out the files automatically using common caching systems. An example for WordPress would be to use W3 TOTAL CACHE. Any blog should be using a caching system already and if your isn’t then your blog is probably slow. Using caching properly is an important step in improving page speed and will offer massive benefits to your users.

 

Testing after setup:

Most CDNs will have a page or dashboard where you can see the usage of your files. Other ways of testing would be to use webpagetest.org.

 

Whether it affect my website SEO (Search Engine Optimization)?

Yes, in some extent as the file name changes it is going to scare you :-). However the reputable CDNs have good solutions for any common SEO problems.

 

I think above article will help you to understand the CDN and host your site on CDN and some common configuration settings.

 

PHP short_open_tag = On should not be used

After a fresh installation you could find that PHP short_open_tag disabled by default in php.ini file.

 

You can check by using phpinfo() PHP function.

Under PHP Core setting you can find as below

 

Directive Local Value Master Value
short_open_tag Off Off

 

If “short_open_tag” is found off in your php.ini file then you cannot use short form (<? ?>) of PHP’s open tag and you must use long form of PHP tags (<?php ?>) instead, otherwise any PHP code inside these tags will not be parsed as PHP.

 

Drawback of PHP short_open_tag if you have enabled.

 

1) Setting this value to off allows for easier use alongside XML by providing the ability to use <?xml ?> inline without having to print it with PHP echo ‘<?xml version=”1.0″?>’; ?>.

 

With the wide spread use of XML(SOAP, XMLRPC, REST-XML) and use of these tags by other languages, the server can become easily confused and end up parsing the wrong code in the wrong context. But because this short cut has been a feature for such a long time, it’s currently still supported for backwards compatibility, but it’s recommend you don’t use them.

 

2) All the standard library use <?php ?>, full php tags so we can say it’s a standard, if you are open source script (distributable or portable script) writer or have PHP open sources community member then it’s always recommended to use full tag instead of short_tag as by default PHP have it disabled in php.ini settings.

 

3) Due to security reasons in some extent it’s advised to not to use short_open_tag.

 

If you still want to use short_open_tag or if you have just entered in a large application that is previously build by any other developer and he have used short_tags in many places, but your you php setting is was disabled then you should enabled short_open_tag, let me tell how you should do this quickly.

 

1) Open you root’s .htaccess file and add the following in that

php_flag short_open_tag on

or

php_value short_open_tag 1

 

2) If you php.ini access and can update any php directive and setting then open php.ini file and change
short_open_tag = Off to short_open_tag = On

It’s always advised to start Apache services after any changes in php.ini settings.

 

3)

 ini_set( "short_open_tag", 1 ); 

will not work, if you are trying to do as it (short_open_tag) is marked as PHP_INI_PERDIR in PHP < 5.3.0, which means you can’t change it with ini_set(). You can check this by below link.

 

Description of core php.ini directives

 

 

Advantages: Let Google Host jQuery For Your Website

Most of us (Web Developer) use JQuery during the development, if you are not aware about the jQuery or interested in any other JavaScript Library then below is just a very quick overview about the jQuery.

 

jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.”

 

Well, how you include that in your file, generally as below.

<script type="text/javascript" src="/js/jQuery.1.8.x.min.js"></script>

 

We all know that the load of JavaScript directly affect the site page load time and Obviously on SEO. Then how to get rid by jQuery?
No worries, you know as usual Google always help us so let Google host jQuery for your website.

 

You can let Google AJAX Libraries CDN (content delivery network) serve jQuery directly from Google’s network as below.
There are three main benefits of doing this is Decreased latency, Increased parallelism and Better caching that directory affect you site page load.

 

You should use/include JQuery as below

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>

 

Benefits of Google CDN Networks(Google hosted JavaScript Libraries)

 

Decreased Latency
A Content Delivery Network (CDN) distributes static content across various servers, diverse physical locations worldwide. When a user visits a page serving files from a CDN, their download will automatically target the closest available server in the network which can reduce download times.

 

Increased Parallelism
All browsers limit the number of connections that can be made simultaneously. Depending on which browser, this limit may be as low as two connections per hostname.
Using the Google AJAX Libraries CDN eliminates one request to your site, allowing more of your local content to be downloaded in parallel.

 

Better Caching
When a user visits a site, their browser will download static files so that when the user visits that page the files will not have to be downloaded again, saving bandwidth usage, server load.
Google AJAX Libraries CDN is that your users may not need to download jQuery at all.

 

If you’re curious why the <script> reference is missing the leading http:, It’s a trick which allows you to use a single reference that works on both HTTP and HTTPS pages.

 

“Protocol-less” URL is the best way to reference third party content that’s available via both HTTP and HTTPS.

 

WordPress .htaccess on Zeus Server Rewrites

WordPress .htaccess on zeus server rewrites (rather than Apache)

Yesterday, I got luck to transfer a WordPress website from one hosting to another.

 

The New hosting provider is http://www.names.co.uk and what I have found is it provides the web server Zeus instead of Apache as always I have worked on.

 

It is really a new experience for me as I have not worked on Zeus server before that.
Let’s discuss what is the main issue I have faced as WordPress move is not a difficult task.

 

You have to export import database and the path updates in database it’s very quick by following some simple queries.

move your wordpress site to a new domain – easy wordpress migration

And the other is just need to transfer files and need to update “wp-config.php”.

That’s it!

 

But what I have faced is, Zeus not supports mod_rewrite as this is a module for Apache servers.
So, Zeus doesn’t support .htaccess files which are required to make your site’s URLs look pretty and SEO friendly (WordPress with its Permalinks).

The file that you need to create is called rewrite.script and is Zeus equivalent to Apache’s .htaccess file.

 

Follow the below steps to work your WordPress site smoothly with permalinks.

The .htaccess File for default WordPress looks like this:

 

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

 

Zeus equivalent rewrite.script File

 

RULE_0_START:
# get the document root
map path into SCRATCH:DOCROOT from /
# initialize our variables
set SCRATCH:ORIG_URL = %{URL}
set SCRATCH:REQUEST_URI = %{URL}

# see if theres any queries in our URL
match URL into $ with ^(.*)\?(.*)$
if matched then
set SCRATCH:REQUEST_URI = $1
set SCRATCH:QUERY_STRING = $2
endif
RULE_0_END:

RULE_1_START:
# prepare to search for file, rewrite if its not found
set SCRATCH:REQUEST_FILENAME = %{SCRATCH:DOCROOT}
set SCRATCH:REQUEST_FILENAME . %{SCRATCH:REQUEST_URI}

# check to see if the file requested is an actual file or
# a directory with possibly an index. don’t rewrite if so
look for file at %{SCRATCH:REQUEST_FILENAME}
if not exists then
look for dir at %{SCRATCH:REQUEST_FILENAME}
if not exists then
set URL = /index.php?q=%{SCRATCH:REQUEST_URI}
goto QSA_RULE_START
endif
endif

# if we made it here then its a file or dir and no rewrite
goto END
RULE_1_END:

QSA_RULE_START:
# append the query string if there was one originally
# the same as [QSA,L] for apache
match SCRATCH:ORIG_URL into % with \?(.*)$
if matched then
set URL = %{URL}&%{SCRATCH:QUERY_STRING}
endif
goto END
QSA_RULE_END:

 

You can also download the “rewrite.script” file by the below URL.

Download rewrite.script file

Upload “rewrite.script” file to your WordPress root folder (the same folder that contains wp-config.php).

 

If your WordPress site in installed in a sub folder, update line 27 and include the folder to the path before /index.php.

Next you will have to go into the WordPress Settings > Permalinks and save your permalink choice again. This will force WordPress to rebuild the permalinks for the site.

 

You can safely delete the .htaccess file from the remote site as it is no longer needed.

 

I think your site is working now fine but you may notice that you have index.php at the start of all your URLs.
Go to the WordPress settings > Permalinks and update that to a custom structure permalink:

/%category%/%postname%/

 

I think it all works, if you still face any issue post your comments below.

What is a WordPress Child theme & how to customize WordPress Theme using WordPress Child theme?

We all know that a WordPress theme is a collection of template files which lets us change the user interface, design, look & feel of the site.

 

Have you created WordPress theme or have installed any free theme or commercial one, many of you have done this job and have also customized but the problem is created when you have customized the original theme files and the update of that theme is available and you never would like to update as your customization will get destroyed if you update that, but my recommendation is that you should always keep your plugins and themes updated to the latest version. So you should take care during the customization and never do the customization in original file and should create a child theme. But what does that mean, and how do you do it?

 

In WordPress 3. 0 or latest versions a new concept was added by WordPress core team and community named as “Child Theme”.

 

As per the WordPress Codex definition of Child Theme:

 

“A WordPress child theme is a theme that inherits the functionality of another theme, called the parent theme. 

Child theme allows you to modify, or add to the functionality of that parent theme. A child theme is the safest and easiest way to modify an existing theme, whether you want to make a few tiny changes or extensive changes. Instead of modifying the theme files directly, you can create a child theme and override within. “

 

How to work with WordPress Child Theme?

 

Let’s take an example; I’ll create a child theme for WordPress default ‘Twenty Twelve’ theme.

1) So in this case, to create a child theme, I have to create a new directory alongside the ‘Twenty Twelve’ theme’s directory called twentytwelve-child.
“twentytwelve-child” directory should be in parallel of original theme twentytwelve.

2) Create a style.css file under the ‘twentytwelve-child’ theme directory.

Put the below text in style.css file

/*
Theme Name:     Twenty Twelve Child
Theme URI:      http://wp. tutsplus.com/
Description:    Child theme for Twenty Twelve
Author:         Japh
Author URI:     http://wp. tutsplus.com/author/japh
Template:       twentytwelve
Version:        1. 0. 0
*/

// This @import line loads the stylesheet of parent theme
@import url('. . /twentytwelve/style.css');

//Theme customization starts here

There are two important parts here to notice:

Template: twentytwelve
It tells WordPress that this theme is a child theme of the ‘Twenty Twelve’ theme

@import url(“. . /twentytwelve/style.css”);
It loads the parent theme’s (twentytwelve in this case) style.css as a starting point

3) Now you can log into your WordPress dashboard and see your ‘Twenty Twelve Child’ theme there, and activate it.

4) Make further alterations & addition and you will found that these will automatically reflected on your website.

 

Just Done!!

 

Now always keep in mind that whenever you want to make a customization to your theme, does it in your child theme.

Files in your child theme override files of the same name in the parent theme. So any file from your parent theme you want to change, copy to your child theme & make your modifications there.

The same goes for any templates that may not be in your parent theme. You can add them in your child theme, and WordPress will use them.

One exception to these rules is the functions.php file. In this case, the functions.php file for the child theme is loaded first, followed by the functions.php file of the parent theme. So there’s no need to copy the functions.php file from the parent into the child, just start fresh in the child theme for that one.

This allows the child theme to have all the functionality from the parent theme. Parent themes can also make their function pluggable, which allows a child theme to override them.

 

Why should you use WordPress Child Themes?

 

1. Safe Updates

A child theme automatically inherits the parent theme’s features, styles, and templates. This allows you to make changes to your site using child themes without ever modifying the parent theme. When a new version of the parent theme available, you can safely update it as you know that all your modifications are saved in the child theme.

 

2. Easy to Extend
A child theme built on a powerful theme framework allows a great deal of flexibility without writing a lot of code. You can selectively modify only the template files and functions that you need without going through other template files. You can add new functionality and much more.

 

3. Fall-back Safe
When you are creating a complete theme you need to think about all the possible scenarios and code for them. However, when you are working on a child theme and you forget to code for something, then there is always the parent theme’s functionality available as the fallback option.

 

WordPress catchable Tools for Child Theme

 

One-Click Child Theme plugin built and tested for the latest WordPress 3.x version.It adds a menu link into your Admin “Themes” section to automatically build a child using your currently active theme.This is fantastic if you don’t want to mess with FTP and are looking to play around with some new ideas.You can also use Child Themify plugin for creating the child themes.

 

If you plan to edit these files within the admin panel you’ll also enjoy clearer syntax highlighting for that you can install the Advanced Code Editor for some much-improved functionality. This makes wading through PHP code blocks and HTML/CSS a whole lot more manageable.

 

Additional Resources & references

 

1. http://wp.tutsplus.com/tutorials/theme-development/child-themes-basics-and-creating-child-themes-in-wordpress/

2. http://www.hongkiat.com/blog/wordpress-child-themes-dev/

 

Hope this all helps.