上传文件 wordpress

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13258432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:05:07  来源:igfitidea点击:

Upload file wordpress

wordpresspermissionsfile-permissions

提问by JohnnyAce

I am trying to upload a file in wordpress using the Media > Add New-- Option but when I click upload I get the following error:

我正在尝试使用Media > Add New-- 选项在 wordpress 中上传文件,但是当我单击上传时,出现以下错误:

Unable to create directory wp-content/uploads/2012/11. Is its parent directory writable by the server?

无法创建目录 wp-content/uploads/2012/11。服务器是否可以写入其父目录?

I have Wordpress 4.3.1 installed.

我安装了 Wordpress 4.3.1。

Thank you

谢谢

EDIT: I am on a shared server with: host=i686-redhat-linux-gnu and Apache. I changed the permissions to 755 and 777 of wp-content/uploads but I get the following error:

编辑:我在一个共享服务器上:host=i686-redhat-linux-gnu 和 Apache。我将 wp-content/uploads 的权限更改为 755 和 777,但出现以下错误:

“my_file.jpg” has failed to upload due to an error Unable to create directory wp-content/uploads/2012/11. Is its parent directory writable by the server?

由于错误无法创建目录 wp-content/uploads/2012/11,“my_file.jpg”无法上传。服务器是否可以写入其父目录?

Any ideas?

有任何想法吗?

回答by markratledge

You need to set folder permissions for /uploads/ and possibly for /wp-content/ , too.

您需要为 /uploads/ 以及可能的 /wp-content/ 设置文件夹权限。

Typically, both folders should be 755. You may have to temporarilyraise /uploads/ to 777 and upload an image (this will also force the server to change the folder permissions and user to the correct settings), but change it back to 755 right away.

通常,两个文件夹都应该是 755。您可能需要暂时将 /uploads/ 提高到 777 并上传图像(这也将强制服务器将文件夹权限和用户更改为正确的设置),但将其更改回 755 right离开。

It's easiest to set permissions with an FTP client. See Filezillaand FTP Clients ? WordPress Codex.

使用 FTP 客户端设置权限最简单。请参阅FilezillaFTP 客户端?WordPress 法典

And see Changing File Permissions ? WordPress Codexfor the correct Wordpress permission settings:

并参阅更改文件权限?WordPress Codex用于正确的 Wordpress 权限设置:

From the codex.wordpress:Typically, all files should be owned by your user (ftp) account on your web server, and should be writable by that account. On shared hosts, files should never be owned by the webserver process itself (sometimes this is www, or apache, or nobody user).

Any file that needs write access from WordPress should be owned or group-owned by the user account used by the WordPress (which may be different than the server account). For example, you may have a user account that lets you FTP files back and forth to your server, but your server itself may run using a separate user, in a separate user group, such as dhapache or nobody. If WordPress is running as the FTP account, that account needs to have write access, i.e., be the owner of the files, or belong to a group that has write access. In the latter case, that would mean permissions are set more permissively than default (for example, 775 rather than 755 for folders, and 664 instead of 644).

来自 codex.wordpress:通常,所有文件都应该归您的 Web 服务器上的用户 (ftp) 帐户所有,并且应该可由该帐户写入。在共享主机上,文件永远不应该归网络服务器进程本身所有(有时是 www、apache 或 nobody 用户)。

任何需要 WordPress 写访问权限的文件都应该由 WordPress 使用的用户帐户(可能与服务器帐户不同)拥有或归组所有。例如,您可能有一个用户帐户,可以让您将 FTP 文件来回发送到您的服务器,但您的服务器本身可能使用单独的用户在单独的用户组中运行,例如 dhapache 或 nobody。如果 WordPress 作为 FTP 帐户运行,则该帐户需要具有写入权限,即成为文件的所有者,或属于具有写入权限的组。在后一种情况下,这意味着权限设置得比默认值更宽松(例如,文件夹是 775 而不是 755,而文件夹是 664 而不是 644)。

回答by George

ssh in and navigate to the wp-contentfolder and type in these 2 lines:

ssh 并导航到该wp-content文件夹并输入以下两行:

sudo chown -R www-data uploads/
sudo chmod -R 755 uploads/

or you can use the static and full path:

或者您可以使用静态和完整路径:

sudo chown -R www-data /var/www/wp-content/uploads/
sudo chmod -R 755 /var/www/wp-content/uploads/

Do not change it to permissions 777 because that is simply insecure

不要将其更改为权限 777,因为那是不安全的

回答by lev.tuby

I had the same problems last week. After trying all proposed solutions with no success, it occurred to me that we had SElinux enabled on the server. In my case, and maybe for many other people, SElinux was responsible of the error message:

我上周遇到了同样的问题。在尝试了所有建议的解决方案但没有成功后,我突然想到我们在服务器上启用了 SElinux。在我的情况下,也许对许多其他人来说,SElinux 是错误消息的原因:

Unable to create directory wp-content/uploads/2013/04. Is its parent directory writable by the server?

My solution is based on the one proposed here: http://doc-ok.org/?tag=selinuxwhich could be more suitable to other people's needs.

我的解决方案基于此处提出的解决方案:http: //doc-ok.org/?tag=selinux,它可能更适合其他人的需求。

In my case, my wordpress directory resides in my home folder on the server, to which I have ssh access. Otherwise you will have to ask your administrator.

就我而言,我的 wordpress 目录位于服务器上的主文件夹中,我可以通过 ssh 访问该文件夹。否则,您将不得不询问您的管理员。

Anyway, this is my solution.

无论如何,这是我的解决方案。

chgrp -R apache wordpress #change wordpress with your base directory for wp..
#alternatively, chown the whole directory to apache
chmod -R 774 wordpress/wp-content #if chown by apache, the permissions can be more restrictive

In my case not only the folder ownership / group ownership had to be changed to apache. Also the SElinux label of wp-content directory had to be changed to either httpd_sys_rw_content_t or httpd_sys_content_t:

在我的情况下,不仅文件夹所有权/组所有权必须更改为 apache。此外,wp-content 目录的 SElinux 标签必须更改为 httpd_sys_rw_content_t 或 httpd_sys_content_t:

chcon -Rv --type=httpd_sys_content_t wordpress/wp-content

This did the trick for me.

这对我有用。

More information on SElinux can be found for example at:

有关 SElinux 的更多信息,例如可以在以下位置找到:

wiki.centos.org/HowTos/SELinux

wiki.centos.org/HowTos/SELinux

and

fedoraproject.org/wiki/SELinux

fedoraproject.org/wiki/SELinux

回答by doublesharp

The /wp-content/uploadsdirectory needs to be writeable by your webserver. Assuming that you are using Apache on Linux, and that it is running as user apache(change to your appropriate user) one quick fix for this would be to run the following command from your web root.

/wp-content/uploads目录需要可由您的网络服务器写入。假设您在 Linux 上使用 Apache,并且它以用户身份运行apache(更改为您的适当用户),一个快速解决方法是从您的 Web 根目录运行以下命令。

chown -R apache.apache wp-content/uploads
chmod -R 755 wp-content/uploads

回答by Mr KaMaL

I faced the same issue and I found a better solution:

我遇到了同样的问题,我找到了更好的解决方案:

  1. go to cpanel > phpmyadmin
  2. select database
  3. open wp_options table
  4. make sql query SELECT * FROM wp_options WHERE option_name LIKE '%upload_path%'
  5. change the path
  1. 转到 cpanel > phpmyadmin
  2. 选择数据库
  3. 打开 wp_options 表
  4. 进行sql查询 SELECT * FROM wp_options WHERE option_name LIKE '%upload_path%'
  5. 改变路径

回答by Max

this should fix it.

这应该解决它。

    sudo chown -R www-data:www-data wp-content/uploads

Do not change the permissions to 755 if it's not necessary. If it still doesn't work try:

如果没有必要,不要将权限更改为 755。如果它仍然不起作用,请尝试:

    chmod -R 755 wp-content/uploads

回答by Phong Thai

this works for me, after many weeks headache

这对我有用,经过数周的头痛

sudo chown -R apache uploads
sudo chmod -R 755 uploads

assuming you're in wp-content

假设你在 wp-content

回答by Vivin Veerali

for those who stumbled on selinux permission issue, here are the steps i made to fix them. We need to allow the following selinux boolean variables to allow installing of wordpress plugins from wordpress admin console using FTP. They are httpd_can_network_connect and ftpd_full_access. They can be activated by

对于那些偶然发现 selinux 权限问题的人,这里是我修复它们的步骤。我们需要允许以下 selinux 布尔变量来允许使用 FTP 从 wordpress 管理控制台安装 wordpress 插件。它们是 httpd_can_network_connect 和 ftpd_full_access。它们可以通过以下方式激活

setsebool ftpd_full_access on

setebool ftpd_full_access 打开

setsebool httpd_can_network_connect on

setebool httpd_can_network_connect 上

also wp-content folder should be write permissible for the ftp user used for uploading.

用于上传的 ftp 用户也应该允许写入 wp-content 文件夹。