Subscribe:

Ads 468x60px

Pages

Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts

Friday, August 19, 2011

Analyzing Web sites with Webalizer

The Webalizer is a fast, free web server log file analysis program. It produces highly detailed, easily configurable usage reports in HTML format, for viewing with a standard web browser.

The Webalizer is a freeware software package which interprets a web site's log file data and displays this data in HTML format. Its is a highly configurable application which can be deployed on both Windows and Unix platforms. The Webalizer can be installed on a web server to provide statistics online, or can be installed on a local hard disc to provide statistics offline. The Webalizer web log analysis software was created by Bradford L. Barrett

The Webalizer. It is intended to explain what statistics are displayed and how the data can be used to provide an insight into the activity of the web site, for the purpose of marketing analysis and future web development. This manual does not provide information on how to install or configure the Webalizer. Information regarding installation and configuration of The Webalizer  is available from the developer's web site. Download The Webalizer software here.


The Usage Statistics Overview page details:
  1. The web site to which the statistics are applicable (displayed in the title)
  2. The summary period for the statistics (for example, "last 12 months")
  3. The last time the statistics were generated (date and time stamp)
Webalizer depends upon the gd graphics library so you will need to installgd first .

Install gd package
# yum install gd

Install webalizer package
# yum install webalizer

Check whether the webalizer installed or not
# rpm -qa | webalizer

your browser to http://localhost/webalizer/ to see what you have. If you do, the only thing you’ll see is:

Not Found
The requested URL /webalizer/ was not found on this server.

# rpm  -ql  webalizer

/etc/cron.daily/00webalizer
/etc/webalizer.conf /var/www/usage


Note: The directive “outputDir    /var/www/usage ” must be changed to “outputDir  /var/www/html/webalizer”
# mkdir  /var/www/html/webalizer
# cp  /var/www/usage/*   /var/www/html/webalizer

Wait the cronjob to execute webalizer (probably the next day ) , or run it manually for now  –> webalizer .

Access with your browser locally or remotely .
# firefox http://localhost/webalizer/ &
# firefox http://192.168.1.xx/webalizer &


Read more...

Wednesday, August 10, 2011

Custom Error Page with .htaccess

404 Page Not Found
When you type wrong URL in a address bar for any website then you usually get the following error with the message.
The 404 is error code in http which represents that “file is not found” in the server.
To display your own custom error page:
create a .htaccess file in the root of the web server and place the following code in that file. 
ErrorDocument 404 /errror404.htm

This would cause any error code resulting in 404 to be forwarded to example.com/error404.html.
In the above line ErrorDocument is a server directive and 404 is the server status code and last part is the name of the error page created by yourself.

If you want to create the custom error page for the codes 404 and 400 (bad request) then you can put the two following lines in .htaccess file.
ErrorDocument 404 /errror404.htm
ErrorDocument 400 /errror400.htm


Note : Never try to put a ErrorDocument for code 200 which mean that page is found and causes the infinite loop in the server.

Read more...

Prevent Directory Listing using .htaccess

Directory Listing
Directory listing:
In most of the website contains “images” folder inside the root folder. If we type “www.example.com/images” in the browser and it shows the listing of the files in the browser like the image above which means that directory listing is allowed on that web server. It’s better not to show the files inside the directory of the web sever for the security purpose.

To prevent directory listing
Put the any one of following code into the .htaccess file
Options -Indexes

or

IndexIgnore *


If you don’t want to list “.jpp , .gif and .zip” and you don’t care about listing other files of that directory then you can out the following code inside .htaccess.
IndexIgnore *.gif *.jpg *.zip

If your want to allow directory listing then you can add the following code in the .htaccess file to allow the directory listing.
Options +Indexes
Read more...

Change Default Directory index page using .htaccess


Default index pages in the webserver is index.html.

For example: When the index page as "index.html" is place in the document root of the apache. when you are typing url in the web browser as "www.example.com" then the default page "index.html" will be appears.

The default directory index pages are defined in the apache’s configuration file and it can be override from .htaccess file. To do so put the following code in the .htaccess file,

 
DirectoryIndex index.html index.htm index.php index.cgi


Remember that you can also append the other names of files in the DirectoryIndex directive and the order of the above “DirectoryIndex” directive determines the order of index file in web directory.



Read more...

Need of .htaccess file



.htaccess files may be used by all of our customers to manipulate the Apache web server, a powerful part of our Linux hosting service . You have full access to .htaccess on all of our Linux web hosting plans which include Semi Dedicated Servers as well.


      .htaccess offers webmasters a new level of control over their hosting thereby allowing them to take charge. Simple server-side Apache directives can allow you to set up countless unique features, few of those are :
* Password protected folders
* Custom error pages
* Blocking specific IPs
* Blocking specific users and sites
* Add new MIME types
* Prevent / allow directory listings
* 301 redirects (search spider safe)
* Change your default index page
* Control hotlinking abuse
* Rewrite dynamic pages as static

Read more...


To redirect the site from http to https
http -  Hypertext Transfer Protocol
https - Hypertext Transfer Protocol over Secure Socket Layer

Most of the sites uses “http” protocol and you can see “http” in the browser’s address bar. But in the e-commerce websites (such as shopping carts) uses payment gateway for online payment. And, those sites uses SSL (secure socket layer) connection to transfer data to and from the payment gateway.


For example, if you type “http://www.gmail.com” in browser after a while the “http” gets converted to “https” in address bar, which means this site is transferring the data over SSL protocol.

To redirect the browser to https when site is using http protocal in PHP

1. SSL must be installed in the server. 
2. Function to redirect the browser to “https” in PHP

Function to redirect the browser to “https” in PHP

function redirectToHTTPS()
{
  if($_SERVER['HTTPS']!="on")
  {
     $redirect= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
     header("Location:$redirect");
  }
}
you can call the  function in Index page to redirect the browser to “https”.

Redirecting whole website to “https” using .htaccess

You can call the above function in all pages to redirect the browser to “https”. Instead of placing the function in every page just write three line of code in .htaccess file to redirect the whole website to use SSL connection throughout the pages.

  RewriteEngine On
  RewriteCond %{HTTPS} !on
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Read more...

Tuesday, August 9, 2011

Fix Internal Server Errors for Apache


How to Fix Internal Server Errors for Apache Linux and cPanel

This is a usual scenario where users might come across such Internal Server Errors.
What do I need to do in this case ?
You should understand that the “Internal Server Error” doesn’t always necessary be due to a server problem. It may also be due to some problem within your files as well.
Let us see how you can identify the actual reason and the solution to a particular Internal Server Error
  • An issue with the .htaccess file
  • Any particular or multiple files and folders have permissions higher than 755 and the server holding it doesn’t allow the level of permissions. Though any software or applications which require 777 permissions will work with 755 permission on our servers.
  • An incorrect PHP version within the “PHP Configuration” section.
  • The username does not own the folder or files.
How to know the exact cause of the Internal Error ?
There is nothing to worry about. Most of these errors can be fixed.
Before proceeding, it is important that you back-up database using the “Backups” section of your cPanel or through file manager or through an FTP client. Check ( How to Backup Database from PHPMyAdmin ) for detailed backup procedure. If you are one of our existing customers, you need not worry about backups since we take backups of all our servers on a regular basis. Upon request, we can help you restore your files. Still, it is always best to maintain backups or sign-up for our R1Soft BackUp plans.
  • Using an FTP client, login to your cPanel by entering your cPanel details in the required boxes of the FTP ie, username, password, port etc. and hit the “Quick Connect” button.
FileZilla or WSFTP pro FTP clients can be used .
Host: websitename.com
Username: cpanel username
Password: cpanel password
  • Look for “public_html”, double click it:
  • Find the “.htaccess” file. You must now double click it inorder to get that onto your local machine. Let this file stay there on your local machine until you are done with the procedures mentioned. Right click “.htaccess” file in the FTP and rename it to “.htaccess2?”
Refresh it once and check your website if its working fine. If yes then that means there is a problem within the “.htaccess” file. Now, you need to get your developers into action. Get the errors rectified from them and upload it back to the same location on the server.
What if it still does not work ?
Incase if the folder is causing the errors and not the public_html, then you must go to the folder that has the .htaccess file. Rename the folder and try if that works.
No use, what next ?
Before proceeding further, we want you to ensure if you have the backup of your files.
Right click on “public_html”, then click on “File Permission”, change the permissions to 755, and checkmark “Recurse into Subdirectories
Now again, go back to your website and check if you still face the same error. If all is working fine, then you have sorted out the problem on your own without the need of help from anyone.
But the problem hasn’t been sorted, what should I do now ?
If you still face the same error, you can login to your cPanel, then look for the “PHP Configuration”. Make changes to the the PHP version from default value to either php5 or php4. That should solve your problem. 
Read more...

Monday, August 8, 2011

What is mod_pagespeed


mod_pagespeed is an apache module that automatically optimizes webpages which are writen in Javascript, HTML, CSS, and images. It does this by rewriting the resources using filters that implement web performance best practices.
Webmasters and web developers can use mod_pagespeed in order to improve the performance of their web pages when serving content with the Apache HTTP Server.


How to install mod_pagespeed on linux dedicated server.

Mod_pagespeed needs mod_deflate to be loaded in Apache.

Following are the steps to install mod_pagespeed with Apache v2.2 + CPanel server running on CentOS 5.5 (32-bit):
[root@server]# cd /usr/src
[root@server src]# wget https://dl-ssl.google.com/dl/linux/d...rrent_i386.rpm
[root@server src]# mkdir mod-pagespeed
[root@server src]# cd mod-pagespeed
[root@server mod-pagespeed]# rpm2cpio ../mod-pagespeed-beta_current_i386.rpm | cpio -idmv

you will get the result as
./etc/cron.daily/mod-pagespeed
./etc/httpd/conf.d/pagespeed.conf
./usr/lib/httpd/modules/mod_pagespeed.so
./var/mod_pagespeed/cache
./var/mod_pagespeed/files
3135 blocks


[root@server mod-pagespeed]# cp ./etc/httpd/conf.d/pagespeed.conf \
/usr/local/apache/conf/
[root@server mod-pagespeed]# cp ./usr/lib/httpd/modules/mod_pagespeed.so \
/usr/local/apache/modules/
[root@server mod-pagespeed]# chmod 755 /usr/local/apache/modules/mod_pagespeed.so
[root@server mod-pagespeed]# mkdir /var/mod_pagespeed/{cache,files} -p
[root@server mod-pagespeed]# chown nobody:nobody /var/mod_pagespeed/*

Now edit /etc/httpd/conf/httpd.conf and add the line

Include “conf/pagespeed.conf”

then edit /usr/local/apache/conf/pagespeed.conf and update the paths as
# vim /usr/local/apache/conf/pagespeed.conf

LoadModule pagespeed_module /usr/src/mod-pagespeed/usr/lib/httpd/modules/mod_pagespeed.so

LoadModule deflate_module modules/mod_deflate.so

Now restart apache service
[root@server mod-pagespeed]# service httpd restart 
Read more...

Enabling CGI on Apache 2.x


For more information, do ready up the Apache Tutorial: Dynamic Content with CGI which provides with a easy-to-read configuration if you wish to enable CGI on the Apache 2.x


The ScriptAlias directive tells Apache that a particular directory is set aside for CGI programs. Apache will assume that every file in this directory is a CGI program, and will attempt to execute it, when that particular resource is requested by a client.

ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/


Explicitly using Options to permit CGI execution

You could explicitly use the Options directive, inside your main server configuration file, to specify that CGI execution was permitted in a particular directory:

<Directory /usr/local/apache2/htdocs/somedir>
     Options +ExecCGI
      AddHandler cgi-script .cgi .pl
</Directory>


User Directories

To allow CGI program execution for any file ending in .cgi in users' directories with a cgi-bin extension, you can do the following:

<Directory /home/*/public_html/cg-bin>
Options +ExecCGI
AddHandler cgi-script .cgi .pl
</Directory>
Read more...

Monday, July 4, 2011

Apache: Website or Web page redirection using a .htaccess file?


Let us see how do we set different types of redirection by using .htaccess file.
The following is the generic syntax to do the redirection.
Redirect /dir1/file1.html http://abcd.com/dir2/newfile.html

1. Redirect the site from without www to with www
This is used to redirect all users who access the site without the www. prefix.For example if you want to redirect all requests which are pointing to http://abcd.com/ to http://www.abcd.com.
Add the following line to the .htaccess file
1
2
3
4
5
# mod_rewrite in use
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^abcd.com [NC]
RewriteRule ^(.*)$ http://www.abcd.com/$1 [R=301,L]


2. Redirect the site from with www to without www
This is used to redirect all users to access the site with the www. prefix.
This is another common requirement.For example if you want to redirect all requests which are pointing to http://www.abcd.com/ to http://abcd.com. This can be easily achieved by adding a few lines of code into the .htaccess file.Even You can make your webserver so that if someone requests http://www.abcd.com/, it does a 301 (permanent) redirect to http://abcd.com/
Add the following line to the .htaccess file
1
2
3
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.abcd\.com$ [NC]
RewriteRule ^(.*)$ http://abcd.com/$1 [L,R=301]
3. Redirect index.html to a specific sub-folder
You can redirect your default index file to a different directory or file.
Add the following line to the .htaccess file
1
2
3
 
# Redirect index.html to a newdirectory subfolder
Redirect /index.html http://globinch.com/newdirectory/
4. Redirect the entire site to a different URL
Add the following line to the .htaccess file
1
2
3
 
# Redirect your entire website to any other domain
Redirect 301 / http://globinch.com/
5. DirectoryIndex to redirect to specific index page:
1
2
# Specify Specific Index Page
DirectoryIndex index.html
6. Redirect to secure version of your domain
This allows the users to redirect to secure site (https://)
Add the following line to the .htaccess file
1
2
3
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.abcd.com/$1 [R,L]
This is document is found from this site: http://www.globinch.com/2010/03/25/website-or-web-page-redirection-using-a-htaccess-file/

Please feel free to comment to make it more useful to everyone.
Read more...