登录drupal管理员

One of the struggles that developers face when moving to Drupal 8 is the lack of best practices in deploying Drupal sites. The Challenges in deployment revolve around Dependency Management, Drupal Contrib Modules/Themes, Configuration Management, and of course Code Base.

开发人员迁移到Drupal 8时面临的困难之一是缺乏部署Drupal站点的最佳实践。 部署中的挑战围绕着依赖性管理,Drupal Contrib模块/主题,配置管理,当然还有代码库。

Drupal 7 has no such problems. But ahhh, Drupal 8 comes with lots of stuff to manage. One of the biggest changes in Drupal 8 is the adoption of Composer. Good things come at a price.

Drupal 7没有这样的问题。 但是啊,Drupal 8有很多东西要管理。 Drupal 8中最大的变化之一就是采用了Composer。 好东西是有代价的。

We will use one codebase for one Drupal site and use Git for version control and deployment.

我们将为一个Drupal站点使用一个代码库,并使用Gi​​t进行版本控制和部署。

作曲家 (Composer)

Composer is a dependency manager for PHP (like npm for Node or pip for Python). Drupal core uses Composer to manage core dependencies like Symfony components and Guzzle. Composer allows us to systematically manage a list of dependencies and their subsidiary dependencies. Composer installs these dependencies via a manifest file called composer.json.

Composer是PHP的依赖项管理器(如Node的npm或Python的pip)。 Drupal核心使用Composer来管理Symfony组件和Guzzle等核心依赖项。 Composer允许我们系统地管理依赖项及其附属依赖项的列表。 Composer通过名为composer.json的清单文件安装这些依赖项。

This composer.json file contains the dependencies that the project requires. You can install it by running

此composer.json文件包含项目所需的依赖项。 您可以通过运行来安装它

composer install

for the first time. It locates, downloads, validates, and loads the packages. It also ensures that exactly the right versions for each package are used, and maintains the log file called composer.lock.

首次。 它查找,下载,验证和加载程序包。 它还确保为每个软件包使用完全正确的版本,并维护名为composer.lock的日志文件。

Note: always commit your composer.lock file, because it contains the exact version of the dependencies that you have defined in the project.

注意:始终提交composer.lock文件,因为它包含您在项目中定义的依赖项的确切版本。

If you want to update any specific package, it’s a good practice to run this command:

如果要更新任何特定的程序包,则运行此命令是一个好习惯:

composer update package/package-name

You should never run composer update, because composer will try to update every single dependency. This can cause problems to your site.

您永远不要运行composer update,因为composer会尝试更新每个依赖项。 这可能会导致您的网站出现问题。

Drupal作曲家 (Drupal Composer)

drupal-composer/drupal-project is the life-saver project for managing your site dependencies with Composer.

drupal-composer / drupal-project是用于通过Composer管理站点依赖项的救生项目。

To install this project template, run this command:

要安装此项目模板,请运行以下命令:

composer create-project drupal-composer/drupal-project:8.x-dev drupal8 — stability dev — no-interaction

It will automatically install a Drupal site with all the dependencies. It will also install Drupal console and Drush locally.

它将自动安装具有所有依赖项的Drupal站点。 它还将在本地安装Drupal控制台和Drush 。

Composer is one of the fastest ways to install dependencies, as it caches the dependencies and loads data from the cache the next time.

Composer是安装依赖项的最快方法之一,因为它会缓存依赖项并在下一次从缓存中加载数据。

目录结构 (Directory structure)

It is different from the Drupal directory structure. You can reassemble web directory with the public directory which contains Drupal files. All third party dependencies are outside the web folder.

它与Drupal目录结构不同。 您可以使用包含Drupal文件的公共目录重新组装Web目录。 所有第三方依赖项都在Web文件夹之外。

You can install any Drupal Modules, themes, and profiles through composer which will be downloaded in the contrib folder inside the modules, themes, and profiles, respectively. In this way, the composer.lock file will have a record of all the Drupal contrib modules along with the third party dependencies.

您可以通过composer安装任何Drupal模块,主题和配置文件,这些文件将分别下载到模块,主题和配置文件内的contrib文件夹中。 这样,composer.lock文件将具有所有Drupal contrib模块以及第三方依赖项的记录。

To download any modules and themes using composer, run the following:

要使用composer下载任何模块和主题,请运行以下命令:

composer require drupal/mediumish_blog
# For installing theme, we will use drupal console
drupal theme:install mediumish_blog

吉特尼奥雷 (Gitignore)

As are all the dependencies and Drupal contrib modules, themes are managed by composer. Therefore, we will not push this content to Git.

与所有依赖项和Drupal contrib模块一样,主题由作曲家管理。 因此,我们不会将此内容推送到Git。

# Ignore directories generated by Composer /drush/contrib /vendor/ /web/core/ /web/modules/contrib/ /web/themes/contrib/ /web/profiles/contrib/ /web/libraries/
# Ignore sensitive information /web/sites/*/settings.php /web/sites/*/settings.local.ph

配置管理 (Configuration management)

Deployment and configuration management are common actions of a project life cycle. We have installed various modules and configured our local site, but our production site has no such configuration.

部署和配置管理是项目生命周期中的常见操作。 我们已经安装了各种模块并配置了我们的本地站点,但是我们的生产站点没有这样的配置。

In Drupal 7, we had the features module, which is used to sync configuration. But Drupal 8 has an inbuilt solution for managing configurations. This allows you to export complete website configurations and store them in YAML files. Exported files can be imported to another website with the same result.

在Drupal 7中,我们具有功能模块,该模块用于同步配置。 但是Drupal 8具有用于管理配置的内置解决方案。 这使您可以导出完整的网站配置,并将其存储在YAML文件中。 导出的文件可以导入到另一个具有相同结果的网站。

Drupal’s configuration system helps to solve the config files synchronization problem in two ways: a unified way to store configuration, and a process to import/export changes between instances of the same site.

Drupal的配置系统以两种方式帮助解决配置文件同步问题:统一的方式来存储配置,以及在同一站点的实例之间导入/导出更改的过程。

如何同步配置文件 (How to synchronize config files)

Open /web/sites/default/settings.php and set $config_directories[‘sync’]

打开/web/sites/default/settings.php并设置$ config_directories ['sync']

$config_directories[‘sync’] = ‘../config/sync’;

It’s a good practice to store config files outside of the web directory to avoid making them accessible from the Internet.

好的做法是将配置文件存储在Web目录之外,以避免从Internet访问它们。

Now use the Drupal console to export the configuration:

现在使用Drupal控制台导出配置:

drupal config:export
# import on prod server
drupal config:import

Note: the production and local Drupal sites should have same UUIDs. Check here for more info.

注意:生产站点和本地Drupal站点应具有相同的UUID。 在此处查看更多信息。

Note: Drupal configuration management has a bug — custom blocks data should neither be imported nor be exported. View the Issue Link here.

注意: Drupal配置管理有一个错误-自定义块数据既不能导入也不能导出。 在此处查看问题链接。

吉特 (Git)

We will use Git to add, commit, and push the local site’s data with all the configuration. This will be pulled from the prod server/site. Let’s see the flow:

我们将使用Git通过所有配置添加,提交和推送本地站点的数据。 这将从产品服务器/站点中拉出。 让我们看一下流程:

# Local
git add .
git commit -m”Add commit message”
git push origin HEAD
# Server
git pull otigin HEAD
composer install # to install any new dependencies, drupal contrib modules, themes
drupal config:import # to import the configuration
drupal cache:rebuild all # rebuild the cache

更新模块,主题和配置文件 (Update modules, themes, and profiles)

composer update drupal/mediumish_blog
drupal update:execute mediumish_blog
drupal update:execute all

更新Drupal核心 (Update Drupal core)

Generally, we face problems in updating the Drupal core. But composer has a simple way to manage this, too:

通常,我们在更新Drupal核心时会遇到问题。 但是作曲家也有一种简单的方法来管理它:

composer update drupal/core — with-dependencies

It will update the Drupal core and all its associated dependencies.

它将更新Drupal核心及其所有相关的依赖项。

管理环境配置 (Managing environment configuration)

My favorite aspect of Drupal, as a developer, is the ability to manage different environment configurations. This can be done by using the vlucas/phpdotenv module, which also comes with the Drupal composer template.

作为开发人员,Drupal最喜欢的方面是管理不同环境配置的能力。 这可以通过使用vlucas / phpdotenv模块完成,该模块也随Drupal作曲家模板一起提供。

Anything that is likely to change between deployment environments — such as database credentials or credentials for 3rd party services — should be extracted from the code into environment variables. Basically, an .env file is an easy way to load custom configuration variables that your application needs without having to modify any other files.

在部署环境之间可能发生任何更改的所有内容,例如数据库凭据或第三方服务的凭据,都应从代码中提取到环境变量中。 基本上, .env文件是加载应用程序所需的自定义配置变量的简便方法,而无需修改任何其他文件。

Rename .env.example to .env file and add all the credentials as a key-value pair in .env file.

将.env.example重命名为.env文件,并将所有凭据添加为.env文件中的键值对。

load.environment.php file in the root will load this .env file and make it available for you.

根目录中的load.environment.php文件将加载此.env文件并使之可供您使用。

如何使用.env文件 (How to use .env file)

Open /web/sites/default/setting.php and add this set of code:

打开/web/sites/default/setting.php并添加以下代码集:

$databases[‘default’][‘default’] = [ ‘database’ => getenv(‘MYSQL_DATABASE’), ‘driver’ => ‘mysql’, ‘host’ => getenv(‘MYSQL_HOSTNAME’), ‘namespace’ => ‘Drupal\\Core\\Database\\Driver\\mysql’, ‘password’ => getenv(‘MYSQL_PASSWORD’), ‘port’ => getenv(‘MYSQL_PORT’), ‘prefix’ => ‘’, ‘username’ => getenv(‘MYSQL_USER’), ];

Open .env file and set the following credentials:

打开.env文件并设置以下凭据:

MYSQL_DATABASE=’db_name’ MYSQL_HOSTNAME=’localhost’ MYSQL_PASSWORD=’secret’ MYSQL_PORT=’3306' MYSQL_USER=’root’

Now, as all our credentials are stored in the .env file, we can push our settings.php to the server and manage its configuration through .env file.

现在,由于所有凭据都存储在.env文件中,因此我们可以将settings.php推送到服务器,并通过.env文件管理其配置。

We generally enable twig debugging while in development and disable upon production. This can also be done easily and smoothly through an .env file.

我们通常在开发时启用树枝调试,并在生产时禁用。 您也可以通过.env文件轻松,顺利地完成此操作。

Add a new key value pair in .env file:

在.env文件中添加一个新的键值对:

APP_ENV=’local’

Now copy web/sites/example.settings.local.php to web/sites/default/settings.local.php and add this code in web/sites/development.services.yml under parameters:

现在,将web / sites / example.settings.local.php复制到web / sites / default / settings.local.php并将此代码添加到web / sites / development.services.yml中的参数下:

twig.config: debug: true auto_reload: true cache: false

Now open web/sites/default/settings.php and add this code:

现在打开web / sites / default / settings.php并添加以下代码:

$env = getenv(‘APP_ENV’);
$base_path = $app_root . ‘/’ . $site_path; $settingsFile = $base_path . ‘/settings.’ . $env . ‘.php’;
if (file_exists($settingsFile)) { include $settingsFile; }

So, in this way, if you set your APP_ENV=’local’, Twig debug will be enabled. Upon production, you can disable by setting APP_ENV=’prod’. You can also configure different configurations for different environments.

因此,以这种方式,如果您将APP_ENV ='local'设置为,则会启用Twig调试。 生产后,可以通过设置APP_ENV ='prod'来禁用。 您还可以为不同的环境配置不同的配置。

结论 (Conclusion)

Drupal 8 offers a built-in solution for exporting and importing site configurations, which is way better than what you could do in D7. Dependencies and contrib modules/themes are managed by the composer itself.

Drupal 8提供了用于导出和导入站点配置的内置解决方案,这比您在D7中可以做的更好。 依赖关系和贡献模块/主题由作曲家自己管理。

It’s not yet perfect, as there is no standard approach, but the workflow described above is a simple and efficient solution. You can define your own workflow based on your needs.

由于尚无标准方法,因此它还不是完美的,但是上述工作流程是一种简单而有效的解决方案。 您可以根据需要定义自己的工作流程。

For reference, I have pushed the code to this repo.

作为参考,我已将代码推送到此repo 。

I hope you have found this article useful. I would love to hear your feedback :)

希望本文对您有所帮助。 我很想听听您的反馈意见:)

This article is from my own blog. To read more such articles, follow it here.

本文来自我自己的博客。 要此类文章,请在此处关注 。

翻译自: https://www.freecodecamp.org/news/the-best-way-to-manage-your-drupal-workflow-ade9525a84c0/

登录drupal管理员

登录drupal管理员_管理您的Drupal工作流程的最佳方法相关推荐

  1. 登录drupal管理员_天气公司依靠Drupal来管理内容

    登录drupal管理员 在通过WorldCom作为Sun硬件和软件工程师构建和配置企业级解决方案来帮助在.com中打下基础之后,Jason Smith进入了AAAS (美国科学促进协会,以及< ...

  2. python删除字符串中重复字符_从Python中删除字符串标点符号的最佳方法

    似乎有一个比以下更简单的方法: 1 2 3import string s ="string. With. Punctuation?" # Sample string out = s ...

  3. 多媒体中控软件开发流程_网络多媒体:视频工作流程提示

    多媒体中控软件开发流程 Just as with images, there is a production workflow to creating video. By necessity, I a ...

  4. sql server management studio 已停止工作_便利店员工的每日工作流程

    07:00-07:30 营业前的准备工作 开业前点检 开启音乐.电视屏和收银机,营业前准备工作 顾客服务 温度管理记录 热食商品制作 高敏感商品点检 果蔬验货.上架陈列 短效期商品保质期复查 07:3 ...

  5. react中绑定点击事件_在React中绑定事件处理程序的最佳方法

    react中绑定点击事件 by Charlee Li 通过李李 在React中绑定事件处理程序的最佳方法 (The best way to bind event handlers in React) ...

  6. html计算器_学习HTML、CSS和JavaScript的最佳方法是什么?

    与其他后端语言相比,HTML.CSS和JavaScript无论从阅读角度还是编写的角度来说都更加容易一点.所以新手在学习前端知识的时候不必有太大的心理压力 ,心态摆正后,大部分人都可以将前端学好.下面 ...

  7. 软件开发安全性_开发具有有效安全性的软件的最佳方法

    软件开发安全性 Casey将于10月4日在柏林LinuxCon上发表演讲 . 无论您进行编程的级别如何,安全性都将受到阻碍. 似乎没有多少应用程序抽象或现代开发过程能够使开发人员免受安全性带来的障碍. ...

  8. 负压电路_通风设备之负压风机的工作原理与安装方法是怎样的?

    点击上方蓝字关注我吧! 作为通风设备之一的负压风机在厂房车间通风换气降温的过程中也发挥了比较重要的作用,常见的车间通风降温方案有工业大风扇+环保空调的"扇机组合",也有环保空调+负 ...

  9. smc数显压力表设定方法_自动增压泵不停止工作原因及解决方法

    如果您发现自动增压泵不用水时依然不停止工作,有可能是以下原因引起的: 1.可能是停机压力值设定过高.如果停机压力设定过高,增压泵无论有没人用水都无法达到设定压力值,不停机也是理所当然啦. 解决方法:如 ...

最新文章

  1. 2021-04-06 符号执行是啥?
  2. 颜值爆表!这是我目前见过最好看的标签页插件了,强烈推荐!
  3. iOS开发之--打印一堆奇怪东西的解决方案
  4. 【Android 逆向】ART 脱壳 ( InMemoryDexClassLoader 脱壳 | dex_file.cc 中创建 DexFile 实例对象的相关函数分析 )
  5. 硬件工程师面试经历2015---面试篇
  6. 解决tomcat同时部署多个SpringBoot应用提示InstanceAlreadyExistsException
  7. HDU 3328 Flipper 栈 模拟
  8. onCreate onRestoreInstanceState onSaveInstanceState
  9. java如何调用linux命令_java程序中如何调用linux命令
  10. 折腾kali linux2.0
  11. congestion map解读
  12. Springcloud学习系列之Ribbon自定义负载均衡规则
  13. 快速下载【百度文库】文档
  14. 生信技能树课程记录笔记(六)20220530
  15. 小米笔记本显示器关闭后无法唤醒曲线解决办法
  16. __stdcall使用
  17. 计算机word虚线在哪里,电脑虚线怎么打出来
  18. 操作系统基础教程——第六章课后答案
  19. liunx更改root@后面的主机名
  20. 杭电计算机专硕报考人数,杭电考研各科目考试工具规定公布,它的报考人数却……...

热门文章

  1. Java缓存Ehcache-核心类和方法介绍及代码实例
  2. 【OpenGL4.0】GLSL-Flat Shading平面着色
  3. 主窗体相关的知识点 winform
  4. 上机 文件读写器 c# 1614998685
  5. 钉钉下载与安装过程 适用于windows系统 20200718
  6. dj鲜生-27-登陆装饰器-使用django内置的登陆装饰器
  7. dj鲜生-通过邮箱发送加密的激活链接
  8. jquery-ajax-jsonp-360搜索引擎的联想词获取
  9. python Django ORM ,用filter方法表示“不等于”的方法
  10. 查看SQL Server当前会话的隔离级别