You are here: dMarkWeb-Web Design Company » Author : Deepak Oberoi
Magento Issue – Internal Server Error 500

Magento Issue – Internal Server Error 500

Today we will find out a solution troubleshooting Internal Server Error with Magento Store in any case for any reason.

Possible Reason/Solutions
===========================
Some might have this problem with their fresh Magento Installation or a Custom Magento Store, some have this problem with their exsiting installtion that is running fine for a long time. Sometime, this error is not visible and it just affect and make some Magento feature not working, for example this error just can be seen with Web Developer by tracking Ajax request and response. So here are a few possible reason
- Htaccess file which is located at Magento root folder. It will be this case if you meet Internal Server Error on every page. Try to remove it for testing purpose
If your website was running file for a long time, then it must be a change at Server side, just submit a ticket to Hosting Company.

The reason might be default permission on some hosting. Some hosting doesn’t allow high permission on folder, some need to grant correct permission on running script. For most cases I meet, you need to set permission 755 for index.php at Magento root
- Code Exception. Okay if you are not technical person, then there is no much thing you can do. Here are some ways you can try before need support from Magento Experts
+ Download magento-check.php script in order to validate basic requirement of your hosting
+ Run magento-clean tool to see if it solve your problem
- Custom code/module conflict. OK, so if you have tried all way above and they don’t help. You may want to play around it. Here is my advise

Turn on Developer Mode

If you look in the Magento bootstrap file (index.php) you’ll see lines similar to the following

#Mage::setIsDeveloperMode(true);
#ini_set(‘display_errors’, 1);

Uncomment these. In a production system, you’d never want to have your errors display to the browser, but while developing having an errors and warnings thrown immediately in your face is invaluable.

This way, you will see the actually problem which lead to the Internal Error Server. In almost cases, the reason is that there is an exception throw after output is sent to browser.

How to move Magento from Local to Live Server

This is the method I used to move my local copy of magento store from XAMPP on windows to a shared hosting account. Whilst developing my store, the size of the database became fairly big, around 70MB. Enough to start complicating the process. After numerious failed attempts, i finally got the right method. Hope this helps you out, any feedback will be greatly appreciated.

Local Server Copy

1. Login into your Local copy of Magento and change configuration > web > unsecured link & sercured link to {{base_url}}
2. This prevents errors with the file paths when you move the server and will be changed back later on.
3. Change the cache settings in the configuration to refresh and save.
4. Open myPHPadmin http://localhost/phpmyadmin/ and select your magento database
5. You are now going to export a copy of the database, also know as a dump. Use the following settings: Leave all the settings as they are but use the “save file as” and use compression none.

Live Server

1. In your control panel for you live server, set up a new mysql database with the same dbname, username, password
2. Unzip the latest version of Magento Commerce onto our root web folder
3. Install a fresh copy of magento using the same database settings
4. After a sucessful install, FTP your media folder and any template files you changed onto the live server, making sure that the file permissions are correct (i.e 777).
5. Delete the var/cache and car/session folder from Live Server
6. Login to the control panelfor for you mysql database (phpmyadmin in my case) and delete all the tables in you new magento database but not the database itself!
7. Import your old magento database using the Import Tab and following the steps.
8. Log into the magneto manager, and now change the {{base_url}} settings to reflect you new domain i.e http://www.webdesignlab.co.uk/magento
9. And finally give the cache settings a refresh.
10. Once complete, check your url and you should see your old site on the new server without any errors.

Setting UP a Local network DNS Server using bind9 for debian

This is a step by step tutorial on how to install and configure DNS server for your LAN using bind9. The DNS server will provide caching and name resolution as well as reverse name resolution for your local network. In this tutorial, we will use the domain “debian.lan” and this will be the domain of your local network. The domain “debian.lan is not accessible from the internet; its private ip address is “192.168.100.1″.

Installing bind9 and dns utilities

I assume that you already have a working Debian or Ubuntu installation. Lets install the bind9 package and dns utilities from Debian repository.

apt-get install bind9 dnsutils

Configure your Linux system

Add this information to your /etc/hostname

echo “main.debian.lan” > /etc/hostname

Edit your /etc/hosts

127.0.0.1       localhost.localdomain   localhost
192.168.100.1   main.debian.lan main
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Edit your /etc/resolv.conf

vi /etc/resolv.conf

and add this information.

search debian.local
nameserver 192.168.100.1
nameserver xxx.xxx.xxx.xxx
nameserver xxx.xxx.xxx.xxx

This is where Linux looks to find out how it should perform DNS lookups.

Lets create a zone

The zone files (or database files) are the heart of your BIND system. This is where all the information is stored on what hostname goes with what ip address.
Before we create a zone file, lets edit first the local configuration file /etc/bind/named.conf.local.

vi /etc/bind/named.conf.local

and the zone file data.

//
// Do any local configuration here
//

// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";

zone "debian.lan" {
        type master;
        file "db.debian.lan";
};

zone "100.168.192.in-addr.arpa" {
        type master;
        file "db.192.168.100";
};

Lets start creating a zone file in /var/cache/bind/ directory. Create a file called db.debian.lan

vi /var/cache/bind/db.debian.lan

And add the following entry

$TTL 604800
@ IN SOA main.debian.lan. admin.debian.lan. (
                2008080101      ;serial
                04800           ;refresh
                86400           ;retry
                2419200         ;expire
                604800          ;negative cache TTL
                )
@       IN      NS      main.debian.lan.
@       IN      A       192.168.100.1
@       IN      MX      10      main.debian.lan.
main    IN      A       192.168.100.1
www     IN      CNAME   main
ubuntu  IN      A       192.168.100.2

Lets create the reverse DNS zone file called db.192.168.100

vi /var/cache/bind/db.192.168.100

and the the following entry.

$TTL 604800
@ IN SOA main.debian.lan. admin.debian.lan. (
                2008080101      ;serial
                604800          ;refresh
                86400           ;retry
                2419200         ;expire
                604800          ;negative cache TTL
                )
@       IN      NS      main.debian.lan.
@       IN      A       192.168.100.1
1       IN      PTR     main.debian.lan.
2       IN      PTR     ubuntu.debian.lan.

The zone files are created, you can check your zone file configurations using these utilities:

named-checkzone convergence.lan /etc/bind/zones/db.convergence.lan

Lets edit the file /etc/bind/named.conf.options

vi /etc/bind/named.conf.options
forwarders {
                202.78.97.41;
                202.78.97.3;
        };

Uncomment the line forwarders and add your ISP’s DNS server.

dig debian.lan

Lets restart our DNS server, and test using the tool dig.

/etc/init.d/bind9 restart
dig debian.lan

You should see the following message

; <<>> DiG 9.3.4 <<>> debian.lan
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54950
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;debian.lan.                    IN      A

;; ANSWER SECTION:
debian.lan.             64800   IN      A       192.168.100.1

;; AUTHORITY SECTION:
debian.lan.             64800   IN      NS      main.debian.lan.

;; ADDITIONAL SECTION:
main.debian.lan.        64800   IN      A       192.168.100.1

;; Query time: 1 msec
;; SERVER: 192.168.100.1#53(192.168.100.1)
;; WHEN: Tue Aug  5 09:33:40 2008
;; MSG SIZE  rcvd: 79

Test your reverse DNS

dig -x debian.lan

If you see this message, you have successfully installed the DNS server.

; <<>> DiG 9.3.4 <<>> -x debian.lan
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 42510
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;lan.debian.in-addr.arpa.       IN      PTR

;; AUTHORITY SECTION:
in-addr.arpa.		10800	IN	SOA	A.ROOT-SERVERS.NET. dns-ops.ARIN.NET. 2008080416 1800 900 691200 10800

;; Query time: 952 msec
;; SERVER: 192.168.100.1#53(192.168.100.1)
;; WHEN: Tue Aug  5 09:34:25 2008
;; MSG SIZE  rcvd: 108

You can also check your DNS configuration using nslookup and host command.

nslookup debian.lan
nslookup 192.168.100.1
host debian.lan
host 192.168.0.1

All computers in the LAN are going to use 192.168.100.1 as a nameserver, this can be set manually by setting statically:

vi /etc/resolv.conf

then put this information.

nameserver 192.168.100.1

Have fun!

How to create SEF URL’s in WordPress

While working on one of my client’s plugin I needed to provide search engine friendly url’s for some custom functionality that was needed and existing plugin was not supporting such urls

       www.example.com/?param1=var1&param2=var2&param3=var3

but for search engine freindly url’s I want it to be like

      www.example.com/var1/var2/var3

So here I am sharing small code snippet which works perfectly for my plguin and showing nice url’s.

We need to update the theme function.php file, just add the below code in function.php file and modify variables according to your need.

<?php
add_filter('rewrite_rules_array','wp_insertRewriteRules');
add_filter('query_vars','wp_insertQueryVars');
add_filter('init','flushRules');

// Remember to flush_rules() when adding rules
function flushRules()
{
  global $wp_rewrite;
  $wp_rewrite->flush_rules();
}

// Adding a new rule
function wp_insertRewriteRules($rules)
{
  $newrules = array();
  $newrules['(mytestpage)/([a-zA-Z0-9_\-]*)/([a-zA-Z0-9_\-]*)$'] =
'index.php?pagename=$matches[1]&var1=$matches[2]&var2=$matches[3]';
  $allrules = $newrules + $rules;
  return $allrules;
}

// Adding the variables  so that WP recognizes it
function wp_insertQueryVars($vars)
{
 array_push($vars, 'id');
 array_push($vars, 'var1');
 array_push($vars, 'var2');
 return $vars;
}
?>

To access these variables from plugin file use following code:

 $var1 = $wp_query->query_vars['var1'];
 $var2 = $wp_query->query_vars['var2'];

Now this will solve your plugins search engine friendly issues.

jQuery Lightbox with jQuery

It’s quite difficult to copy-paste JavaScript for same thing again and again. That’s why I’ve come up with Thickbox helper for CakePHP – as a result of a project which involved lot of thickboxes implementations. For those who don’t know what it is be sure to check Thickbox jQuery Plugin.

To use it, just include this helper in your controller and Its implementation is very simple:

1. For inline content:

PHP:

  1. <?
  2. $thickbox->setProperties(array(‘id’=>‘domId’, ‘height’=>’300′, ‘width’=>’334′)); // set height, width and DOM ID
  3. $thickbox->setPreviewContent(‘click me’); // the link which will trigger thickbox on click
  4. $thickbox->setMainContent(‘<div>see it??</div>’); // the content which will be shown in thickbox
  5. echo $thickbox->output();
  6. ?>

 

2. For AJAX:

PHP:

  1. $thickbox->setProperties(array(‘id’=>‘domId’,‘type’=>‘ajax’,‘ajaxUrl’=>‘/controller/action’));
  2. $thickbox->setPreviewContent(“Click me to see thickbox”);
  3. echo $thickbox->output();

Here’s the helper:

PHP:

  1. <?php
  2. class ThickboxHelper extends AppHelper {
  3.  
  4.     var $helpers = array(‘Javascript’, ‘Html’);
  5.    
  6.     /**
  7.      * Set properties – DOM ID, Height and Width, Type of thickbox window – inline or ajax
  8.      *
  9.      * @param array $options
  10.      */
  11.     function setProperties($options = array())
  12.     {
  13.         if(!isset($options['type']))
  14.         {
  15.             $options['type'] = ‘inline’;
  16.         }
  17.         $this->options = $options;
  18.     }
  19.    
  20.     function setPreviewContent($content)
  21.     {
  22.         $this->options['previewContent'] = $content;
  23.     }
  24.  
  25.     function setMainContent($content)
  26.     {
  27.         $this->options['mainContent'] = $content;
  28.     }
  29.    
  30.     function reset()
  31.     {
  32.         $this->options = array();
  33.     }
  34.    
  35.     function output()
  36.     {
  37.         extract($this->options);
  38.         if($type==‘inline’)
  39.         {
  40.             $href = ‘#TB_inline?’;
  41.             $href .= ‘&inlineId=’.$id;
  42.         }
  43.         elseif($type==‘ajax’)
  44.         {
  45.             $ajaxUrl = $this->Html->url($ajaxUrl);
  46.             $href = $ajaxUrl.‘?’;
  47.         }
  48.                
  49.         if(isset($height))
  50.         {
  51.             $href .= ‘&height=’.$height;
  52.         }
  53.         if(isset($width))
  54.         {
  55.             $href .= ‘&width=’.$width;
  56.         }
  57.        
  58.        
  59.         $output = ‘<a class=”thickbox” href=”‘.$href.‘”>’.$previewContent.‘</a>’;
  60.        
  61.         if($type==‘inline’)
  62.         {
  63.             $output .= ‘<div id=”‘.$id.‘” style=”display:none;”>’.$mainContent.‘</div>’;
  64.         }
  65.        
  66.         unset($this->options);
  67.        
  68.         return $output;
  69.     }
  70.    
  71.     function beforeRender()
  72.     {
  73.         $out = $this->Html->css(‘/effects/css/thickbox.css’).‘<script src=”‘.$this->Html->url(‘/effects/js/thickbox-compressed.js’).‘”></script>’;
  74.         $view =& ClassRegistry::getObject(‘view’);
  75.         $view->addScript($out);
  76.     }
  77.  
  78. }
  79. ?>

 

You’ll need to copy the thickbox files to /app/webroot/effects. You can keep it in any folder for that matter, but as our team is following plugins – it’s made that way.

Using AJAX with CakePHP Forms

CakePHP helpers are so powerful that when you begin to hack helpers here and there you discover a lot of possibilities which can save you a lot of time. Same thing happened when I had an idea to AJAX’ify the forms using some shortcut.

Let’s try hacking the FormHelper and enable AJAX. We’ll use jQuery Form plugin to submit forms via AJAX request (I don’t know any other good plugins for forms).

What we’ll be doing:

Converting a normal form like below one, to make it call AJAX(using jQuery lib) and alert us when form posted:

PHP:

  1. <div class=“jerks form”>
  2. <?php echo $form->create(‘Jerk’);?>
  3.     <fieldset>
  4.        <legend><?php __(‘Add Jerk’);?></legend>
  5.     <?php
  6.         echo $form->input(‘name’);
  7.     ?>
  8.     </fieldset>
  9. <?php echo $form->end(‘Submit’);?>
  10. </div>

 

1. Extend your FormHelper to something like AjaxFormHelper (Now normally I don’t extend core helpers like this, but use a similar method similar to this (comment by grigri): http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/#comment-110708 ) and overwrite create() method like this:

PHP:

  1. function create($model = null, $options = array())
  2. {
  3.     $output = “”;
  4.     if(isset($options['ajax']) && $options['ajax']==‘true’)
  5.     {
  6.         if(!isset($options['id']))
  7.         {
  8.             $options['id'] = ‘form’ . intval(mt_rand());
  9.         }
  10.        
  11.         $this->ajaxForm = $options['id'];
  12.         $url = “$(‘#”.$options['id'].“‘).attr(‘action’)+’?ajax=1&flash_only=1″;
  13.        
  14.         if(@$options['response']==‘inline’)
  15.         {
  16.             $datatype = ‘text’;
  17.             $success = “$(‘#”.$options['id'].“_status’).hide().html(responseText).fadeIn();
  18.                         setTimeout(function(){
  19.                             $(‘#”.$options['id'].“_status’).fadeOut();
  20.                         }, 5000);”;
  21.             $url .= “&js=false’”;
  22.         }
  23.         else {
  24.             $datatype = ‘script’;
  25.             $success = ;
  26.             $url .= “‘”;
  27.         }
  28.        
  29.         // to-do: avoid multiple inclusion of this script
  30.         $output .= “<div id=’”.$options['id'].“_status’ style=’display:none;’></div>”;
  31.         $output .= “<script src=’”.$this->Html->url(‘/effects/js/jquery.form.js’).“‘></script>”;
  32.         $output .= “<script>
  33.         $(document).ready(function() {
  34.         $(‘#”.$options['id'].“‘).ajaxForm({dataType: ‘”.$datatype.“‘, url:  “.$url.“,
  35.             beforeSubmit: function(){
  36.             $(‘#”.$options['id'].” .submit input’).attr(‘disabled’, true);
  37.             $(‘#progressIndicator’).show();
  38.             $(‘#”.$options['id'].” .form_progress’).show();
  39.             },
  40.             success: function(responseText, statusText){
  41.             $(‘#”.$options['id'].” .submit input’).attr(‘disabled’, false);
  42.             $(‘#progressIndicator’).hide();
  43.             $(‘#”.$options['id'].” .form_progress’).hide();
  44.             “.$success.
  45.             },
  46.         });
  47.     });
  48.     </script>”;
  49.     }
  50.     // unset js options
  51.     $output .= parent::create($model, $options);
  52.    
  53.     return $this->output($output);
  54. }

I’m not that good in explaining code flow, but you might have noted 3 get variables appended to our form action URL above. These variables are: ‘ajax’,'flash_only’ ,’js’ and serves their own purpose that I’ll tell in next steps.

 

2. Now we enable the AJAX in our form (CakePHP’s $options array is so good that you can overwrite and modify almost many methods easily):

This will show a JS alert after form has been submitted successfully.

PHP:

  1. <div class=“jerks form”>
  2. <?php echo $ajaxForm->create(‘Jerk’, array(‘ajax’=>‘true’));?>
  3.     <fieldset>
  4.        <legend><?php __(‘Add Jerk’);?></legend>
  5.     <?php
  6.         echo $ajaxForm ->input(‘name’);
  7.     ?>
  8.     </fieldset>
  9. <?php echo $ajaxForm ->end(‘Submit’);?>
  10. </div>

This will show an inline message after form has been submitted successfully.

PHP:

  1. <div class=“jerks form”>
  2. <?php echo $ajaxForm->create(‘Jerk’, array(‘ajax’=>‘true’ , ‘response’=>‘inline’));?>
  3.     <fieldset>
  4.        <legend><?php __(‘Add Jerk’);?></legend>
  5.     <?php
  6.         echo $ajaxForm ->input(‘name’);
  7.     ?>
  8.     </fieldset>
  9. <?php echo $ajaxForm ->end(‘Submit’);?>
  10. </div>

Note that ajax=true parameter we sent in create() method. This will tell helper to load this form via AJAX.

 

3. Now your form will be AJAX ready (if you’ve included this AjaxFormHelper properly). But because our controller function was made to process normal POST function, and flash message on success – we’ll have to change that behavior. This is what a normal JerksController::add() method should look like:

PHP:

  1. function add() {
  2.         if (!empty($this->data)) {
  3.             $this->Jerk->create();
  4.             if ($this->Jerk->save($this->data)) {
  5.                 $this->Session->setFlash(‘Jerk saved.’);
  6.             } else {
  7.             }
  8.         }
  9.     }

We don’t need full action content from views/jerks/add.ctp to appear in response when AJAX is called. We can make this work traditional way by checking if it’s an AJAX request in controller method itself and do needful, but I wouldn’t want to modify all my controller functions to enable AJAX, so here’s what I’ve come up with.

Remember the 3 GET variables above?

‘ajax’ => This one will determine if a given HTTP request is an AJAX request.

‘flash_only’ => This will tell if rendering should happen or not. Flash only means, after controller function is executed, do not render, just show flash message.

‘js’ => This is used for alert type, if this is not set, show inline alert. If set true, helper must show JS alert() on form success.

Inside your AppController::beforeFilter(), add this code:

PHP:

  1. if(isset($_GET['ajax']))
  2. {
  3.     Configure::write(‘debug’,0);
  4.     $this->layout = ‘ajax’;
  5.     $ this ->set(‘ajax’, true);
  6.     if($_GET['flash_only'])
  7.     {
  8.         $ this ->set(‘flash_only’, true);
  9.         //$ this ->autoRender = false;
  10.     }
  11.    
  12.     if($_GET['js']==‘false’)
  13.     {
  14.         $ this ->set(‘js’, 0);
  15.     }
  16.     else {
  17.         $ this ->set(‘js’, 1);
  18.     }
  19. }

Do not blame me for using GET variables, I found many issues with ‘named’ so I’m relying on normal GET variables.

Now you’ll need to edit ajax.ctp layout file.

PHP:

  1. <?php
  2. if ($session->check(‘Message.flash’))
  3. {
  4.     $strMessage = ;
  5.     $message = $session->read(‘Message.flash’);
  6.     if(isset($message['params']['type']))
  7.     {
  8.         $type = $message['params']['type'];
  9.         $strMessage = ucfirst($type).“: “.$message['message'];   
  10.     }
  11.     else {
  12.         $strMessage = $message['message'];     
  13.     }
  14.     $session->del(‘Message.flash’);
  15. }
  16. if(!empty($this->validationErrors))
  17. {
  18.     $strMessage = ;
  19.     foreach($this->validationErrors as $model=>$errors)
  20.     {
  21.         foreach($this->validationErrors[$model] as $field=>$error)
  22.         {
  23.             $strMessage .= $error;
  24.         }
  25.     }
  26. }
  27. ?>
  28. <?
  29. if($strMessage) {
  30.     if($js==1) {
  31. ?>
  32.     alert(‘<?=$strMessage;?>’);
  33. <? } elseif($js==0) {
  34.     echo $strMessage;
  35. } } ?>
  36. <?
  37. if(!isset($flash_only))
  38. {
  39.     echo $content_for_layout;
  40. }
  41. ?>

This should be self explanatory, even though this code definitely needs some refactoring. We’re basically manipulating those 3 GET variables according to our need. In process, we’re also checking validation errors occurred in form.

I have not used it under the production environment yet, so I’d really like to hear any pitfalls (if any) using this approach. Thanks for reading.

Using CakePHP Framework for Web Development

dMarkWeb has been in business for a while.  Building and designing web applications using PHP.  We initially started building site management systems using our own developed file structure.  No templates, no smarty, just straight mixed up, stirred, PHP and html.  That is exactly what it was.  PHP with a bunch of echos everywhere to display the html dynamically. Keep Reading…

Website Maintenance

Website Maintenance

View More

You cannot let your website stagnate. Your website needs regular bug fixing, content upgrades, link validation and fresh designs to stay ahead of competition. We offer you comprehensive website maintenance that fixes every issue and keeps your website sparkling new.

Website Maintenance Services

Ecommerce Development

Ecommerce Development

View More

We offer customized e-commerce web design services of all scopes and complexities. From a small online store selling a few books to mammoth online businesses retailing thousands of products.

Ecommerce Development

Offshore Outsourcing

Offshore Outsourcing

View More

Offshore outsourcing lets you delegate your workload helping you focus on your business, cut costs and grow faster than ever!
As per the statistics release by National Association of Software and Service Companies (India), there has been a 34% growth within software services export from India.

OutSourcing at dmarkWeb.com