Alexander-Schranz
Alexander Schranz
Core Developer – Sulu GmbH
Core developer and support king. So dedicated to his work that we couldn't find a hobby to mention.
@alex_s_

How the Sulu Dev Team Sets Up a New Project

In our guide to getting started with Sulu we explained the first steps to beginning a Sulu project. If you’re a Symfony developer already familiar with Composer, you'll know how easy it is to get started with Sulu. When you’re ready to take it to the next level and optimize your dev setup, we’ve put together some of the best practices and suggested tools that we on the Sulu dev team employ every time we begin a new Sulu CMS project.

Gather your initial requirements

To hit the ground running on your Sulu Project, we recommend installing the following before you begin: 

Use Composer to install dependencies

To install Composer for dependency management, you can either use the command line or download a package from their website, which contains more detailed installation instructions. 

Tip: For macOS users, we especially recommend installing PHP and Composer locally — Symfony frequently accesses the File System, which can cause performance issues when you run PHP inside of a Docker container. 

When you need to confirm system requirements, all of the Sulu CMS’s can be found in the requirements section of the composer.json file of the sulu/sulu package. At the moment, Sulu CMS is compatible with every Symfony version, starting from 4.4, and requires a PHP version of 7.2 or higher, which you can install from the command line with Homebrew

Tip: Homebrew makes it possible to install and use multiple PHP versions:

brew install php@8.1

brew install php@8.2

Run a MySQL database instance with Docker

Every Sulu project requires a running database, and we test each new version of Sulu using both MySQL and PostgreSQL databases. If you’re unsure what kind of database is right for your project, we recommend MySQL. It’s one of the most common databases available and performs fairly well.

Docker is a great tool for setting up your development database — no need for time-consuming configuration and setup of a MySQL instance on your local machine.

To run your development database:

  1. Install Docker
  2. Install Docker Compose
  3. Configure your MySQL database in a docker-compose yml file
  4. Start the services with the command: docker-compose up

An example of how to configure your MySQL database through the docker-compose file can be found on our Sulu Skeleton’s GitHub page, and below:

version: '3'
services:
  database:
    image: mysql/mysql-server:8.0
    environment:
      MYSQL_DATABASE: ${MYSQL_DATABASE:-su_myapp}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-ChangeMe}
      MYSQL_ROOT_HOST: '%'
    volumes:
      - db-data:/var/lib/mysql

Spin up a local web server using the Symfony CLI

While PHP comes with a built-in web server, we prefer using the Symfony CLI for local development. The Symfony CLI comes in handy if you want a feature-rich local web server, but you’re not ready to set up a production web-server like Apache or Nginx. Some of the useful, additional features you get include: 

  • Support for HTTPS, which allows you to ensure your libraries run on the secure version of a website.
  • The ability to define local domain names, so you can have stable endpoints and check the functionality of your domains:subdomain structure.

Install the Symfony CLI by following the instructions on their website. Once you’re ready to preview your project locally, spin up the web server with the command:

symfony server:start --daemon

This should log the URL address that your web server is listening in on. You can visit by entering the address into your browser, or typing the command:

symfony open:local

To stop the server you can run:

symfony server:stop

Tip: If you want to use a specific PHP version for your project, you can create a .php-version file within your project's root directory to tell the Symfony CLI which PHP version should be used:

echo 8.1 > .php-version

Hit the ground running with Sulu today

Now that you’re set-up, you’re ready to create your project. As a Symfony developer, the directory and file structure should be familiar to you, so create your project with the Composer command 

composer create-project sulu/skeleton {directory name} -n 

and make your first project commit with Git. Be confident — you’re now set up like the Sulu dev team!