This site looks a lot better with CSS turned on. Note: IE<10 is not supported.

an article is displayed.

Symfony 4: setting up a new project

How to set up a Symfony 4 project

Introduction

I've written a couple of articles that required new Symfony projects, and so to save repeating myself I've moved the instructions for the setup process into this standalone article.

This article has been updated (29th April 2020): now Symfony 5 has been released, it's necessary to specify version 4 when installing using Composer

Goals

By the end of this article, you should be able to:

  • set up a skeleton Symfony 4 project

Prerequisites

  • OSX Mojave
  • A local installation of the Composer dependency manager

OSX Mojave isn't an essential requirement, but that's what I've used to test everything.

Create a Symfony 4 skeleton project

Navigate to a location where you'd like to create a new project, and run the following command. NOTE: this command will create a new directory wherever you run it. I'm using the name symfony_4_test_project here, but choose something else if you prefer.

composer create-project symfony/website-skeleton hackerbox_symfony_4_test_project ^4.4.0

When the setup has finished, navigate to the new hackerbox_symfony_4_test_project directory

Start the Symfony project

Now let's check whether the project will run properly.

Ensure you're in the project root, and run the following command:

php bin/console server:run

If you see an error stating that Command "server:run" is not defined, then you might need to install the web server bundle as a development dependency:

composer require symfony/web-server-bundle --dev

Point a web browser at http://localhost:8000, and verify that Symfony is running

The Symfony 4 splash screen

If your PHP development server throws any errors when you start adding your own files and templates, simply restart it.

Summary

You should now have the foundations of a functional Symfony 4 project, all ready to modify for your own purposes.

As always, do your own research around this topic, and if you found my article useful then please share it around.

If you liked that article, then why not try:

Symfony 4: using ParcelJs with Twig templates

Following on from my recent explorations in the world of PHP and Symfony 4, I decided that I'd have a look into front-end asset bundling. Although Symfony 4 has really great support for Webpack via the Webpack Encore API, my requirements were very simple this time around and so it was time to give ParcelJs a shot.