Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Magento 檔案與目錄權限設定完整指南:SSH、後台與 PHP 三種方式

編輯:Linux 教學

權限錯誤典型徵狀

  • 無法安裝擴充套件
  • Magento Connect 失效
  • 圖片不顯示、上傳失敗
  • 後台二級選單不可用

90% 以上皆為檔案權限設定不當所致。

方式一:SSH 指令 (適用 VPS/獨立主機)

標準權限 (推薦)

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

若標準權限仍失效 (寬鬆模式)

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 777 {} \;
chmod o+w var/.htaccess
chmod 550 mage

方式二:Magento 後台指定路徑權限

755 目錄清單

magento/app/etc
magento/media
magento/app
magento/skin
magento/var
magento/var/.htaccess
magento/js
magento/downloader

644 檔案清單

magento/index.php
magento/downloader/index.php

方式三:PHP 遞迴修權腳本 (適用無 SSH 環境)

<?php
function AllDirChmod($dir = "./", $dirMode = 0755, $fileMode = 0644) {
    $iterator = new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator($dir),
        RecursiveIteratorIterator::SELF_FIRST
    );
    foreach ($iterator as $path) {
        if ($path->isDir()) {
            chmod($path, $dirMode);
        } elseif ($path->isFile()) {
            chmod($path, $fileMode);
        }
    }
}
AllDirChmod();
?>

將上述碼存為 fix_perms.php 放入 Magento 根目錄,瀏覽器執行即可。

關鍵提醒

  1. 執行權限修改前請備份 app/etc/local.xml
  2. 生產環境建議優先使用「標準權限」,僅在必要時啟用「寬鬆模式」
  3. 修改後清除快取:rm -rf var/cache/* var/session/*
Copyright © Windows教程網 All Rights Reserved