我可以在不提供 FTP 访问的情况下安装/更新 WordPress 插件吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/640409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:30:05  来源:igfitidea点击:

Can I install/update WordPress plugins without providing FTP access?

wordpress

提问by user77413

I am using WordPresson my live server which only uses SFTPusing an SSHkey.

我使用的WordPress只使用我活的服务器上SFTP使用SSH密钥。

I want to install and upgrade plugins, but it appears that you are required to enter your FTP login to install the plugins. Is there a way to install and upgrade plugins by manually uploading the files instead of having WordPress handle the entire process?

我想安装和升级插件,但您似乎需要输入您的 FTP 登录名才能安装插件。有没有办法通过手动上传文件而不是让 WordPress 处理整个过程来安装和升级插件?

回答by stereoscott

WordPress will only prompt you for your FTP connection information while trying to install plugins or a WordPress update if it cannot write to /wp-contentdirectly. Otherwise, if your web server has write access to the necessary files, it will take care of the updates and installation automatically. This method does not require you to have FTP/SFTP or SSH access, but it does require your to have specific file permissions set up on your webserver.

如果无法/wp-content直接写入,WordPress 只会在尝试安装插件或 WordPress 更新时提示您输入 FTP 连接信息。否则,如果您的 Web 服务器具有对必要文件的写访问权限,它将自动处理更新和安装。此方法不需要您具有 FTP/SFTP 或 SSH 访问权限,但需要您在网络服务器上设置特定的文件权限。

It will try various methods in order, and fall back on FTP if Direct and SSH methods are unavailable.

它将按顺序尝试各种方法,如果 Direct 和 SSH 方法不可用,则回退到 FTP。

https://github.com/WordPress/WordPress/blob/4.2.2/wp-admin/includes/file.php#L912

https://github.com/WordPress/WordPress/blob/4.2.2/wp-admin/includes/file.php#L912

WordPress will try to write a temporary file to your /wp-contentdirectory. If this succeeds, it compares the ownership of the file with its own uid, and if there is a match it will allow you to use the 'direct' method of installing plugins, themes, or updates.

WordPress 会尝试将临时文件写入您的/wp-content目录。如果成功,它会将文件的所有权与其自己的 uid 进行比较,如果匹配,它将允许您使用“直接”方法安装插件、主题或更新。

Now, if for some reason you do not want to rely on the automatic check for which filesystem method to use, you can define a constant, 'FS_METHOD'in your wp-config.phpfile, that is either 'direct', 'ssh', 'ftpext' or 'ftpsockets'and it will use that method. Keep in mind that if you set this to 'direct', but your web user (the username under which your web server runs) does not have proper write permissions, you will receive an error.

现在,如果由于某种原因您不想依赖自动检查要使用的文件系统方法,您可以'FS_METHOD'在您的wp-config.php文件中定义一个常量,即两者之一'direct', 'ssh', 'ftpext' or 'ftpsockets',它将使用该方法。请记住,如果您将其设置为“direct”,但您的网络用户(运行网络服务器的用户名)没有适当的写入权限,您将收到错误消息。

In summary, if you do not want to (or you cannot) change permissions on wp-content so your web server has write permissions, then add this to your wp-config.php file:

总之,如果您不想(或不能)更改 wp-content 的权限以便您的 Web 服务器具有写入权限,请将其添加到您的 wp-config.php 文件中:

define('FS_METHOD', 'direct');


Permissions explained here:

权限解释在这里:

回答by unc0nnected

As stated before none of the perm fixes work anymore. You need to change the perms accordingly AND put the following in your wp-config.php:

如前所述,所有烫发修复都不再起作用。您需要相应地更改烫发并将以下内容放入您的wp-config.php

define('FS_METHOD', 'direct');

回答by sufinawaz

Just wanted to add that you must NEVER set the wp-contentpermission or permission of any folder to 777.

只是想补充一点,您绝不wp-content能将任何文件夹的权限或权限设置为777.

This is what I had to do to:

这是我必须做的:

1) I set the ownership of the wordpress folder (recursively) to the apache user, like so:

1)我将wordpress文件夹的所有权(递归)设置为apache用户,如下所示:

# chown -R apache wordpress/

# chown -R apache wordpress/

2) I changed the group ownership of the wordpress folder (recursively) to the apache group, like so:

2)我将wordpress文件夹的组所有权(递归)更改为apache组,如下所示:

# chgrp -R apache wordpress/

# chgrp -R apache wordpress/

3) give owner full privilege to the directory, like so:

3) 赋予所有者对该目录的完全权限,如下所示:

# chmod u+wrx wordpress/*

# chmod u+wrx wordpress/*

And that did the job. My wp-contentfolder has 755permissions, btw.

这就完成了工作。我的wp-content文件夹有755权限,顺便说一句。

TL;DR version:

TL;DR 版本:

# chown -R apache:apache wordpress
# chmod u+wrx wordpress/*

回答by Lamy

  1. In wp-config.phpadd define('FS_METHOD', 'direct');
  2. Make server writable the directories wp-content/, wp-content/plugins/.
  3. Install the plugin (copy the plugin dir into the wp-content/pluginsdir).
  1. wp-config.phpdefine('FS_METHOD', 'direct');
  2. 使服务器可写目录wp-content/, wp-content/plugins/
  3. 安装插件(将插件目录复制到wp-content/plugins目录中)。

Worked on version 3.2.1

在版本 3.2.1 上工作

回答by StreetCoder

open wp-config.phpfile and add the following line:

打开wp-config.php文件并添加以下行:

define('FS_METHOD', 'direct');

define('FS_METHOD', 'direct');

this is working for me ...Thanks

这对我有用......谢谢

回答by ravi patel

Just a quick change to wp-config.php

只需快速更改wp-config.php

define('FS_METHOD','direct');

That's it, enjoy your wordpress updates without ftp!

就是这样,享受没有 ftp的 wordpress 更新!

Alternate Method:

替代方法:

There are hosts out there that will prevent this method from working to ease your WordPress updating. Fortunately, there is another way to keep this pest from prompting you for your FTP user name and password.

Again, after the MYSQL login declarations in your wp-config.php file, add the following:

有一些主机会阻止这种方法工作以简化您的 WordPress 更新。幸运的是,还有另一种方法可以防止这种害虫提示您输入 FTP 用户名和密码。

同样,在 wp-config.php 文件中的 MYSQL 登录声明之后,添加以下内容:

define("FTP_HOST", "localhost");
define("FTP_USER", "yourftpusername");
define("FTP_PASS", "yourftppassword");

回答by JacquelineIO

In order to enable the use of SSH2 for your updates and theme uploads, you have to generate your SSH keys and have the PHP SSH module installed. Then WordPress will detect that you have SSH2 available and you'll see a different option (SSH2) displayed when doing an upload/upgrade.

为了能够使用 SSH2 进行更新和主题上传,您必须生成 SSH 密钥并安装 PHP SSH 模块。然后 WordPress 会检测到您有可用的 SSH2,并且您会在上传/升级时看到不同的选项 (SSH2)。

1.) Make sure you have the PHP module installed for debian it is:

1.) 确保为 debian 安装了 PHP 模块,它是:

sudo apt-get install libssh2-php

2.) Generate SSH keys, adding a passphrase is optional:

2.) 生成 SSH 密钥,添加密码是可选的:

ssh-keygen
cd  ~/.ssh
cp id_rsa.pub authorized_keys

3.) Change the permission so that WordPress can access those keys:

3.) 更改权限,以便 WordPress 可以访问这些密钥:

cd ~
chmod 755 .ssh
chmod 644 .ssh/*

Now you'll get the SSH2 option when doing an upload/upgrade/plugin. WP SSH Connection

现在,您将在执行上传/升级/插件时获得 SSH2 选项。 WP SSH 连接

4.) For added ease you can setup the defaults in your wp-config.phpand this will pre-populate the SSH credentials in the WordPress upload window.

4.) 为了更方便,您可以设置默认值wp-config.php,这将在 WordPress 上传窗口中预填充 SSH 凭据。

define('FTP_PUBKEY','/home/<user>/.ssh/id_rsa.pub');
define('FTP_PRIKEY','/home/<user>/.ssh/id_rsa');
define('FTP_USER','<user>');
define('FTP_PASS','passphrase');
define('FTP_HOST','domain.com');

The 'passphrase' is optional, if you don't setup a passphrase during ssh-kengen; then don't add it in wp-config.php

'passphrase' 是可选的,如果你没有在ssh-kengen; 然后不要添加它wp-config.php

This solved my issue. And I didn't have to do the chownat all. But I have seen this method referenced in other places.

这解决了我的问题。而我根本不需要这样做chown。但是我在其他地方看到过这种方法的引用。

References:

参考:

回答by Toby Allen

Usually you can just upload your plugin to the wp-content\pluginsdirectory. If you don't have access to this directory via SFTP I'm afraid you may be stuck.

通常,您只需将插件上传到wp-content\plugins目录即可。如果您无法通过 SFTP 访问此目录,恐怕您可能会被卡住。

回答by Roman

You can get it very easily by typing the following command on command promt

您可以通过在命令提示符下键入以下命令来轻松获取它

sudo chown -R www-data:www-data your_folder_name

or copy & paste the following code in your wp-config.php file.

或将以下代码复制并粘贴到 wp-config.php 文件中。

define('FS_METHOD', 'direct');

Where "your_folder_name" is the folder where your WordPress is installed inside this folder.

其中“your_folder_name”是您的 WordPress 安装在此文件夹中的文件夹。

回答by Bikram Shrestha

Execute the following code in terminal

在终端中执行以下代码

sudo chown -R www-data /var/www

For further detail visit Wordpress on Ubuntu install plugins without FTP access

有关更多详细信息,请访问 Ubuntu 上的 Wordpress 安装插件,无需 FTP 访问