daniel
Daniel Rotter
Core Developer – Sulu GmbH
Core developer and support guru. Passionate traveler and soccer player.
@danrot90
2020-03-31

Adding Sulu CMS to an existing Symfony project

With Sulu CMS you can create super-fast applications in Symfony that have a adaptable and easy to use content management UI for your editors. Users will be happy because the UI is flexible and intuitive and Symfony developers will be happy because Sulu CMS works like they expect it to work.

If you’re starting from scratch with a new project, we built the Skeleton to help you get started with new projects quickly. You can clone the Sulu Skeleton repository and make it your own.

So it’s understandable one of the most common questions is: what if you want to add Sulu CMS to an existing application? In fact, what you do is the reverse: add your application to the Sulu Skeleton. Let us first explain how, and then we’ll explain why you’d do it this way.

How to integrate your existing Symfony application with Sulu CMS

The first thing you’ll need to know is you’ll be starting with the Sulu Skeleton and adding your application.

  1. Create a new sulu project using our Getting started Guide and omit the Git initialization
  2. Move the `.git` folder of your old project to the new sulu project (cp -r <your-old-project>/.git <your-new-sulu-project>/.git)
  3. Add your project files one by one into the new Sulu directory structure
  4. Commit the changes once everything is working (git will retain your history of your project files)

The most important thing you need to remember is: don’t create a new repository, but continue to work in the existing one. Git will do a fabulous job of retaining your project history.

Any potential issues to consider?

In theory, if you have multiple kernels in your application, this wouldn’t work. However, we haven’t come across it, because it’s pretty rare.

Another potential issue is that if you have your own skeleton, then you wouldn’t be able to do it this way. For example, with an application like Sylius, both systems try to take the leading role in the application. So you have to either integrate Sulu and Sylius as separate applications or put more effort into combining them as a single application.  

If you have any questions, contact us in Slack. We also offer training and consulting if you want some more hands-on help.

What is the Sulu Skeleton?

So you might be wondering why you’d need to add your application to Sulu CMS, rather than the other way around. First, we should explain why the Skeleton exists.

Back in the day, we decided to use a setup with multiple kernels. It seemed like the right thing to do, because it allowed us to register certain bundles — including their services and configuration — only for the website or only for the administration interface. Having many services was a bigger issue in the past, because all of them were compiled into a single file that needed to be loaded. The more services you had, the bigger the resulting file was, and this file had to be loaded on every request. Since these services are now split among multiple files, this is not such a big issue anymore.

Another drawback of having a single kernel was that the Symfony firewall always started a HTTP session. That included the website, which would also have caused a performance impact and made caching the website harder. But Symfony has also solved this problem since then.

However, we still rely on having two kernels in some parts of our code, but Symfony 4 introduced Symfony Flex, a kind of package manager for Symfony which “enables distribution composition instead of inheritance,” as Fabien Potencier wrote in a Symfony 4 demo in 2017. This allows you to make use of Symfony Recipes to integrate third-party packages into Symfony applications. Symfony Flex will take care of the boring tasks like registering the bundle in the correct file and adding some basic configuration required by the bundle to work. These tedious tasks had to be done manually previously.

But Symfony Flex only supports a single-kernel setup, so we cannot use the Symfony Skeleton. Therefore we have created our own Sulu Skeleton to open up the world of Symfony recipes.

Now, if you start with the Sulu skeleton, you can use Symfony recipes, and cook up something awesome.

Speaking of recipes, check out this case study of a cool cooking website built in Sulu CMS: Küchengötter (“Gods Of The Kitchen”). OK — enough of the cooking metaphors!

Tell us how you’re using Sulu CMS

We love hearing how people are using Sulu CMS with their Symfony applications.

Ping us on Slack, and show us what you’re working on, or tell us on Twitter @Sulu.