解决wordpress不能上传图片的权限限制问题,亲测有效

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

1、不能上传图片 
 
2、不能自动安装主题、插件(需要FTP账户)   
3、不能自动更新   
4、其它任何需要wordpress写文件的问题  
    这些问题基本都是一个原因,   你的wordpress目录不属于当前的用户和组,   即web访问的用户没有权限操作wp的一切需要写权限的操作。   解决方法    
首先需要你有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
  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.

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值