Sunday, February 27, 2011

Apache is running super slow Xampp / Wamp / Stand-Alone

Recently, I found that my apache running super slow, as I do my most of the developments on the local host this was an unacceptable, and I know there is no good reason for this. And finally I figured out this is coming from my hosts file.

In there a line of code for 127.0.0.1 to some strange ip address fortunately I found it is not malicious and it was my previous ip address some how entered automatically there.

I remove that line and add following to it.

## Localhost
127.0.0.1 127.0.0.1

127.0.0.1 localhost

And now it is working super fast. For your knowing this is a little guide to windows, it says if I'm tries to go to localhost just redirect me to 127.0.0.1, not to any other address.

Friday, February 18, 2011

Fix An Unexpected HTTP Error occurred during the API request Wordpress Error

This error can happen either your default timeout limit is not enough or.
If you're developing on localhost, may be your firewall blocks the apache http.exe server.

If your site is hosted on a web server, and you see the error message 'An Unexpected HTTP Error occurred during the API request' after requesting a page on WordPress Admin Dashboard and you are getting this error frequently on your dashboard, then it means you have to increase the wordPress timeout limit for every request. To do that

  1. Open your FTP Client software
  2. locate the file "class-http.php" inside "wp-includes" folder.
  3. And find the code "'timeout' => apply_filters( 'http_request_timeout', 5)" and change the timeout limit to 30. (5 --> 10)
If you're developing on localhost then, and if you see this error mean your server software being blocked by the firewall or you dont have an active internet connection. To fix this,

  1. Make sure your connection is active (probably you checked already)
  2. And make sure server software in not blocked. In my case, it is httpd.exe (Apache HTTP Server) This is only required if you're accessing to the internet for something like plugin installation and, etc....

Get Current File Name using PHP

There are two ways I found to get the current page name using php.

<?php
$path = $_SERVER["SCRIPT_NAME"];
$file = basename($path); // $file is set to "myfile.php"
$file = basename($path, ".php"); // $file is set to "myfile"
?>


<?
$currentFile = $_SERVER["SCRIPT_NAME"];
$parts = Explode('/', $currentFile);
$parts = array_reverse($parts);
echo("Script is " . $parts[0]);
?>

Stylesheet (CSS) Media Types

One of the most important features of style sheets is that they specify how a document is to be presented on different media: on the screen, on paper, with a speech synthesizer, with a braille device, etc.

Certain CSS properties are only designed for certain media. Stylesheets for different media types may share a property, but require different values for that property. For example, the 'font-size' property is useful both for screen and print media. The two media types are different enough to require different values for the common property; a document will typically need a larger font on a computer screen than on paper. Therefore, it is necessary to express that a style sheet, or a section of a style sheet, applies to certain media types.
  1. all -- Suitable for all devices.
  2. braille -- Intended for braille tactile feedback devices.
  3. embossed -- Intended for paged braille printers.
  4. handheld -- Intended for handheld devices (typically small screen, limited bandwidth).
  5. print -- Intended for paged material and for documents viewed on screen in print preview mode.
  6. projection -- Intended for projected presentations, for example projectors.
  7. screen -- Intended primarily for color computer screens.
  8. speech -- Intended for speech synthesizers. Note: CSS2 had a similar media type called 'aural' for this purpose.
  9. tty -- Intended for media using a fixed-pitch character grid (such as teletypes, terminals, or portable devices with limited display capabilities). Should not use pixel units with the "tty" media type.
  10. tv -- Intended for television-type devices (low resolution, color, limited-scrollability screens, sound available).
Notes:
  • Media type names are case-insensitive
  • Media types are mutually exclusive in the sense that a user agent can only support one media type when rendering a document.
  • User agents may use different media types on different canvases. E.g. a document may (simultaneously) be shown in 'screen' mode on one canvas and 'print' mode on another canvas.
Specifying media-dependent Stylssheets
  • Specify the target medium from a style sheet with the @media or @import at-rules.
Example(s):
@import url("fancyfonts.css") screen;
@media print {
/* style sheet for print goes here */
}
  • Specify the target medium within the document language.
<link rel="stylesheet" type="text/css" media="print, handheld" href="style.css">

Thursday, February 17, 2011

Must have Wordpress Plugins all the time

Google XML Sitemaps
This plugin will generate a special XML sitemap which will help search engines like Google, Bing, Yahoo and Ask.com to better index your blog. With such a sitemap, it's much easier for the crawlers to see the complete structure of your site and retrieve it more efficiently. The plugin supports all kinds of WordPress generated pages as well as custom URLs. Additionally it notifies all major search engines every time you create a post about the new content.


WP-DBManager

Allows you to optimize database, repair database, backup database, restore database, delete backup database , drop/empty tables and run selected queries. Supports automatic scheduling of backing up and optimizing of database.


W3 Total Cache

The fastest and most complete WordPress performance plugin. Dramatically improve the speed and user experience of your site. Add browser, page, object and database caching as well as minify and content delivery network (CDN) to WordPress.


cbnet Different Posts Per Page

Show different numbers of posts on home, archive, and search pages. This plugin will allow you to modify the number of posts shown on home, archive (category, date, author, etc.), search pages and feeds. You can even set the order of posts by ascending or descending order.


Post Editor Buttons

This plugins allows you to add your own buttons to the post edtor's toolbar. (buttons that you see above your content text area when editing posts (b,i,link,img,ul,li)).


All in One SEO Pack
Automatically optimizes your WordPress blog for Search Engines (Search Engine Optimization).

Search plugins: Wordpress Plug-ins directory

How to use WordPress Action Hooks

Why Action Hooks?
Let's think there is no concept called Action Hooks. When we wanted to change or extend some function of WordPress then probably we wanted to change core files of wordpress installation. And when it comes time to upgrade wordpress, you'll have to recoding all the modifications you have done to prior version files, or you'll have to stick with the old version.


What are Action Hooks.
When it comes to above type of scenario wordpress action hooks are become more handy. For an example let's take very common wordpress action like "wp_head" or "wp_footer". Using action hooks, we can execute a function when certain wordpress action(action we define in hook) execute.

For an example, I need to perform my function "addNewCss" when wordpress action wp_head encounter. To do that simply I can use wordpress hooks

<?php
function addNewCss() {
//function content goes here.
}
add_action('wp_head', 'addNewCss', 5);
?>

This will execute my function addNewCss when it encountered wp_head action and the priority is 5. Which makes run this function earlier. Default is 10. (setting it to 5 would make it run earlier and setting it to 12 would make it run later.


Creating Own Action Hooks
Sometimes you may want to create own action hooks then others can extend your code functionality without touching your codes and make those in separate files. To do that use,

<?php do_action('mynew_action_hook'); ?>

Now, anyone can come hook their own function to your "mynew_action_hook".

Install Wordpress in a different Directory other than root directory

Why:
1. Security Reasons (No one can find your wordpress files unless they are pretty smart)
2. Keeps your root directory clean.
  1. Create a folder inside your root directory "public_html" and need to be long and un-guessable "HelloDirecotryName"
  2. Export wordpress package into it
  3. And Move the files index.php and the .htaccess to the root directory
  4. Next open index.php file and change
require('./wp-blog-header.php');
…to this
require('./helloDirecotryName/wp-blog-header.php');

5. Now every time you login to your system you'll have to use exact path http://mywordpressite.com/HelloDirecotryName/wp-admin/
6. Once you login to your dashboard go to Settings >> General Settings and ensure
  • WordPress address (URL) points to http://mywordpressite.com/HelloDirecotryName/
  • Site address (URL) http://mywordpressite.com/

Install wordpress on localhost(Own Computer) with WAMP

Complete guide to install wordpress locally (localhost) with wamp
  1. Download and unzip the WordPress package
  2. Install WAMP and open phpmyadmin
  3. Create a DATABASE for wordpress (CREATE DATABASE wordpress_db)
  4. Open WWW folder (inside wamp installation directory)
  5. Unzip wordpress package there
  6. Rename the wp-config-sample.php file to wp-config.php
  7. Open wp-config.php in a text editor
  8. Locate the following
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

9. Fill with appropriate settings
  • database_name_here == database you created
  • username_here == root (most of the time)
  • password_here == password for root, most of the time leave black (if you not set a password for root)
10. Next Locate the "Authentication Unique Keys and Salts" and click link there to generate Unique Keys and Salts

Replace following with with generated one
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');

11. If you like to have multiple wordpress installations with one DB (Optional)
Find $table_prefix = 'wp_'; and create a unique prefix (I always love to do so, normally I use wordpress version $table_prefix = 'wp_305'; )

12. Now run wp-admin/install.php using a web browser (in my case http://localhost/wordpress/wp-admin/install.php )

13. Opened window create
  • site title
  • User Name
  • Password
  • and Your E-mail (password recovery)
  • Uncheck "Allow my site to appear in search engines like Google and Technorati" (as you on localhost)

14. Click Install


15. Now if it is successful(as it should), you'll be able to login to your wordpress dashboard via login link

Wednesday, February 16, 2011

Setting a Password for user 'root' WAMP

Once you may installed wamp it gives this error (As it does ever time)

"Your configuration file contains settings (root with no password) that correspond to the default MySQL privileged account. Your MySQL server is running with this default, is open to intrusion, and you really should fix this security hole by setting a password for user '.root'."

To fix this you have to set "password" for user "root" (default it hasn't any password)
  1. Open phpmyAdmin( where this error occur)

  2. click Privileges tabROOT password set WAMP
  3. Select user 'root' and Edit privileges
    WAMP password set for user root

  4. In next opened window locate "Change password"

  5. Select radio "password" and type your password and make sure retype it too and click "GO"


Now we have to configure "config.inc.php" for phpmyadmin otherwise we won't be able to access our mysql databases via phpmyadmin as it default comes with no password but now our mysql server expecting a password from every application that want to connected to it.
  1. Locate the config.inc.php file in my case it is in the directory "c:\wamp\apps\phpmyadmin3.2.0.1"
  2. Find "$cfg['Servers'][$i]['password']" and type your password there "$cfg['Servers'][$i]['password'] = 'yourPassHere';"
  3. Save


and we done