Tuesday, 12 February 2013

How to create Virtual host


Virtual host

You now need to create an Apache virtual host for the application and edit your hosts file so that http://zf2-tutorial.localhost will serve index.php from the zf2-tutorial/public directory.
Setting up the virtual host is usually done within httpd.conf or extra/httpd-vhosts.conf. If you are using httpd-vhosts.conf, ensure that this file is included by your main httpd.conf file. Some Linux distributions (ex: Ubuntu) package Apache so that configuration files are stored in /etc/apache2 and create one file per virtual host inside folder /etc/apache2/sites-enabled. In this case, you would place the virtual host block below into the file /etc/apache2/sites-enabled/zf2-tutorial.
Ensure that NameVirtualHost is defined and set to “*:80” or similar, and then define a virtual host along these lines:
<VirtualHost *:80>
    ServerName zf2-tutorial.localhost
    DocumentRoot /path/to/zf2-tutorial/public
    SetEnv APPLICATION_ENV "development"
    <Directory /path/to/zf2-tutorial/public>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
Make sure that you update your /etc/hosts or c:\windows\system32\drivers\etc\hosts file so that zf2-tutorial.localhost is mapped to 127.0.0.1. The website can then be accessed usinghttp://zf2-tutorial.localhost.
127.0.0.1               zf2-tutorial.localhost localhost
Restart your web server. If you’ve done it right, you should see something like this:

Saturday, 22 December 2012

How install Apache 2.4 PHP 5.4 and MySQL 5.5.21 on Windows 7


Recently decided to install a working Apache 2.4 / PHP 5.4 and MySQL 5.5 running locally on my Windows 7 laptop for web design, not using XAMPP or WAMP installation methods. Which are great but this round I wanted to match my Linux server.
Apache 2.4 Install
First download Apache 2.4 from http://www.apachelounge.com/download/ (httpd-2.4.1-win32.zip) Apache 2.4.1
with IPv6 apr-1.4.6 apr-util-1.4.1 apr-iconv-1.2.1 pcre-8.21 lua-5.1 libxml2-2.7.8 openssl-1.0.0g zlib-1.2.6. This release is supported by the PHP 5.4 install from windows.php.net for Apache 2.4.
Extract the zip and copy it to the root of C:\. This will be C:\Apache24 when it is all done.
Download PHP 5.4 VC9 x86 Thread Safe from http://windows.php.net/download/ . Extract and rename folder to php and move to C:\
Also, download php5apache2_4.dll-php-5.4-win32.zip(http://www.apachelounge.com/download/win32/modules-2.4/php5apache2_4.dll-php-5.4-win32.zip)
Runs with PHP 5.4 Thread Safe (TS), and only with Apache 2.4 Win32 VC9 or VC10.
Extract php5apache2_4.dll-php-5.4-win32.zip and copy php5apache2_4.dll to thec:\php\ext directory. This is needed to allow Apache to use PHP.  Edit Apache’s config file, c:\Apache24\conf\httpd.conf and add the following lines to the bottom of the file.
LoadModule php5_module "c:/php/ext/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"
While we are at it we can add index.php to Apache’s list just incase we want to have a starting page as php.
Find Directory index and add index.php
DirectoryIndex index.html index.php
Next we need to input a value  for ServerName variable. You will have to un-comment it. Save the changes to the config file.
Now let’s register Apache as a service. Open a command prompt and type.
c:\apache24\bin\httpd -k install
If do not want Apache starting automatically at start-up/reboot:
GUI Way
  • START | RUN
  • Type in services.msc, hit Enter or click OK
  • Locate Apache2 service and double-click (or right-click for Properties)
  • Find the caption Startup type: (in the middle of the dialog box), use the pull-down and select Manual
  • Click OK
Command line
C:\> sc config Apache2.4 start= demand
Add
c:\Apache24; c:\Apache24\bin
to PATH in Environment variables. PATH ENVIRONMENT (System Properties | Advanced | Environment Variables | System variables | Path).
Example:
;c:\php;c:\apache24;c:\apache24\bin;
Now lets check Apache settings by issuing the command, c:\Apache24\bin\httpd -S
PHP Edits
Now we have to do a few edits to the php.ini file to tell it to load support for mysql and the location for the extensions. Since there is not a already set php.ini file we need to rename one of the two examples to php.ini.
Rename c:\php\php.ini-development to php.ini
Now let’s edit php.ini
Uncomment extension directory
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"

Uncomment mysql modules
extension=php_mysql.dll
extension=php_mysqli.dll
Save the changes and open a command prompt. Check to make sure it shows loaded modules.
C:\> php -m
So now we have Apache running and configured to use php. Lets create a file called info.php, save it and see if Apache parses the info correctly to display the results.
Open Notepad or your favorite Windows editor and type and save the following.
 <?php
phpinfo();
?>
Open your browser and type, localhost/info.php for the location and you should receive alot of information about PHP.
MySQL
Download and install mysql-5.5.21-win64.msi. Change installation directory to C:\MySQL\MySQL Server 5.5 instead of Program files as there could be permissions issues. Once the installation is completed you can let the configuration wizard run and setup the database server. The defaults will work just fine, but remember what you set the password to for root.
PHPMyAdmin
PHPMyAdmin is a very nice tool to use for administering your MySQL installation.
Download and install phpmyadmin-3.4.10.1-english.zip.
Extract the file and move to c:\apache24\htdocs. Rename directory to phpmyadmin.
Create a config directory under phpmyadmin. Open a browser and type localhost/phpmyadmin/setup/index.php to complete the installation.
At this point you should have a working Apache / PHP / MySQL installation running and ready for you to start developing !!!

Thursday, 4 October 2012

External urls

If there are external urls on your website and you want to followed or indexed by search engine. 

There are two parameters; "index" and "follow".

"Index" refers to whether or not you want that particular page to be indexed.  


"Follow" refers to whether or not you want the spider to follow the links on that page.

You would decide whether you wanted the page indexed, and whether you wanted the links followed. Based on that decision, you would chose one of the above options

 This is very important for SEO. 

eg: http://sitejabber.com is a external link on your website, then in html of the link.

<a href="http://sitejabber.com" rel=" noindex , nofollow" target="_blank">Click here</a>

or 

<a href="http://sitejabber.com" rel="index , nofollow" target="_blank">Click here</a>

Robot metatags


About the Robots <META> tag

In a nutshell

You can use a special HTML <META> tag to tell robots not to index the content of a page, and/or not scan it for links to follow.
For example:
<html>
<head>
<title>...</title>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
</head>
There are two important considerations when using the robots <META> tag:
  • robots can ignore your <META> tag. Especially malware robots that scan the web for security vulnerabilities, and email address harvesters used by spammers will pay no attention.
  • the NOFOLLOW directive only applies to links on this page. It's entirely likely that a robot might find the same links on some other page without a NOFOLLOW (perhaps on some other site), and so still arrives at your undesired page.
Don't confuse this NOFOLLOW with the rel="nofollow" link attribute.

The details

Like the /robots.txt, the robots META tag is a de-facto standard. It originated from a "birds of a feather" meeting at a1996 distributed indexing workshop, and was described in meeting notes.
The META tag is also described in the HTML 4.01 specification, Appendix B.4.1.
The rest of this page gives an overview of how to use the robots <META> tags in your pages, with some simple recipes. To learn more see also the FAQ.

How to write a Robots Meta Tag

Where to put it

Like any <META> tag it should be placed in the HEAD section of an HTML page, as in the example above. You should put it in every page on your site, because a robot can encounter a deep link to any page on your site.

What to put into it

The "NAME" attribute must be "ROBOTS".
Valid values for the "CONTENT" attribute are: "INDEX", "NOINDEX", "FOLLOW", "NOFOLLOW". Multiple comma-separated values are allowed, but obviously only some combinations make sense. If there is no robots <META> tag, the default is "INDEX,FOLLOW", so there's no need to spell that out. That leaves:
<META NAME="ROBOTS" CONTENT="NOINDEX, FOLLOW">
<META NAME="ROBOTS" CONTENT="INDEX, NOFOLLOW">
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">

To secure specific urls of a website

Sometimes we need some urls https and others http, This can also done bye htaccess easily.


### AR SSL ######
RewriteEngine on 
Options +FollowSymlinks 
RewriteCond %{SERVER_PORT} ^443$ 
RewriteRule ^robots.txt$ robots_ssl.txt

In robot.txt i have given the some specific folder path or some file type which can be allow or disallow to a visitor

robot.txt:

# allow all
User-agent: *

Disallow: /backup/
Disallow: /site/
Disallow: /*.php
Disallow: /*% 
Disallow: /*? 
 
robot_ssl.txt
# SSL robots

User-agent: *
Disallow: / 

#User-agent: *
Allow: /signup/
Allow: /register/
Allow: /user/forgotpass/
 
So signup, forgot password and login page would be https and others would be http.
 
please give feedback if you want to.

To restrict files acess on server from htaccess


There should be security on your web server to restrict the access of some file types. This can be done by htaccess file.
# Exclude file types # AR 26/6/2012
<FilesMatch "\.(htaccess|htpasswd|ini|log|sh|inc|bak|tar|gz|sql|zip)$">
Order Allow,Deny
Deny from all
</FilesMatch>
 
Enjoy! 

Add trails in all urls of website

Google search is very much based on '/' in the url's end. We can do it easily with htaccess. Here is the code.


### AR add trailing slash ######
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]

Hope this would be useful for you!!