Solved: DirectoryIndex not allowed here

When I tried to run my one of my project on server I got following error on the Browser.:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

When I got above error I opened the error log file.

Error Log File log(#vim /var/log/httpd/error_log)
[Wed Oct 14 12:02:56 2009] [notice] mod_python: Creating 4 session mutexes based on 256 max processes and 0 max threads.
[Wed Oct 14 12:02:56 2009] [notice] mod_python: using mutex_directory /tmp
[Wed Oct 14 12:02:56 2009] [notice] Apache/2.2.9 (Unix) DAV/2 PHP/5.2.6 mod_python/3.3.1 Python/2.5.1 mod_ssl/2.2.9 OpenSSL/0.9.8g mod_perl/2.0.4 Perl/v5.10.0 configured — resuming normal operations
[Wed Oct 14 12:02:59 2009] [alert] [client 127.0.0.1] /var/www/html/your_domain_name/.htaccess: DirectoryIndex not allowed here, referer: http://your_domain_name.org/
[Wed Oct 14 12:03:29 2009] [alert] [client 127.0.0.1] /var/www/html/your_domain_name/.htaccess: DirectoryIndex not allowed here, referer: http://your_domain_name.org/
[Wed Oct 14 12:11:13 2009] [notice] caught SIGTERM, shutting down
[Wed Oct 14 12:11:13 2009] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Oct 14 12:11:13 2009] [notice] Digest: generating secret for digest authentication …
[Wed Oct 14 12:11:13 2009] [notice] Digest: done

At the end of file I saw above error.

When I saw that I opened the httpd.conf file and I searched for line.

AllowOverride None

I commented this line.
#AllowOverride None

Then I added following lines to that tag
Order allow,deny
Allow from all

Then I saved the httpd.conf file and restarted the apache server.

This solved the my issue.

solved: [warn] _default_ VirtualHost overlap on port 80, the first has precedence

Here I am using the Fedora 9 for this example. I solved the issue of _default_ VirtualHost overlap on port 80 warning in linux

If you want to host many sites on one computer or machine.
I added following lines to httpd.conf file(end of file).

[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]

<VirtualHost  *:80>

Options +FollowSymLinks
ServerName example1.com
DocumentRoot /var/www/html/example1

VirtualHost>

<VirtualHost  *:80>

Options +FollowSymLinks
ServerName example2.com
DocumentRoot /var/www/html/example2

</ VirtualHost>

[/viral-lock]

When I restarted the apache server using following command.
#su
#ROOT_PASSWORD
#/etc/init.d/httpd restart

I got the following error;
[warn] _default_ VirtualHost overlap on port 80, the first has precedence

Again I opend the httpd.conf tile and I read following lines;
#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80

# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#

Than only I uncommented following line and restarted the Server.

NameVirtualHost *:80

My promlem get solved.

Solved issue -Directory index forbidden by Options directive:

I want to change the default location of Apache folder which is (var/www/html).
I am using the Fedora as OS and apache 2 here. you can use following code with any linux box like centos or ubuntu. Here we solved the issue of directory.

When I inserted the following code in bottom of the httpd.conf file.
<VirtualHost *:80>
Options +FollowSymLinks
ServerAdmin siwan@yahoo.co.in
DocumentRoot /var/www/html/testfolder
ErrorLog logs/error_log_net
TransferLog logs/access_log_net
</VirtualHost>

When tried the http://localhost/ in browser, I got the default browser page.
Then I tried to look my apache error using following command:
#[root@localhost ]# tail -f /var/log/httpd/error_log

In apache error log I got following error.
[Wed Oct 07 15:59:50 2008] [error] [client 127.0.0.1] Directory index forbidden by Options directive: /var/www/html/testfolder/

I changed the AllowOverride option but nothing is happens. Then I read the welcome page text
“To prevent this page from ever being used, follow the instructions in the file /etc/httpd/conf.d/welcome.conf.”
I opend the welcome.conf file.

I found following lines in welcome.conf file.
<LocationMatch “^/+$”>
Options -Indexes
ErrorDocument 403 /error/noindex.html
LocationMatch>

I changed that to as follows:

[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]

<LocationMatch “^/+$”>
Options Indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>

[/viral-lock]

That solve my problem. Some time your selinux will cause the issue so you need to deactivate the selinux.
Some time File permission will also cause the issue.
You can change the file permission using following command, go to that directory and run following command.
#chmod 777 *

You can use above commands on any linux box. Ubuntu, centos, redhat or on fedora box.. still solution will be same.

How to use juggernaut in Rails project

Juggernaut is the Rails plugin for sending and receiving data in different thread. It gives you real time connection to server and you can implement different ideas work or fulfil your requirement.

Juggernaut uses the eventmachine as a server.

So install the supported gem first.

#gem install json

#gem install eventmachine

#gem install juggernaut

Juggernaut is aims to revolutionize your Rails app by letting the server initiate a connection and push data to the client.

Juggernaut is used for speciallycreating Chat application.

If you want to full details about Juggernaut then go to http://juggernaut.rubyforge.org/

First install the juggernaut to your application using this command.
ruby script/plugin install git://github.com/maccman/juggernaut_plugin.git

install the gem : gem install juggernaut

Configure the gem: juggernaut –g juggernaut.yml

Start the Juggernaut server: juggernaut -c juggernaut.yml

(This is not rails server or mongrel server)

In your controller you can use this method to send data to Juggernaut server

Juggernaut.send_to_all(“alert(‘hi from juggernaut’)”)

If you want customize the Juggernaut methods or add new methods then open file:

/vender/plugin/juggernaut_plugin/lib/juggernaut.rb

Add your methods there and use in your projects.

ActiveRecord-JDBC is for use with JRuby only….

Few days back when i tred to run my rails project. I got an error saying

ActiveRecord-JDBC is for use with JRuby only
jdbc-mysql is only for use with JRuby
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in `establish_connection’: Please install the jdbcmysql adapter: `gem install activerecord-jdbcmysql-adapter` (no such file to load — java) (RuntimeError)
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in `establish_connection’
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection’
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:417:in `initialize_database’
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:141:in `process’
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:113:in `send’
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:113:in `run’
from /var/www/html/HOO/trunk/config/environment.rb:9
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require’
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require’
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:521:in `new_constants_in’
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require’
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:84
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require’
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’

I am using Fedora 9 as Os and mysql as database.

I read all the error than i got to know. I need to change my database.yml file.

in that file i have following text;

adapter: jdbcmysql

i changed that to:

adapter: jdbcmysql

socket: /var/lib/mysql/mysql.sock

I thoutht jruby database issue but not. the database setting is an issue.

setting up basic authentication apache

Two months back, we got the requirement of do basic authentication for testing site server. We given steps and code for setting up basic authentication apache. So Google or any search engine site cannot index the testing sites.

setting up basic authentication apache

We are using Fedora as Operating System and Apache as web server on our testing machine. We hosted more than fifteen test sites on that server.

I successfully created basic authentication on server.

Use following commands:

#su

#ROOT_PASSWORD

#vi /etc/httpd/conf/httpd.conf

in that file you need to insert following lines.

AccessFileName htaccess.acl .htaccess
# htpasswd -c /home/USER/pwd.txt USER(you can define your user of stystem.)
New password: mypassword
Re-type new password: mypassword

That sit. Your username and password is set for popup.

Now you need to only create or update your .htaccess  file. You can create or find .htaccess file in your project folder.

Use or copy and paste following code in that file: (.htaccess file)

AuthUserFile /home/USER/pwd.txt
AuthName "Protected"
AuthType Basic


require valid-user

I following exact method for my server and projects. It is working perfect for me.

How to Use chkconfig command on fedora

chkconfig command is default command for linux versions.
chkconfig command is basically used for what is status when machine is rebooting. Startup of machine which services get started automatically.

For listing for services:
#su
#ROOT-PASSWORD
#chkconfig –list

If you want to add any service at startup:
# chkconfig –add nginx

If you want to turn on any service at startup:
#chkconfig nginx on

Stopping service
#chkconfig mysql off

install netbeans 6.7 on fedora 9

For installation of  netbeans package you need JDK 1.6 installed on your Fedora box. on Fedora 9 you are having already installed JDK 1.6 so you need to update the installation only.

Use following command for installing or updating JDK installation.

#su

#ROOT_PASSWORD

#yum update java-1.6.0-openjdk-devel

#yum install java-1.6.0-openjdk-devel
Than go to this URL (http://www.netbeans.org/downloads/index.html) and download the .sh file which you want install on your Fedora 9 box.

As per my view Netbeans supports for Rails and PHP and Netbeans is best IDE for Rails and PHP.

For Linux platforms, the installer file has the .sh extension. For these platforms, you need to make the installer files executable by using the following command:
#chmod +x netbeans-6.7.0-ml-ruby-linux.sh

This command i given for ruby IDE, you can choose your IDE or as per file name.

Than run the installer file

#netbeans-6.5.1-ml-ruby-linux.sh

That sit netbeans installtion will start to PC. After installation you can start netbeans from programming menu.

Compress the server response with Nginx

Maybe you aware with apache “mod_gzip and mod deflate”

Compress the server response with Nginx

Web page compression is not a new technology, but it has recently gained higher recognition in the minds of IT administrators and managers because of the rapid ROI it generates. Compression extensions exist for most of the major Web server platforms

For Apache Normally use following syntax:

mod_gzip_item_exclude file \.js$
mod_gzip_item_exclude mime ^text/css$

mod_gzip_item_include file \.html$
mod_gzip_item_include file \.shtml$
mod_gzip_item_include file \.php$
mod_gzip_item_include mime ^text/html$

mod_gzip_item_include file \.txt$
mod_gzip_item_include mime ^text/plain$

mod_gzip_item_include file \.css$
mod_gzip_item_include mime ^text/css$

We used gzip and compressing files technology with various browers. You need following browser support for this.

  • Accept-encoding: gzip
  • Accept-encoding: gzip, deflate

For Nginx i used following code in Nginx.conf file:

# Compression of response time
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 9;
gzip_http_version 1.0;
gzip_min_length 0;
gzip_types text/plain text/html text/css image/x-icon image/png image/jpg image/jpeg text/js text/php;
gzip_vary on;

Memcached Server with Rails

To install memcached server on linux/fedora box
yum install memcached

Find help for memcached commands and option
memcached -help

Start memcached server(11211 is default port Number for memcached server)
memcached -m 500 -l 192.168.2.4 -p 11211 -vv
(192.168.2.4 this is my local ip address you can cahnge that)

Stop the Memcached server
ps -ef|grep memcached
kill PROCESS_ID

start memcached server with
memcached -m 500 -l 192.168.2.4 -p 11211 -vv

How to install on Windows server:
1.  Downloaded this Win32 port of memcached by Kenneth Dalgleish.(download from following url)
http://thewebfellas.com/blog/2008/6/9/rails-2-1-now-with-better-integrated-caching
2. Extracted the files to C:\Program Files\memcached
3. Opened a command prompt in the folder and installed memcached as a service using memcached -d install
4. Started the service using net start “memcached Server”

How to use memcache in Rails app?
Open  /config/environments/development.rb for development mode,
production.rb for production mode.
paste following line into file.
config.cache_store = :mem_cache_store, ‘127.0.0.1’, ‘127.0.0.1:11211’ , { :namespace => ‘dev’ }
(127.0.0.1 this is my local ip address you can cahnge or point out to any server where memcached server is running)
Restart mongrel server. you are ready to use memcached server

How to use in Rails
@user= User.find(1)—–OLD Code

New Code With Caching:
@user = cache([‘User’,1],:expires_in => 30.minutes) do
User.find(1)
end