Password protecting your development site using .htaccess / .htpasswd

September 21, 2013  |  1 Comments  |  by Raj (MagePsycho)  |  Apache

You may want to restrict the development site from search engine or from direct access. One of the popular way of doing so is to use Apache2 Basic Authentication.
Here we will be discussing on how to password protect your development site using Apache2 Basic Authentication which makes a use of .htaccess & .htpasswd files.


1. Create & upload .htaccess file to the root of your dev site with the following content:

AuthName "Authorisation Required"
AuthUserFile "/path/to/.htpasswd"
AuthType Basic
require valid-user
ErrorDocument 401 "Authorisation Required"

Notes: If .htaccess file already exists then you can add the above code on the top.
Also note that omitting ‘ErrorDocument 401 “Authorisation Required”‘ line can lead to 404 error.
2. Create & upload the .htpasswd file to ‘AuthUserFile’ path with the following content:


Notes: Where ‘foo’ is the username and ‘$apr1$yB1.9vIT$IVVBmq5vMauwsNR8CZdHQ.’ is the MD5 encrypted password of ‘bar’.
That was just an example, in fact you can use any username/password combination.
In order to create encrypted password you can use some free online tool like:

3. Now try to visit the dev site, you will get the screen similar as:

Apache2 Basic Authentication

Apache2 Basic Authentication

And you will only be able to browse the dev site once the correct username/password are entered.

Hope this helps you in password protecting your site.

500 Internal Server Error: Mismatch between target GID (XXX) and GID (XXX) of file

April 29, 2012  |  No Comments  |  by Raj (MagePsycho)  |  Apache, Latest, Linux, Magento

Today (at the time of writing) i tried to install Magento via SSH as ‘root’ user using following bash script:

tar -zxvf magento-
tar -zxvf magento-sample-data-1.2.0.tar.gz
mv magento-sample-data-1.2.0/media/* magento/media/
mv magento-sample-data-1.2.0/magento_sample_data_for_1.2.0.sql magento/data.sql
mv magento/* magento/.htaccess .
chmod -R o+w media
mysql -u dbUserName -pdbPass dbName < data.sql
chmod o+w var var/.htaccess app/etc
rm -rf downloader/pearlib/cache/* downloader/pearlib/download/*
rm -rf magento/ magento-sample-data-1.2.0/
rm -rf magento- magento-sample-data-1.2.0.tar.gz data.sql

And when i tried to browse the url for Magento installation, i got the screen with ‘500 Internal Server Error’.
Being aware of all possible causes of 500 Internal Server Error during Magento Installation, I tried all possible solutions that i know like:

  1. 1. Checking of Web / Unsecure / Base Url & Web / Secure / Base Urls
  2. 2. Changing permission setting for index.php:
    chmod 0755 index.php
  3. 3. Changing permission setting for folder / files recursively:
    find . -type d -exec chmod 755 {} \;
    find . -type f -exec chmod 644 {} \;
  4. 4. Renaming .htaccess file:
    mv .htaccess .htaccess.bak

But none of them worked for me.

When i checked at the apache error log file then i got the following error in log file:

SoftException in Application.cpp:431: Mismatch between target GID (508) and GID (1072) of file “/home/username/public_html/index.php”

Note: 1072 -> id of ‘root’ user
508 -> id of ‘username’ user

From above it’s clear that error is due to mismatching between ownership and got solved by using following command:

chown -R username:username /home/username/public_html

Where [username] = username of hosting(

Final Note:
Always make a habit of checking the Apache error log file in case of ‘500 Internal Server Error’ as the error can be caused due to various reasons instead of directily diving into solutions.

Configuring Magento for Development / Debug Mode

March 10, 2012  |  12 Comments  |  by Raj (MagePsycho)  |  Apache, Latest, Magento

Configuring Magento for Development / Debug Mode:

1. Disable Cache
System > Cache Management > Select All [check-boxes] > Actions = Disable > Submit

2. Re-Index All
System > Index Management > Select All [check-boxes] > Actions = Reindex Data > Submit

3. Disable Compilation
System > Tools > Compilation > Disable

Note: By default compilation mode is disabled. So just check if the Compiler Status is Enabled or not.

4. Turn on Error Reporting
a> Open index.php and un-comment the following line

#ini_set('display_errors', 1);

b> Open .htaccess and add the following line at the end


5. Turn on Logging
System > Configuration > Advanced > Developer > Log Settings > Enabled => Yes

6. Configuring Mangeto Error Page
rename errors/local.xml.sample to errors/local.xml

7. Install ‘Easy Template Path Hints’
Install Easy Template Path Hints for turning on/off the template path hints for frontend and backend easily & securely.

That’s all. Let me know for any missing points.
Happy Debugging!

Invalid command ‘Header’, perhaps misspelled or defined by a module not included in the server configuration

March 7, 2012  |  4 Comments  |  by Raj (MagePsycho)  |  Apache, Latest, Linux, Magento

I got the following error for one of the Magento e-commerce website:

Invalid command ‘Header’, perhaps misspelled or defined by a module not included in the server configuration

After googling it was found that related headers module was not enabled in Apache.

I was able to fix the issue simply by following two commands:
1. Enabling headers Module

ln -sf /etc/apache2/mods-available/headers.load /etc/apache2/mods-enabled/headers.load

2. Restarting Apache

/etc/init.d/apache2 restart

Note: Above commands were run from Ubuntu 10.04.2 server

Hope this’s helpful.

Setting custom environment variables using .htaccess

October 16, 2011  |  No Comments  |  by Raj (MagePsycho)  |  Apache, Latest

If you are familiar with Magento, esp with setting up multiple websites/stores using .htaccess then you may have encountered variables like: MAGE_RUN_CODE & MAGE_RUN_TYPE. Yes they are the custom environment variables.

In order to set up custom environment variables using .htaccess, try as follows:

RewriteRule ^ - [E=MAGE_RUN_CODE:default]
RewriteRule ^ - [E=MAGE_RUN_TYPE:store]

Where MAGE_RUN_CODE & MAGE_RUN_TYPE are custom environment variables.
and from php you can access this variable as:

echo $_SERVER['MAGE_RUN_CODE']; //prints default
echo $_SERVER['MAGE_RUN_TYPE']; //store

Hope this gave some info about custom environment variables.