折騰好 Wordpress,開始安裝插件了,結果直接報錯
Installation failed: Could not create directory
當時站點健康工具(Site Health)里的檔案系統權限(Filesystem Permissions) 全是 Not Writable

搜了一圈,這篇文章解決了我的問題:
Linux無法寫入權限問題 & 解決Wordpress不能自動安裝主題、插件
Author:flymorn Source:飄易
正 文:
當你的wordpress遇到以下問題時:
- 不能上傳圖片
- 不能自動安裝主題、插件(需要FTP賬戶)
- 不能自動更新
- 其它任何需要wordpress寫檔案的問題
這些問題基本都是一個原因,你的wordpress目錄不屬于當前的用戶和組,即web訪問的用戶沒有權限操作wp的一切需要寫權限的操作,其實就是linux下權限不足,無法寫入造成的,
解決方法:
首先需要你有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
備注:補充以另外一種查找當前用戶和組的名稱的方法:
打開:
/usr/local/php/etc/php-fpm.conf
里面有 user和group項,看他們的值是什么,如下圖:

Linux無法寫入權限問題 & 解決Wordpress不能自動安裝主題、插件
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.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/520605.html
標籤:其他
上一篇:Scala-隱式轉換
