兔源码网 - 专注DZ模版分享、DZ插件分享!

 找回密码
 立即注册

QQ登录

只需一步,快速开始

广告
温馨提示:本站所有DZ相关模板、插件、教程(包括DZ应用中心已下架插件、模板)所有用户可全部免费下载,无任何收费模式(不包括VIP版块非DZ资源,VIP版块需购买会员组方可下载),如本站没有您需要的插件或模板,请自行前往淘宝互站网送吗网等第三方站点搜索相关插件或模板进行低价格购买下载本站非常不建议用户浪费金钱前往DZ应用中心购买。

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

[复制链接]
tuzi 发表于 2015-8-8 22:57:08 | 显示全部楼层 |阅读模式
温馨提醒:禁止内容附带广告图片、二维码图片,否则将在不通知情况下永久禁言账号!
欢迎加入兔源码站长交流群,您的加入是我们前行的动力!

DZ站长建站交流群:493651246

[ 温馨提示:点击上方群文字,可快速加入QQ群 ]


正 文:
( i: a3 c. T7 R5 ^: p1 M
  H1 Q! S3 ^  V- y$ x
    当你的wordpress遇到以下问题时:8 E8 P$ @; k, m  o. J
1、不能上传图片
+ K( q4 h" J7 a& J4 _" l: a$ T2、不能自动安装主题、插件(需要FTP账户) $ d# \0 l; ?1 n! Q) E- ~& f7 {0 t0 Z) T/ W
3、不能自动更新 4 B' B, y3 S9 g
4、其它任何需要wordpress写文件的问题0 @( C) f# \5 y! J4 `, ~
    这些问题基本都是一个原因,你的wordpress目录不属于当前的用户和组,即web访问的用户没有权限操作wp的一切需要写权限的操作,其实就是linux下权限不足,无法写入造成的。
8 j2 N! f. S& k3 O: B解决方法. T) h. ?5 M8 n$ }
首先需要你有root权限,SSH登录,进入到wp的安装目录:7 ?8 c7 J1 c1 x$ u
cd /var/www/html/my_wp_blog) X& J# _+ ?; T3 @" s7 ~( A/ t3 I) P- L6 V
给予所有的写权限:' v0 H* J: o  T" E! C# O+ \
chmod 777 wp-content4 S$ D- d" P/ [6 w% X# J& J3 {  d
接下来给你的博客的文章上传一张图片,WP会生成一个目录,然后查看是哪个用户创建了文件夹。一般情况下,这个用户名叫“apache”,也有不少人发现这个用户是“nobody”,就飘易本身遇到的问题,我在VPS上安装的是LNmp,这个用户是“www”。
! A& I8 ?4 _0 j1 U- ?" v: I$ F进入到wp的wp-content目录,查看该目录下所有文件/文件夹的权限,所属用户、用户组:2 k1 M" x9 @4 q0 v
cd wp-content3 u/ A/ k( ]: O6 ~/ l" j
ls -l

" ]* k" G" V- n( V; T1 Jtotal 16! h1 C$ N9 [: L2 T2 @
-rw-r–r– 1 root root   30 May  4  2007 index.php
" I9 h: o  l# ~/ rdrwxr-xr-x 3 root root 4096 Feb 10 19:31 plugins$ g- F$ O4 H9 E0 Z8 n6 H! N
drwxr-xr-x 5 root root 4096 Mar 23 03:04 themes, |& j4 t2 `) i
drwxrwxrwx 3 www www 4096 Mar 24 02:08 uploads1 b. m, M' k+ D  D. `4 S. i# H7 N
注意上传目录 uploads 是用户 www 创建的。
) l8 @! n1 l8 v接下来把wp-content权限还原到 755::. e; \( H( p* N' V1 |7 ?5 \
cd ..- ?" d1 p) t/ f
chmod 755 wp-content
% l6 C$ x7 R) Z" b, P) ~: ^
下来就是实际修复的命令了,改变wp所在文件夹的拥有者为刚找到的这个用户www:' \3 U* V+ q) B
cd ..; v0 a, U  C8 @1 v' W
chown -R www:www my_wp_blog
* C# i2 G8 b, V/ ^, h0 H
备注:补充以另外一种查找当前用户和组的名称的方法
& F9 [  p( [2 ?8 ?5 a" W9 m  S8 v打开:
, T0 ~9 s4 U- l5 Q2 i/ w) V3 d/usr/local/php/etc/php-fpm.conf5 n* _5 m: c- W7 y
# @  E) s( N! {2 W/ }( y  f, }
里面有 user和group项,看他们的值是什么,如下图:1 K/ I+ o" b8 D1 P+ ?+ _$ ~$ b7 t
201432916553176.jpg

8 I4 F9 `5 c3 K" }
! q3 m* K5 J. u  a3 y9 v* G' L2 P) W9 IOK,问题解决了。下面是英文的原文:' k; ^% p- |. K5 }3 s  U- E6 s
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:
, j1 p2 r/ t% a; B5 S* Problems uploading images9 V4 j- m$ \5 w; [# U
* Problems installing themes, plugins+ t3 X4 k5 c) v7 m9 w( N: D
* Problems auto-upgrading Wordpress+ g  N8 d9 P+ t
* Anything else where Wordpress needs to write files+ A2 S- z5 B+ _7 ?7 _1 B
And here is a typical error message:+ i3 N- N2 R- T% y( p
“To perform the requested action, connection information is required.” Or…, @1 X) P. m* }: [" L5 R6 D2 I
“Unable to create directory [...]. Is its parent directory writable by the server?”) F' t9 d& K! a0 W6 j' q, j- J
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.( p5 e; z: {1 p) t# \+ P  ?
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.
: J4 w2 w# k" ?, s! MFirst 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.
# K; L5 ?) [7 H, }0 D4 a  IGo to your Wordpress root directory:, S; g+ j4 {0 W. X- _$ n; B
# cd /var/www/html/my_wp_blog
0 h! ^/ W! T" D% w( O, VGive the world write access to the content directory:
; ]8 P& _" e1 |# O, d# chmod 777 wp-content
: o+ o( d2 |6 E- C" e; g* @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.# B9 E, o: D4 |6 S7 Q. Q
# cd wp-content
2 E, c" C0 t+ U8 h! I1 O# ls -l
0 O3 S* w5 H, p: E6 z* l: S
total 16/ G7 v4 V/ [0 u
-rw-r–r– 1 root root   30 May  4  2007 index.php7 f( X# q: I1 f/ G/ C; p- n
drwxr-xr-x 3 root root 4096 Feb 10 19:31 plugins3 c" L7 m$ L. O3 ]2 J. }
drwxr-xr-x 5 root root 4096 Mar 23 03:04 themes
8 L' @+ {# |5 C" a" \, wdrwxrwxrwx 3 apache apache 4096 Mar 24 02:08 uploads$ j) v  Q/ p; d5 n% g! k: Q! b
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.
3 Z. r7 E0 u+ n! |- O% E# cd ..
% f0 Z: r  y/ _& h# chmod 755 wp-content
3 m5 U, g; a9 i  f/ ~
Now for the actual fix. Recursively set the owner and group for your Wordpress installation to the user that created the uploads directory.3 @, X  [: u' N7 F: K  o7 Q: F1 i
# cd ..4 g' S5 T7 e! N; j. E5 ^
# chown -R apache:apache my_wp_blog
9 f& _+ s$ O* x
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.
% k; T2 I# A( `& i' Y" ], C' U

版权声明
1、转摘或引用本站内容资源须注明原网址,并标明本站网址(兔源码www.tuyuanma.com);
2、对于转摘或引用本站内容资源而引起的民事纠纷、行政处罚或其他损失,本站不承担责任;
3、对于不遵守本声明或其他违法、恶意使用本站内容者,本站保留其追究法律责任的权利。




自动排版 | 高级模式
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广告

兔源码网 ( 赣ICP备17001544号 公网安备36112102000036号 )

兔源码 QQ交流群:493651246  GMT+8, 2019-11-12 03:51
←站长统计工具 查看密码:tuyuanma

兔源码DZ模板下载 站长邮箱:tuyuanma@qq.com 站长QQ:3197813386 网站地图

© 2001-2013 本站内容皆来自互联网及用户分享,如需删除请提供软著或商标证书。

     
快速回复 返回顶部 返回列表