重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

Linux 无法写入权限问题 | Wordpress 不能自动安装主题、插件

折腾好 Wordpress,开始安装插件了,结果直接报错

香河网站建设公司创新互联公司,香河网站设计制作,有大型网站制作公司丰富经验。已为香河近千家提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的香河做网站的公司定做!

Installation failed: Could not create directory

当时站点健康工具(Site Health)里的文件系统权限(Filesystem Permissions) 全是 Not Writable

搜了一圈,这篇文章解决了我的问题:

Linux无法写入权限问题 & 解决Wordpress不能自动安装主题、插件
Author:flymorn Source:飘易

正 文:
当你的wordpress遇到以下问题时:

  1. 不能上传图片
  2. 不能自动安装主题、插件(需要FTP账户)
  3. 不能自动更新
  4. 其它任何需要wordpress写文件的问题

这些问题基本都是一个原因,你的wordpress目录不属于当前的用户和组,即web访问的用户没有权限操作wp的一切需要写权限的操作,其实就是linux下权限不足,无法写入造成的。

解决方法:

首先需要你有root权限,SSH登录,进入到wp的安装目录:

cd /var/www/html/my_wp_blog

给予所有的写权限:

chmod 777 wp-content

接下来给你的博客的文章上传一张图片,WP会生成一个目录,然后查看是哪个用户创建了文件夹。一般情况下,这个用户名叫“apache”,也有不少人发现这个用户是“nobody”,就飘易本身遇到的问题,我在VPS上安装的是LNmp,这个用户是“www”。

进入到wp的wp-content目录,查看该目录下所有文件/文件夹的权限,所属用户、用户组:

cd wp-content
ls -l
total 16
-rw-r–r– 1 root root   30 May  4  2007 index.php
drwxr-xr-x 3 root root 4096 Feb 10 19:31 plugins
drwxr-xr-x 5 root root 4096 Mar 23 03:04 themes
drwxrwxrwx 3 www www 4096 Mar 24 02:08 uploads

注意上传目录 uploads 是用户 www 创建的。
接下来把wp-content权限还原到 755::

cd ..
chmod 755 wp-content

下来就是实际修复的命令了,改变wp所在文件夹的拥有者为刚找到的这个用户www:

cd ..
chown -R www:www my_wp_blog

备注:补充以另外一种查找当前用户和组的名称的方法:
打开:

/usr/local/php/etc/php-fpm.conf

里面有 user和group项,看他们的值是什么,如下图:

Linux无法写入权限问题 & 解决Wordpress不能自动安装主题、插件
OK,问题解决了。下面是英文的原文:

There are a wide variety of problem reports appearing on support forums related to Wordpress that all have one root cause and solution. Here are some common issue descriptions:

  • Problems uploading images
  • Problems installing themes, plugins
  • Problems auto-upgrading Wordpress
  • Anything else where Wordpress needs to write files

And here is a typical error message:

“To perform the requested action, connection information is required.” Or…
“Unable to create directory [...]. Is its parent directory writable by the server?”

The problem is that Wordpress is executing in the context of your web server process, but the directories have write permissions based on the user context used to originally create the directories.

Many of the suggested solutions on the web simply won’t work, while other solutions work but create security problems with your Wordpress installation. Here is the full solution that should work on all Linux systems, regardless of the specific environment.

What we are going to do is give your web server ownership of the directories and files of your Wordpress install. This requires you to be knowledgeable and comfortable in your bash shell environment, which is probably reasonably true if you installed Wordpress yourself.

First we will give everybody write access so that WP can write the content directories. Some solutions on the web stop at this step, but this leaves your files with no filesystem security. We are only doing this briefly in order to determine what user context is being used by the web server.

Go to your Wordpress root directory:

cd /var/www/html/my_wp_blog

Give the world write access to the content directory:

chmod 777 wp-content

Now log into Wordpress and upload a photo to a blog post, causing WP to create the new directories required. Then look on the server to see what user created the directories. This would commonly be apache, but also many people are reporting that this is the user “nobody” on their server.

cd wp-content
ls -l

total 16
-rw-r–r– 1 root root   30 May  4  2007 index.php
drwxr-xr-x 3 root root 4096 Feb 10 19:31 plugins
drwxr-xr-x 5 root root 4096 Mar 23 03:04 themes
drwxrwxrwx 3 apache apache 4096 Mar 24 02:08 uploads

Notice that the uploads directory was created by user apache:apache. This is the information you needed. Go back down one dir level and set the permissions back to a secure level.

# cd ..
# chmod 755 wp-content

Now for the actual fix. Recursively set the owner and group for your Wordpress installation to the user that created the uploads directory.

# cd ..
# chown -R apache:apache my_wp_blog

You’re done. Wordpress now has access to the file system for photo and attachment uploads, automatic upgrades, and anything else needed by your plugins.


本文名称:Linux 无法写入权限问题 | Wordpress 不能自动安装主题、插件
文章转载:http://cqcxhl.com/article/dsoihcc.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP