如何解决opencart的Linux权限问题


How to solve a Linux permission issue for opencart

我曾使用subversion来恢复我的PHP Opencart项目,但我遇到了权限问题(示例如下:

警告:imagejpeg():无法打开"/var/www/html/opencart/image/cache/data/pavblog/img-blog-620x300w.jpg"进行写入:权限在第45行的/var/www/html/opencart/system/library/image.php中被拒绝

警告:imagejpeg():无法打开"/var/www/html/opencart/image/cache/data/pavblog/img-blog-250x250w.jpg"进行写入:权限在第45行的/var/www/html/opencart/system/library/image.php中被拒绝

警告:imagejpeg():无法打开。。。

我执行了以下命令来向这些文件夹添加权限,但我的网站上仍然收到警告消息。

sudo chmod 777 /var/www/html/opencart
cd /var/www/html/opencart 
sudo chmod 777 image/ 
sudo chmod 777 image/cache/ 
sudo chmod 777 image/data/ 
sudo chmod 777 system/cache/ 
sudo chmod 777 system/logs/ 
sudo chmod 777 download/ 
sudo chmod 777 config.php
sudo chmod 777 admin/config.php

我该怎么解决这个问题?

要修复您的权限,您需要采取两个不同的步骤:

  1. 将权限授予适当的实体。由于您在/var/www/html中,我猜测正确的用户是"apache"。

    # Grants permissions to apache
    sudo chown apache:apache -R /var/www/html/opencart
    # If that doesn't work, perhaps try www-data
    sudo chown www-data:www-data -R /var/www/html/opencart
    
  2. 正确设置文件和文件夹的权限(文件具有执行权限可能很危险)

    # Sets directory permissions to 755 (rwxr-xr-x)
    sudo find /var/www/html/opencart -type d -exec chmod 755 {} ';
    # Sets file permissions to 644 (rw-r--r--)
    sudo find /var/www/html/opencart -type f -exec chmod 644 {} ';
    

您需要递归地应用权限。尝试

sudo chmod -R 777 image/cache/