如何从 OVH 服务器上的 ssh 命令行更新 Drupal 9?

Posted

技术标签:

【中文标题】如何从 OVH 服务器上的 ssh 命令行更新 Drupal 9?【英文标题】:How do I update Drupal 9 from ssh command line on OVH server? 【发布时间】:2021-12-31 10:44:38 【问题描述】:

我在 OVH 服务器上一键安装了 Drupal。第一个意外:我发现安装的 9.1.9 版需要安全更新到 9.2.9。

第二个意外:drush 默认没有安装。所以我必须先安装composer,才能使用以下命令安装drush

curl -sS https://getcomposer.org/installer | php

经过一些战斗,composer 工作正常。我安装了drush 发出命令:

composer require --dev drush/drush

可能--dev 标志不是必需的。

我看到composer 能够通过运行列出drupal 的可用更新:

composer show drupal/recommended-project --all
name     : drupal/recommended-project
descrip. : Project template for Drupal 9 projects with a relocated document root
keywords : 
versions : 9.4.x-dev, 9.3.x-dev, 9.3.0-beta2, 9.3.0-beta1, 9.3.0-alpha1, 9.2.x-dev, 9.2.9, 9.2.8, 9.2.7, 9.2.6, 9.2.5, 9.2.4, 9.2.3, 9.2.2, 9.2.1, 9.2.0, 9.2.0-rc1, 9.2.0-beta3, 9.2.0-beta2, 9.2.0-beta1, 9.2.0-alpha1, 9.1.x-dev, 9.1.14, 9.1.13, 9.1.12, 9.1.11, 9.1.10, 9.1.9, 9.1.8, 9.1.7, 9.1.6, 9.1.5, 9.1.4, 9.1.3, 9.1.2, 9.1.1, 9.1.0, 9.1.0-rc3, 9.1.0-rc2, 9.1.0-rc1, 9.1.0-beta1, 9.1.0-alpha1, 9.0.x-dev, 9.0.14, 9.0.13, 9.0.12, 9.0.11, 9.0.10, 9.0.9, 9.0.8, 9.0.7, 9.0.6, 9.0.5, 9.0.4, 9.0.3, 9.0.2, 9.0.1, 9.0.0, 9.0.0-rc1, 9.0.0-beta3, 9.0.0-beta2, 9.0.0-beta1, 9.0.0-alpha2, 9.0.0-alpha1, 8.9.x-dev, 8.9.20, 8.9.19, 8.9.18, 8.9.17, 8.9.16, 8.9.15, 8.9.14, 8.9.13, 8.9.12, 8.9.11, 8.9.10, 8.9.9, 8.9.8, 8.9.7, 8.9.6, 8.9.5, 8.9.4, 8.9.3, 8.9.2, 8.9.1, 8.9.0, 8.9.0-rc1, 8.9.0-beta3, 8.9.0-beta2, 8.9.0-beta1, 8.8.x-dev, 8.8.12, 8.8.11, 8.8.10, 8.8.9, 8.8.8, 8.8.7, 8.8.6, 8.8.5, 8.8.4, 8.8.3, 8.8.2, 8.8.1, 8.8.0, 8.8.0-rc1, 8.8.0-beta1, 8.8.0-alpha1
type     : project
license  : GNU General Public License v2.0 or later (GPL-2.0-or-later) (OSI approved) https://spdx.org/licenses/GPL-2.0-or-later.html#licenseText
homepage : https://www.drupal.org/project/drupal
source   : [git] https://github.com/drupal/recommended-project.git 7f83a471aca47ffaa981bc8cb8a0cf615163ae5b
dist     : [zip] https://api.github.com/repos/drupal/recommended-project/zipball/7f83a471aca47ffaa981bc8cb8a0cf615163ae5b 7f83a471aca47ffaa981bc8cb8a0cf615163ae5b
names    : drupal/recommended-project

support
chat : https://www.drupal.org/node/314178
docs : https://www.drupal.org/docs/user_guide/en/index.html
source : https://github.com/drupal/recommended-project/tree/9.4.x

requires
composer/installers ^1.9
drupal/core-composer-scaffold ^9.4
drupal/core-project-message ^9.4
drupal/core-recommended ^9.4

requires (dev)
drupal/core-dev ^9.4

conflicts
drupal/drupal *

我的问题是我安装了drupal/drupal,这显然与drupal/recommended-project 冲突,我看到我需要升级drupal

从 Drupal 9.1.9 升级到 Drupal 9.2.9 的下一步应该是什么?对不起,如果这个问题是微不足道的,但我被大量的文档弄得不知所措。

更新:这是我在主目录中找到的composer.json 文件:


    "require-dev": 
        "drush/drush": "^10.6"
    

还有 UPDATE2:这是我在 Drupal 根目录中找到的 composer.json 文件:


    "name": "drupal/legacy-project",
    "description": "Project template for Drupal 9 projects with composer following drupal/drupal layout",
    "type": "project",
    "license": "GPL-2.0-or-later",
    "homepage": "https://www.drupal.org/project/drupal",
    "support": 
        "docs": "https://www.drupal.org/docs/user_guide/en/index.html",
        "chat": "https://www.drupal.org/node/314178"
    ,
    "repositories": [
        
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        
    ],
    "require": 
        "composer/installers": "^1.9",
        "drupal/core-composer-scaffold": "^9.1",
        "drupal/core-project-message": "^9.1",
        "drupal/core-recommended": "^9.1",
        "drupal/core-vendor-hardening": "^9.1"
    ,
    "conflict": 
        "drupal/drupal": "*"
    ,
    "minimum-stability": "stable",
    "prefer-stable": true,
    "config": 
        "sort-packages": true
    ,
    "extra": 
        "drupal-scaffold": 
            "locations": 
                "web-root": "./"
            
        ,
        "installer-paths": 
            "core": [
                "type:drupal-core"
            ],
            "libraries/$name": [
                "type:drupal-library"
            ],
            "modules/contrib/$name": [
                "type:drupal-module"
            ],
            "profiles/contrib/$name": [
                "type:drupal-profile"
            ],
            "themes/contrib/$name": [
                "type:drupal-theme"
            ],
            "drush/Commands/contrib/$name": [
                "type:drupal-drush"
            ],
            "modules/custom/$name": [
                "type:drupal-custom-module"
            ],
            "profiles/custom/$name": [
                "type:drupal-custom-profile"
            ],
            "themes/custom/$name": [
                "type:drupal-custom-theme"
            ]
        ,
        "drupal-core-project-message": 
            "include-keys": [
                "homepage",
                "support"
            ],
            "post-create-project-cmd-message": [
                "<bg=blue;fg=white>                                                         </>",
                "<bg=blue;fg=white>  Congratulations, you’ve installed the Drupal codebase  </>",
                "<bg=blue;fg=white>  from the drupal/legacy-project template!               </>",
                "<bg=blue;fg=white>                                                         </>",
                "",
                "<bg=yellow;fg=black>Next steps</>:",
                "  * Install the site: https://www.drupal.org/docs/8/install",
                "  * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
                "  * Get support: https://www.drupal.org/support",
                "  * Get involved with the Drupal community:",
                "      https://www.drupal.org/getting-involved",
                "  * Remove the plugin that prints this message:",
                "      composer remove drupal/core-project-message"
            ]
        
    

【问题讨论】:

你能发布你的composer.json吗 您似乎登陆了this situation,无法使用 Composer 更新核心。引用重要部分:将现有的 drupal/drupal 站点切换到最新推荐的作曲家管理模板 drupal-composer/drupal-project 的一个选项是 GoComposer 插件。这很棒,因为 drupal-composer/drupal-project 也被弃用了!因此,如果您熟悉 Web 项目,则最好清理并重新安装以重新安装。应该让事情变得简单的服务使事情变得复杂,感谢 OVH.. @leymannx:我将更新我的问题并包含composer.json 文件。 这是您的 Drupal 文件夹中的 composer.json 吗?这不可能。您运行的composer show 命令和有关冲突的行只是告诉您推荐项目不会让您添加drupal/drupal。如果您发布的 composer.json 确实是您项目中唯一的一个,您需要找到一种方法在本地机器上下载更新的核心文件,通过 FTP 上传它们,然后在浏览器中访问 example.com/update.php。但是,如果您的网站不是 Composer 管理的,那么您会遇到困难,并且 Drush 在这里将无济于事。 Drush 将不再让您更新 Drupal 核心。而updating core manually 并不好玩。在这一点上,@EricLavault 确实可能是正确的,您从头开始重新启动。现在您在主机上安装了 Composer,您可以运行 composer create-project 命令来启动一个新项目。您可以尝试的最后一招是安装新的Automatic Updates 模块。 【参考方案1】:

如果您的项目是新项目,您可以在最新版本的 drupal 上执行一些操作。 为避免任何冲突,您必须:

rm -rf /vendor
rm composer.lock (this file fix the versions of your dependencies)

然后

composer update

它将安装每个依赖项的最新版本。 如果您只想更新drupal依赖项(不删除composer.lock和/vendor):

composer update drupal/core-recommended --with-dependencies

【讨论】:

谢谢。我已经找到了答案。无论如何,我很遗憾地告知我们将迁移到 Wordpress,因为它易于升级。【参考方案2】:

我像这样使用composer/drush/drupal的初始安装

drush 部分很重要

作曲家

PATH=/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php7.4.2/bin:$PATH
  php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8')  echo 'Installer verified';  else  echo 'Installer corrupt'; unlink('composer-setup.php');  echo PHP_EOL;"
  php composer-setup.php
  php -r "unlink('composer-setup.php');"
  sudo mv composer.phar /usr/local/bin/composer
  PATH="$(composer config -g home)/vendor/bin:$PATH"

冲刺

cd /drushproject/web/

composer require drupal/console:~1.0 --prefer-dist --optimize-autoloader

composer global require consolidation/cgr

cgr drush/drush

# correct DrushLog problems (alternatively run once: drush cr)
composer require drush/drush

drupal

drupal --root=/drushproject/web/

【讨论】:

以上是关于如何从 OVH 服务器上的 ssh 命令行更新 Drupal 9?的主要内容,如果未能解决你的问题,请参考以下文章

如何从命令行使用受限用户帐户更新 Azure 上的云服务

如何强制 ssh 从命令行接受新的主机指纹?

命令行怎么重启ssh,用/etc/init.d/ssh restart不行

如何查看linux上的ssh服务是不是正常

OVH - 执行 cron

身份验证在 ngrok 上的 PuTTY 命令行中不起作用