正 文:php
當你的wordpress遇到如下問題時:
一、不能上傳圖片
二、不能自動安裝主題、插件(須要FTP帳戶)
三、不能自動更新
四、其它任何須要wordpress寫文件的問題
這些問題基本都是一個緣由,你的wordpress目錄不屬於當前的用戶和組,即web訪問的用戶沒有權限操做wp的一切須要寫權限的操做,其實就是linux下權限不足,沒法寫入形成的。html
解決方法:
首先須要你有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_bloglinux
備註:補充以另一種查找當前用戶和組的名稱的方法:
打開:web
/usr/local/php/etc/php-fpm.confshell
裏面有 user和group項,看他們的值是什麼,以下圖:apache
OK,問題解決了。下面是英文的原文:bash
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?」app
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.less
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.ide
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.