7

I tried taking a backup of Magento by Admin->System->Tools and when I clicked on System Backup, the website showed me -

Internal Server Error

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

Please contact the server administrator, [email protected] 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.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

Apache Server at ***.com Port 80

Now, every page is loading the same error.

Please help.

1
  • 1
    provide the error occured (check you apache/php logs, e.g. /var/log/apache2/error.log)
    – Vitaly Muminov
    Aug 17, 2013 at 11:14

5 Answers 5

8

Note: More detail on the Magento code that causes the issue and how to clean up over here...

The Magento backup system in 1.6 and later has an unfortunate feature where it will change certain file/folder permissions which then can fall afoul of security measures like SuExec, SuPHP or cPanel WHM settings.

The root error that causes a 500 error page will show in the server log. The server error log should be available in your cPanel or in a log folder in your account folder. If not, you can contact your hosting provider to tell you what the errors for the 500 error are being recorded.

Often, clearing the 500 error is as simple as using WinSCP to change permissions. The vile and stupid change often is that index.php in your Magento root folder is given permissions of 666 (readable and writable by everyone) instead of the 644 or 664 permissions that don't violate system security checks. Also check for a file in your magento root called maintenance.flag and delete it.

In worst-case scenarios, the backup can change all file/folder permissions and you then have to run a script to change folder permissions to 755 and file permissions to 644.

Magentocommerce help page for setting file permissions

Given that Magento An e-Bay Inc. Company has allowed some pages to cease existence on their website, transferring the meat of the subject here to link-rot proof. For Magento 1.5+ as follows:

Here’s how to reset your file and directory permissions if PHP is running through FastCGI, suPHP, or LSAPI:

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chmod 550 mage

YMMV depending on hosting provider, files 664 and directories 775 MAY be needed

If PHP is running as a module (DSO), you will need to do this:

sudo find . -type f -exec chmod 644 {} \;
sudo find . -type d -exec chmod 755 {} \;
sudo chmod o+w var app/etc
sudo chmod 550 mage
sudo chmod -R o+w media

On that page is mentioned the Magento Cleanup Tool (as long as it's still available) which is run as a php script. Several people recommend running it after every Magento Admin panel system backup.

Of course, the way around it is to dispense with the Magento system backup till they fix it and use a combined tarball/mysqldump backup as a manual scripted operation or to set up another system and use rsync and do a cron scripted gzipped mysql dump that is pulled over when the rsync backup is run.

2
  • When using find you can speed up this process (due to the volume of files) by using + instead of \; - For example: find . -type f -exec chmod 0644 {} +
    – Ash
    Apr 20, 2015 at 8:03
  • <b>100% Solution</b> I have used admin backup after backup show 500 internal server error. i have root access i run these commands find . -type f -exec chmod 644 {} \; find . -type d -exec chmod 755 {} \; chmod 550 mage
    – Sourav
    Nov 14, 2017 at 5:47
2

The cause of this issue is most likely file permission problems due to the changes ins erver files and directories. A very quick and easy way to overcome this problem is to run the Magento cleanup script. If that doesnt work then then you will need to set the file permissions manually.

Save the code as a PHP file in the root directory of Magento and run.

<?php

## Function to set file permissions to 0644 and folder permissions to 0755

function AllDirChmod( $dir = "./", $dirModes = 0755, $fileModes = 0644 ){
   $d = new RecursiveDirectoryIterator( $dir );
   foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){
      if( $path->isDir() ) chmod( $path, $dirModes );
      else if( is_file( $path ) ) chmod( $path, $fileModes );
  }
}

## Function to clean out the contents of specified directory

function cleandir($dir) {

    if ($handle = opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != '.' && $file != '..' && is_file($dir.'/'.$file)) {
                if (unlink($dir.'/'.$file)) { }
                else { echo $dir . '/' . $file . ' (file) NOT deleted!<br />'; }
            }
            else if ($file != '.' && $file != '..' && is_dir($dir.'/'.$file)) {
                cleandir($dir.'/'.$file);
                if (rmdir($dir.'/'.$file)) { }
                else { echo $dir . '/' . $file . ' (directory) NOT deleted!<br />'; }
            }
        }
        closedir($handle);
    }

}

function isDirEmpty($dir){
     return (($files = @scandir($dir)) && count($files) <= 2);
}

echo "----------------------- CLEANUP START -------------------------<br/>";
$start = (float) array_sum(explode(' ',microtime()));
echo "<br/>*************** SETTING PERMISSIONS ***************<br/>";
echo "Setting all folder permissions to 755<br/>";
echo "Setting all file permissions to 644<br/>";
AllDirChmod( "." );
echo "Setting pear permissions to 550<br/>";
chmod("pear", 550);

echo "<br/>****************** CLEARING CACHE ******************<br/>";

if (file_exists("var/cache")) {
    echo "Clearing var/cache<br/>";
    cleandir("var/cache");
}

if (file_exists("var/session")) {
    echo "Clearing var/session<br/>";
    cleandir("var/session");
}

if (file_exists("var/minifycache")) {
    echo "Clearing var/minifycache<br/>";
    cleandir("var/minifycache");
}

if (file_exists("downloader/pearlib/cache")) {
    echo "Clearing downloader/pearlib/cache<br/>";
    cleandir("downloader/pearlib/cache");
}

if (file_exists("downloader/pearlib/download")) {
    echo "Clearing downloader/pearlib/download<br/>";
    cleandir("downloader/pearlib/download");
}

if (file_exists("downloader/pearlib/pear.ini")) {
    echo "Removing downloader/pearlib/pear.ini<br/>";
    unlink ("downloader/pearlib/pear.ini");
}

echo "<br/>************** CHECKING FOR EXTENSIONS ***********<br/>";
If (!isDirEmpty("app/code/local/")) {
    echo "-= WARNING =- Overrides or extensions exist in the app/code/local folder<br/>";
}
If (!isDirEmpty("app/code/community/")) {
    echo "-= WARNING =- Overrides or extensions exist in the app/code/community folder<br/>";
}
$end = (float) array_sum(explode(' ',microtime()));
echo "<br/>------------------- CLEANUP COMPLETED in:". sprintf("%.4f", ($end-$start))." seconds ------------------<br/>";

Manual Method:

Manual Method for Magento setting file permossions

1
  • 1
    Please provide the contents of the pastebin in the answer as the pastebin is likely to go away at some point.
    – philwinkle
    Oct 5, 2013 at 19:46
2

In some cases you don't have access (or don't have ROOT (sudo)) to SSH, so what I did was:

Go to your cPanel -> File Manager and change all files and folders to 755, then it will let you work.

Then download the Magento cleanup tool, upload it to your root directory and access it from your browser. It will clean all the permisions.

Hope it'll help.

Cheers :)

2

Thanks for all the help. I fixed it easily using FileZilla FTP, I just selected the root folder for magento and changed permissions for all files and it did it automatically. No running of scripts required.

FileZilla also has an option for changing all folder permissions automatically.

Hope it helps.

-1

May be I'm wrong but you please try it.

Just delete the temperory file "maintenance.flag" from root directory then your website will works back.

Hope this will help you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.