解决WordPress不能自动安装主题、插件,Linux无 写入权限问题

解决Wordpress不能自动安装主题、插件,Linux无 写入权限问题

正 文:


第一次安装,当你的wordpress遇到以下问题时:
1、无法上传图片
2、无法自动安装主题、插件(需要FTP账户)
3、无法自动更新
4、其它任何需要wordpress写操作文件的问题
其实这类问题基本都是一个原因, WordPress目录不属于当前的用户和组,即web访问的用户没有权限操作wp的一切需要写权限的操作,

其实就是linux下权限不足,无法写入造成的。

解决方法:

首先需要你有root权限,SSH登录,推荐winsows用户使用 Winscp、putty、xshell等一类的工具进入到wp的安装目录:

cd /var/www/html/my_wp_blog

(my_wp_blog为你的网站安装的根目录的文件夹名称,如我的网站根目录是www.nmbhost.com

那my_wp_blog  就要替换成www.nmbhost.com  以下雷同)

chmod 777

赋予所有的写权限:

chmod 777 wp-content

接下来给你的博客的文章上传一任意张图片,WP会生成一个目录,在wp-content文件夹下 然后查看是哪个用户创建了文件夹。

一般情况下,这个用户名叫“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

 

另外一种查找当前用户和组的名称的方法:
用winscp工具打开路径文件:

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

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

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

附上下面是国外网友的英文解决方法原文: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.



.user.ini 无法修改/删除

了解chattr命令:

Linux chattr命令用于改变文件属性。

这项指令可改变存放在ext2文件系统上的文件或目录属性,这些属性共有以下8种模式:

a:让文件或目录仅供附加用途。
b:不更新文件或目录的最后存取时间。
c:将文件或目录压缩后存放。
d:将文件或目录排除在倾倒操作之外。
i:不得任意更动文件或目录。
s:保密性删除文件或目录。
S:即时更新文件或目录i。
u:预防意外删除。
我们主要用的是 i 的模式

第二:

切换到 .user.ini 目录

第三:

使用命令 chattr -i .user.ini  解除文件不可更动属性,之后就可以修改/删除.user.ini这个文件了

第四:

chattr +i .user.ini   重新恢复文件不可更动属性
————————————————
版权声明:本文为CSDN博主「熊 :)」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42957379/article/details/86554287

允许随意转载;但,请点赞!点赞-NMBHOST:NMB HOST » 解决WordPress不能自动安装主题、插件,Linux无 写入权限问题

赞 (9) 点下广告支持吧 →▶
0 0 投票数
文章评分
订阅评论
提醒
guest

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

0 评论
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x