vagrant入门_Vagrant The Right Way™上的Sulu CMS入门

vagrant入门

In this tutorial, we’ll learn how to get started with Sulu CMS the right way – meaning, we’ll deploy a Sulu “Hello World” instance using Homestead Improved and be mindful of performance issues and configuration values while we’re at it. We’ll also cover some common pitfalls, all in an attempt to get a good base set up for future Sulu tutorials. It is recommended you follow along with the instructions in this post and drop a comment with any problems you might run into.

在本教程中,我们将学习如何以正确的方式开始使用Sulu CMS –意思是,我们将使用Homestead Enhanced部署Sulu“ Hello World”实例,并注意性能问题和配置值。 我们还将介绍一些常见的陷阱,以期为以后的Sulu教程奠定良好的基础。 建议您按照本文中的说明进行操作,并对可能遇到的任何问题发表评论。

Many thanks to Daniel Rotter and Patrik Karisch for helping me iron this process out!

非常感谢Daniel RotterPatrik Karisch帮助我解决了这一过程!

Note that it’s highly recommended to be familiar with Homestead Improved before starting out. If you’re not at that level yet, you should buy our amazing book about PHP Environment Basics.

请注意,强烈建议您在开始之前熟悉Homestead Improvementd 如果您还没有达到这个水平,则应该购买我们有关PHP Environment Basics的惊人书籍



[旁注]输入您的项目名称 ([Sidenote] Enter your project’s name)

This tutorial is dynamic in that it will replace all placeholders in the text below with the project name you define in the field under this paragraph. That way, the commands become very copy/paste friendly.

本教程是动态的,它将用您在本段下的字段中定义的项目名称替换下面文本中的所有占位符。 这样,命令变得非常易于复制/粘贴。

Generated slug: my_sulu_project

生成的子弹:my_sulu_project



OS X Vagrant文​​件夹共享问题 (OS X Vagrant Folder Sharing Problems)

When using the NFS folder-sharing mode on OS X hosts, the vagrant-bindfs plugin will be necessary. Install it alongside your Vagrant installation with vagrant install plugin vagrant-bindfs. This is a one-time thing that’ll prevent many, many headaches down the line if OS X is your main OS.

在OS X主机上使用NFS文件夹共享模式时,将需要vagrant-bindfs插件。 使用vagrant install plugin vagrant-bindfs将其与Vagrant安装一起vagrant install plugin vagrant-bindfs 。 如果OS X是您的主要操作系统,那么这是一次性的事情,它将避免很多麻烦。

The rest is all automatic and already configured in the Homestead Improved instance, you don’t need to do anything else.

其余的都是自动的,并且已经在Homestead Improvement实例中进行了配置,您无需执行其他任何操作。

无家可归 (Vagrant Up)

The first thing we do is, of course, clone the HI repo.

我们要做的第一件事当然是克隆HI回购。

git clone https://github.com/swader/homestead_improved my_sulu_project
cd my_sulu_project

Next, let’s configure the shared folders:

接下来,让我们配置共享文件夹:

bin/folderfix.sh

This made the current working directory shared with the /Code directory inside the VM. That way, the changes made in this folder will be reflected inside the virtual machine and vice versa.

这使得当前工作目录与VM中的/Code目录共享。 这样,在此文件夹中所做的更改将反映在虚拟机内部,反之亦然。

Like with any Symfony app, Sulu requires a custom virtualhost configuration for Nginx. We’ve made things easier by turning it into a “project type” in Homestead Improved, so all you need to do is the following modification on Homestead.yaml:

与任何Symfony应用程序一样,Sulu需要Nginx的自定义虚拟主机配置 。 通过在Homestead Improvement中将其转换为“项目类型”,我们使事情变得更加容易,因此您要做的就是对Homestead.yaml进行以下修改:

  • add the nfs folder sharing type (on OS X and Windows 10)

    添加nfs文件夹共享类型(在OS X和Windows 10上)

  • add the sulu project type and change its document root subfolder to web

    添加sulu项目类型并将其文档根子文件夹更改为web

The relevant sections should end up looking like this:

相关的部分应该看起来像这样:

...

folders:
    - map: /Users/swader/vagrant_boxes/homestead/my_sulu_project
      to: /home/vagrant/Code
      type: nfs

sites:
    - map: my_sulu_project.app
      to: /home/vagrant/Code/my_sulu_project/web
      type: sulu

Finally, let’s fire up the VM.

最后,让我们启动虚拟机。

vagrant up; vagrant ssh

Protip: Useful aliases to set up for future use:

Protip:有用的别名,供以后使用:

alias vh='vagrant halt; cd ..'
alias vush='vagrant up; vagrant ssh'
alias vh='vagrant halt; cd ..'
alias vush='vagrant up; vagrant ssh'

设置Sulu (Setting up Sulu)

创建项目 (Creating the Project)

Let’s install Sulu’s standard edition (the minimal edition is actually “standard” now, whereas the old “standard” is deprecated – they’re working on renaming this).

让我们安装Sulu的标准版( minimal版本现在实际上是“标准”,而旧的“标准”已过时-他们正在重命名)。

cd Code
composer create-project sulu/sulu-minimal my_sulu_project

Note that the docs currently suggest adding a -n flag at the end of that Composer command which means “No interactive questions”. I like it when an installer asks me about things I’m supposed to configure anyway, so I omitted it.

请注意, 文档当前建议在该Composer命令的末尾添加-n标志,这表示“无交互问题”。 当安装程序向我询问我应该配置的东西时,我喜欢它,因此我省略了它。

The installation will take a while because Symfony has a lot of dependencies (see the Polyfills sub-section in the Pitfalls and FAQ section below).

因为Symfony有很多依赖项,所以安装需要一段时间(请参阅下面的陷阱和常见问题解答部分中的Polyfills子部分)。

Once the packages have been downloaded, the installer will ask some questions about the database, email, and other user-fillable data. The only values you should have to set there will be the database related ones, and maybe the secret token or mailer settings if you know them by heart:

下载软件包后,安装程序将询问有关数据库,电子邮件和其他用户可填充数据的一些问题。 您唯一需要设置的值将是与数据库相关的值,如果您很清楚地知道它们,则可能是秘密令牌或邮件程序设置:

Some parameters are missing. Please provide them.
database_driver (pdo_mysql):
database_host (127.0.0.1):
database_port (null):
database_name (sulu): homestead
database_user (root): homestead
database_password (null): secret
database_version (5.5):
mailer_transport (smtp):
mailer_host (127.0.0.1):
mailer_user (null):
mailer_password (null):

...

You can always modify these manually after the fact by editing the app/config/parameters.yml file.

您可以始终在事后通过编辑app/config/parameters.yml文件手动修改这些文件。

网站空间 (Webspaces)

It’s time to set up a webspace. A webspace is like a single website inside of your Sulu installation. For example, think of SitePoint’s free, public facing side as one webspace, and the Premium side as another.

现在是时候建立网站空间了。 网站空间就像您在Sulu安装中的单个网站一样。 例如,将SitePoint的免费,面向公众的一面视为一个网站空间,将Premium面作为另一空间。

There’s an app/Resources/webspaces/example.com.xml file which should be renamed to match your project: app/Resources/webspaces/my_sulu_project.xml.

有一个app/Resources/webspaces/example.com.xml文件,应将其重命名以匹配您的项目: app/Resources/webspaces/my_sulu_project.xml

In that file, two values (name and key) need to be updated to match the project:

在该文件中,需要更新两个值( namekey )以匹配项目:

<?xml version="1.0" encoding="utf-8"?>
<webspace xmlns="http://schemas.sulu.io/webspace/webspace"
          xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://schemas.sulu.io/webspace/webspace http://schemas.sulu.io/webspace/webspace-1.1.xsd">

    <name>{{My Project}}</name>
    <key>my_sulu_project</key>

    <!-- ... -->
</webspace>

The filename and the key value do not have to match, but it’s usually clearer if they do.

文件名和键值不必匹配,但是如果匹配,通常会更清晰。

Something from the docs to keep in mind:

文档中要注意的一点:

Changing the <key> of a webspace later on causes complications. We recommend to decide what key to use before you build the database in the next step.

稍后更改Webspace的<key>会引起复杂性。 我们建议在下一步构建数据库之前决定要使用的密钥。

创建数据库 (Create the Database)

If you haven’t already, you should create the database. Homestead Improved comes with a default homestead database, accessible by the user homestead with the password secret, so if you’re using it, you probably don’t have to do anything.

如果还没有,则应该创建数据库。 改进的Homestead带有默认的homestead数据库,用户homestead可以使用密码secret访问该数据库,因此,如果您使用它,则可能无需执行任何操作。

建立 (Build)

As a final preparatory step, we need to run the (arguably difficult to remember) command:

作为最后的准备步骤,我们需要运行(可能很难记住)命令:

php bin/adminconsole sulu:build dev

This will prompt us to confirm the following:

这将提示我们确认以下内容:

Options:

  - nodeps: false
  - destroy: false
  - help: false
  - quiet: false
  - verbose: false
  - version: false
  - ansi: false
  - no-ansi: false
  - no-interaction: false
  - shell: false
  - process-isolation: false
  - env: 'dev'
  - no-debug: false

Before confirming, let’s quickly explain each of these flags that could be passed into the build command. These are, in fact, the flags of the Symfony Console component – the reason why they’re echoed our here like this is unclear.

在确认之前,让我们快速解释一下可以传递给build命令的每个标志。 实际上,这些是Symfony Console组件的标志–尚不清楚它们在此处与我们相呼应的原因。

A note about terminology: a build target is a “recipe” for an application. A set of instructions to be executed to get the app to its target. In the case of dev (which is a build target here, not an environment), this includes building assets, publishing routes, creating users, and much more. Another target, prod, does the exact same thing, but without generating default users (a security risk, hence prod for production). To see which targets are available, just run the plain bin/adminconsole sulu:build.

关于术语的注释: build target是应用程序的“配方”。 一组要执行的指令以使应用程序达到其目标。 对于dev (这里是构建目标,而不是环境)而言,这包括构建资产,发布路线,创建用户等。 另一个目标prod可以执行完全相同的操作,但是不会生成默认用户(存在安全风险,因此会prod产品)。 要查看可用的目标,只需运行普通的bin/adminconsole sulu:build

  1. nodeps: when building, dependencies of the targets will also be built by default. If you wish to prevent this, the --nodeps flag is used. A dependency could be another target, a specific fixture in a database, and so on.

    nodeps :构建时,默认情况下还将构建目标的依赖项。 如果希望防止这种情况,请使用--nodeps标志。 依赖关系可以是另一个目标,也可以是数据库中的特定固定装置,依此类推。

  2. destroy: destroys existing data in an application. Useful for a full restart, a factory reset of sorts.

    destroy :销毁应用程序中的现有数据。 对于完全重新启动很有用,它可以恢复出厂设置。

  3. help: if added to the command like so: bin/adminconsole sulu:build dev --help, explains what the build command does.

    help :如果像这样添加到命令中: bin/adminconsole sulu:build dev --help ,说明build命令的作用。

  4. quiet: produces no output from the build process whatsoever. If this flag is present, the next flag, verbose, has no effect.

    quiet :不会从生成过程中产生任何输出。 如果存在此标志,则下一个标志verbose无效。

  5. verbose: how much information the process outputs. Can have a value from 1 to 3, like so: --verbose=3.

    verbose :过程输出多少信息。 可以具有1到3之间的值,例如:-- --verbose=3

  6. version: displays the application’s version. If used, nullifies the sulu:build dev part of the command.

    version :显示应用程序的版本。 如果使用,则使命令的sulu:build dev部分无效。

  7. ansi: if set to true, decorates (colors and formats) the output messages with ANSI.

    ansi :如果设置为true,则使用ANSI 装饰 (颜色和格式)输出消息。

  8. no-ansi: disables ANSI decoration, helpful in cases like these

    no-ansi :禁用ANSI装饰,在此类情况下no-ansi

  9. no-interaction: will attempt to auto-confirm all choices at their default/assumed value instead of asking for input from the user.

    no-interaction :将尝试以其默认/假定值自动确认所有选择,而不是要求用户输入。

  10. shell: launches shell mode, which makes the console interactive, as in, lets you use it as you would, for example, use MySQL when logged into it. You can then execute all the Console commands without prefixing them with bin/adminconsole. Nullifies all other commands if used, shell takes precedence and sulu:build dev would have to be re-issued from inside the shell.

    shell :启动shell模式,使控制台具有交互性,就像在其中一样,使您可以像在登录时使用MySQL一样使用它。 然后,您可以执行所有控制台命令,而无需在它们前面加上bin/adminconsole 。 如果使用其他所有命令,则将其sulu:build dev ,shell优先,并且必须从shell内部重新发出sulu:build dev

  11. process-isolation: launches the commands about to be executed as separate processes

    process-isolation :启动将作为独立进程执行的命令

  12. env: the current environment’s name (dev by default). Changed with --env=prod.

    env :当前环境的名称(默认为dev )。 用--env=prod更改。

  13. no-debug: disables debug mode. In other words, it disables the collection of dev debug data like performance bottlenecks, logs, etc., which is useful if you want the performance of prod but don’t want to switch the environment from dev.

    no-debug :禁用调试模式。 换句话说,它禁用了诸如性能瓶颈,日志等之类的dev调试数据的收集,这在您需要prod的性能但又不想从dev切换环境时非常有用。

Confirm the command.

确认命令。

登录 (Log In)

To inspect the front end of the application, visit my_sulu_project.app/ in the browser. To log in as administrator, visit my_sulu_project.app/admin/ and log in with admin/admin.

要检查应用程序的前端,请在浏览器中访问my_sulu_project.app/ 。 要以管理员my_sulu_project.app/admin/登录,请访问my_sulu_project.app/admin/并使用admin / admin登录。

前端工作

Not much to look at but hey, it works!

没什么可看的,但是,嘿,行得通!

后端工作

The back end is much prettier. Feel free to play around in this UI – in the next post, we’ll get started with developing things in Sulu!

后端更漂亮。 随意在此UI中玩耍-在下一篇文章中,我们将开始在Sulu中开发东西!

陷阱和常见问题解答 (Pitfalls and FAQ)

There are several questions that might be rolling around in your head after this, as they were in mine, so let’s get to them. As you post others, we’ll make sure we update this list with answers from the Sulu team themselves.

在那之后,您可能会想起几个问题,因为它们是我的,所以让我们开始吧。 当您发布其他内容时,我们将确保使用来自Sulu团队本身的答案来更新此列表。

Sulu对新闻网站有用吗? (Is Sulu good for a news website?)

Not by default, which is admittedly odd given the fact that it’s an “enterprise CMS”. The default content setup is a tree structure, where each page can have sub-pages and so on. This doesn’t work well for a flat list of files. What does, though, is the SuluArticleBundle – an under-development bundle that lends itself perfectly to regular posting of articles.

并非默认情况下,考虑到它是“企业CMS”这一事实,这是很奇怪的。 默认的内容设置是结构,其中每个页面都可以有子页面,依此类推。 对于平面文件列表,这不太适用。 不过,它是SuluArticleBundle的一部分SuluArticleBundle是一个开发不足的软件包,非常适合常规的文章发布。

Keep this in mind when launching a high-publish-frequency site on Sulu.

在Sulu上发布高发布频率的网站时,请记住这一点。

Polyfills? (Polyfills?)

安装了不同的填料

You may have noticed that different polyfills of various past PHP versions get installed during the installation process. This slows the process down, and bloats the project. This is because they’re a dependency of Symfony/symfony, which is a dependency of Sulu. Symfony includes these because the minimum PHP requirement is version 5.5.9 (for now), and these polyfills need to be in place to support functionality that only newer versions of PHP have.

您可能已经注意到,在安装过程中会安装各种过去PHP版本的不同的polyfill。 这会减慢流程速度,并使项目肿。 这是因为它们是Symfony / symfony的依赖项,这是Sulu的依赖项。 Symfony之所以包含这些内容,是因为最低PHP要求是5.5.9版(目前),并且需要使用这些polyfill来支持只有较新版本PHP才具有的功能。

There’s a discussion under way about hacking these away during installation.

正在讨论有关在安装过程中破解这些漏洞的讨论

Sulu会跟随Symfony进入Symfony 4和Flex吗? (Will Sulu follow Symfony into Symfony 4 and Flex?)

Yes, the Sulu team is looking at the Flex project and following Symfony 4’s progress. It’s not clear what effect Flex and Symfony’s new setup will have on Sulu in time, and how long it’ll take to get them in sync – it all depends on the types and magnitude of changes the new version brings, but even right now you can test Sulu 1.6.0. RC1 which uses the newest Symfony 3.3. All you need to do is modify the create-project command slightly:

是的,Sulu团队正在研究Flex项目,并关注Symfony 4的进度。 目前尚不清楚Flex和Symfony的新设置会在时间上对Sulu产生什么影响,以及同步它们将花费多长时间–这完全取决于新版本带来的更改的类型和程度,但即使现在您也可以可以测试Sulu 1.6.0。 RC1使用最新的Symfony 3.3。 您需要做的就是稍微修改create-project命令:

composer create-project sulu/sulu-minimal=1.6.0-RC1 my_sulu_project

结论 (Conclusion)

Sulu has matured as a platform, and is becoming more and more DX-friendly by the day. My hope is that with tutorials like these I’ll bring the concepts closer to you and help you understand the power this Symfony-based CMS holds, and that it makes sense as a starting point for many of your projects, regardless of size.

Sulu已经成为一个成熟的平台,并且每天都对DX友好。 我的希望是,通过这些教程,我将使概念更接近您,并帮助您理解基于Symfony的CMS所具有的强大功能,并且对于许多项目,无论其大小如何,它都是一个起点。

If anything about this post hasn’t been properly explained, or you’ve run into any difficulties with setting things up, please don’t hesitate to leave a comment below and tell us about the issues.

如果关于此帖子的任何内容都没有得到正确的解释,或者在设置方面遇到任何困难,请随时在下面发表评论并告诉我们有关问题。

翻译自: https://www.sitepoint.com/getting-started-sulu-cms-vagrant-right-way/

vagrant入门

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值