Linux无法写入权限问题 & 解决Wordpress不能自动安装主题、插件-站长杂谈下载

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

开通本站Svip会员,全站资源免费下
正 文:
* z- _* d, W/ \! u9 a

' s$ f/ m9 V* q8 j# G6 l- P
    当你的wordpress遇到以下问题时:/ [& b& ~/ N2 b: Z
1、不能上传图片 7 ^6 S7 w1 G  Z5 O" r" k) @3 V
2、不能自动安装主题、插件(需要FTP账户)
* U# U" i4 W* w- k* c3、不能自动更新 : L/ S6 g6 Q* {
4、其它任何需要wordpress写文件的问题- W2 J; U: F+ B; l( o: Q7 N; N& X
    这些问题基本都是一个原因,你的wordpress目录不属于当前的用户和组,即web访问的用户没有权限操作wp的一切需要写权限的操作,其实就是linux下权限不足,无法写入造成的。' q7 Q* K' @! O
解决方法
# e# M: b, N8 Q0 f2 T首先需要你有root权限,SSH登录,进入到wp的安装目录:
4 L" g+ V! I2 u2 j' E% T) ccd /var/www/html/my_wp_blog. T8 P5 K" {+ y
给予所有的写权限:
2 A0 z& ?. I9 n% b, x6 W* Mchmod 777 wp-content
# t& n1 R9 F4 p( Q  g+ n9 s接下来给你的博客的文章上传一张图片,WP会生成一个目录,然后查看是哪个用户创建了文件夹。一般情况下,这个用户名叫“apache”,也有不少人发现这个用户是“nobody”,就飘易本身遇到的问题,我在VPS上安装的是LNmp,这个用户是“www”。
& L/ s( o( q; F4 m( ^进入到wp的wp-content目录,查看该目录下所有文件/文件夹的权限,所属用户、用户组:
, x. ]7 m: a8 J, Q! i! Tcd wp-content: F/ S% L3 A# ]: m* k
ls -l
& L7 N5 m  t3 Q
total 16# [7 A1 [2 L+ ]* T7 u/ |3 W/ f
-rw-r–r– 1 root root   30 May  4  2007 index.php. v/ {; Z4 G+ ~- W
drwxr-xr-x 3 root root 4096 Feb 10 19:31 plugins6 m* ^7 b; ~$ b0 A7 |
drwxr-xr-x 5 root root 4096 Mar 23 03:04 themes4 W7 {) @; Z  [# U- D5 L$ j
drwxrwxrwx 3 www www 4096 Mar 24 02:08 uploads
' y4 ~8 t: k& H: A& ^注意上传目录 uploads 是用户 www 创建的。; l: ]6 l& S6 q+ q5 X% ^! o$ V6 N) M
接下来把wp-content权限还原到 755::
. v; Y$ S2 s: i0 N$ G. j" ]2 Icd ..
0 e- b" a# b" u5 kchmod 755 wp-content

3 i! a% j8 S8 Y+ M" _3 F下来就是实际修复的命令了,改变wp所在文件夹的拥有者为刚找到的这个用户www:! t& a" y1 t" j( x, Y
cd ..
4 U+ z) |; Q& W$ |" g( H* Kchown -R www:www my_wp_blog
, k5 E" d# _& Q9 S; C
备注:补充以另外一种查找当前用户和组的名称的方法
& G0 ]8 ~, u. A6 y% I打开:
( @8 M! K3 k9 n( t! u' c/usr/local/php/etc/php-fpm.conf: a  s- Y9 F, u3 m

2 |4 }: t' ?! s- {  d  ~里面有 user和group项,看他们的值是什么,如下图:3 u* n) t0 w7 X0 P
201432916553176.jpg
7 o1 P5 ~/ G- e& S' L1 F5 J, q

9 p1 u7 ^6 |( B1 ^% HOK,问题解决了。下面是英文的原文:
7 K; f4 O3 H, ?* D+ ?4 hThere 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:
3 x  H* \9 f% F0 R" f- H* Problems uploading images
5 ], f8 m0 a7 k+ j: i) g% d; W7 M* Problems installing themes, plugins
% U3 |4 b. K+ o$ H* Problems auto-upgrading Wordpress2 a5 G/ [0 ~2 ]% Z$ s: F/ i! n
* Anything else where Wordpress needs to write files* O4 z# o* u7 g6 b" f
And here is a typical error message:
8 i8 @3 k, i! U" {" B& E7 e" S3 e/ I“To perform the requested action, connection information is required.” Or…5 {7 [9 v8 n: c  p6 I+ t
“Unable to create directory [...]. Is its parent directory writable by the server?”
6 J# Y  S% s; u% Z. n& H% hThe 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.. S: }  N3 \1 |" C
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.
' Y7 u0 D+ g+ U% FFirst 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." R% a/ O1 W" [7 D) H# j6 i
Go to your Wordpress root directory:
% w( Q7 Q# C2 u& l1 J) _. u# cd /var/www/html/my_wp_blog9 S$ ]$ |9 z; P4 B8 _1 A; L3 x
Give the world write access to the content directory:
7 y- V% @. l  p5 {) J7 D# chmod 777 wp-content
0 L7 ?. \! r: l- U; a2 aNow 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.7 g9 d9 f  C2 n" A
# cd wp-content
2 \! t2 c8 I/ E2 p  x. u( N# ls -l
3 K8 T4 N5 Z. t1 g" q4 i+ K
total 16
! R% j& s! b: m-rw-r–r– 1 root root   30 May  4  2007 index.php4 X. r, x3 }* e4 Y
drwxr-xr-x 3 root root 4096 Feb 10 19:31 plugins
( N0 Z' e1 d$ w/ H- r4 fdrwxr-xr-x 5 root root 4096 Mar 23 03:04 themes
* i' p. i: `: Sdrwxrwxrwx 3 apache apache 4096 Mar 24 02:08 uploads
0 a9 J. \) x& ONotice 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 p) Q1 m/ L! S7 f% `# cd ..
- G- u+ d- b0 p7 O& |1 a# chmod 755 wp-content
/ U9 J7 u7 @$ e7 K4 C7 E
Now for the actual fix. Recursively set the owner and group for your Wordpress installation to the user that created the uploads directory.
# x' B1 J* S7 ~  i( ]' R# cd ..
7 Z* h6 v7 x8 a! S% A# chown -R apache:apache my_wp_blog

0 r/ N/ Y5 v, \0 s4 Y3 G3 KYou’re done. Wordpress now has access to the file system for photo and attachment uploads, automatic upgrades, and anything else needed by your plugins.
- z4 C( [" u: W  y0 T7 Q$ A7 r

全部评论 0

您需要登录后才可以回帖 立即登录
登录
0
0
0
返回顶部