Drupal 9:使用 DrupalVM 快速设置
我喜欢使用DrupalVM并且我已经使用基于Ansible的Vagrant设置工作多年,所以我非常熟悉它的设置。更重要的是,我发现我在运行它时遇到的问题很少。我通常使用Vagrant运行它,但如果您愿意,也可以使用Docker运行它。
当开始一个新的站点项目时,我通常将DrupalVM添加到代码库中,以便我可以快速启动并运行站点。如果涉及Solr之类的东西,这将特别有用,因为设置它很痛苦。我想我会完成将DrupalVM添加到您的代码库所涉及的步骤,因为它非常简单,并且可以让您在大约10分钟内启动并运行Drupal站点。
从Composer设置中的Drupal站点开始。我通常运行Drupal推荐的Composer安装文件,以便我有一个最新的Drupal代码库,所以让我们在这里做。
composercreate-projectdrupal/recommended-projectdrupal_vm_setup
这将创建您的Composer文件并安装Drupal代码库以及一些其他依赖项。有关推荐的Composer文件中内容的更多信息,请参阅我之前关于该主题的博客文章。在此步骤之后,您可以需要任何其他基于Drupal的模块或项目。此时添加Drush通常是一个好主意。
composerrequiredrush/drush
有了这个设置,下一步就是需要DrupalVM。我们这样做是作为“开发”依赖项,因为我们不需要在生产中运行DrupalVM。
composerrequire--devgeerlingguy/drupal-vm
这本身并没有做很多事情,所以在我们配置机器之前,我们需要添加一些配置文件。
我们需要添加到项目中的第一件事是一个VagrantFile,它将允许Vagrant运行。我们不是创建DrupalVMVagrantFile的完整副本,而是创建一个小的代理文件来设置配置目录,然后从DrupalVM目录加载VagrantFile。
将以下内容复制到您的VagrantFile中。
# The absolute path to the root directory of the project. Both Drupal VM and # the config file need to be contained within this path. ENV['DRUPALVM_PROJECT_ROOT'] = "#{__dir__}" # The relative path from the project root to the config directory where you # placed yourconfig.ymlfile. ENV['DRUPALVM_CONFIG_DIR'] = "box" # The relative path from the project root to the directory where Drupal VM is located. ENV['DRUPALVM_DIR'] = "vendor/geerlingguy/drupal-vm" # Load the real Vagrantfile load "#{__dir__}/#{ENV['DRUPALVM_DIR']}/Vagrantfile"
正如您在上面看到的,我们定义了一个名为“box”的配置目录。我们可以随意命名它,但我认为给它一个与“config”截然不同的名称很重要,这样它就不会与Drupal配置目录混淆。
在box目录中添加一个名为config.yml的文件。这是DrupalVM将用来以您想要的方式配置框的配置文件。
您放入此文件的内容可能会有很大差异。DrupalVM的默认配置文件绝对庞大,您无需复制所有这些选项即可让您的本地机器正常工作。相反,这些值的示例横截面可以更改一些默认值并公开一些更频繁更改的设置。下面的代码显示了一些合理的默认设置,可以让您正确设置机器,而无需尝试做您可能不想要的额外事情(例如,在设置好机器后安装Drupal)。
# Set up some defaults for the box. vagrant_box: geerlingguy/ubuntu1804 vagrant_machine_name: drupalvmsetup vagrant_hostname: "{{ vagrant_machine_name }}.local" vagrant_ip: 192.168.88.90 # Setup the vagrant synced folders. vagrant_synced_folders: - local_path: . destination: "/var/www/{{ vagrant_machine_name }}" type: nfs create: true drupal_core_path: "/var/www/{{ vagrant_machine_name }}/web" # Allow easy configuration of the machine resources. vagrant_memory: 2048 vagrant_cpus: 2 # The web server software to use. Can be either 'apache' or 'nginx'. drupalvm_webserver: apache # Turn off all automatic installer features. drupal_build_makefile: false drupal_build_composer: false drupal_build_composer_project: false drupal_install_site: false # Configure built in software. installed_extras: - adminer # - blackfire # - drupalconsole - drush # - elasticsearch # - java - mailhog # - memcached # - newrelic # - nodejs - pimpmylog # - redis # - ruby # - selenium # - solr # - tideways # - upload-progress - varnish # - xdebug # - xhprof # use `tideways` if you're installing PHP 7+ # Configure PHP and xdebug. php_version: "7.4" php_xdebug_idekey: PHPSTORM php_xdebug_version: "2.9.6" php_xdebug_default_enable: 1
完成所有设置后,您现在可以运行“vagrantup”,DrupalVM将为您配置您的机器。
完成后,您可以访问http://dashboard.drupalvmsetup.local/(或您添加到Vagrant文件中的任何URL)并查看DrupalVM仪表板。从这里您可以访问您的Drupal站点并开始正确安装Drupal。
您还可以使用“vagrantssh”登录框,这将直接带您进入Drupal代码库,并允许您在站点上运行Drush命令。
从头到尾,我可以在大约10到15分钟内从无到有到完全安装的Drupal站点,尽管这取决于您的互联网连接速度。这个设置的好处是它在你的代码库中创建了一个最小的设置,并且可以毫无问题地添加到你的项目gitrepo中。
顺便说一句,如果您想使用上述方法安装Drupal8,那么您唯一需要更改的是推荐项目设置的初始版本。
composercreate-projectdrupal/recommended-project8.9.0drupal_vm_setup