How to set up a Symfony 4 Flex project with the latest PHP (PHP 7.4) on MacOS

Dominik Szymański
3 min readNov 11, 2019

--

If you want to set up a Symfony 4 project with the latest PHP 7.4 you found the right place to get started with!

0. Get the Homebrew package manager

It’s a must-have on every macOS developer machine. A package manager for Macs.

What is a package manager? It’s a tool to do all the hard tasks with simple commands.

tl;dr: It’s just like the apt on a Linux.

How to install the Homebrew package manager? Simply open the Terminal app and paste:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

And voila! You’re set to go!

1. Download the PHP from Homebrew

Check the latest available PHP formula in Homebrew Formulae (https://formulae.brew.sh/formula/php)

After checking the latest available PHP version in the Homebrew type the command below

brew install php

And check the installed PHP environment

php -v
PHP 7.3 ready to go!

2. Download Composer

The Composer tool is a must-have for every PHP project. The tool manages, updates and autoloads packages. All hassle-free.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \\
php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \\
php composer-setup.php \\
php -r "unlink('composer-setup.php');" \\
mv composer.phar /usr/local/bin/composer # To use the Composer tool globally
Composer installation process

And check the version using composer --version :)

3. Getting started with the Symfony CLI

Symfony has gone into a Laravel-like project set up process. From now it’s easy — like a piece of cake!

Download the Symfony CLI binary

curl -sS https://get.symfony.com/cli/installer | bash
Our binary is located in the current directory and ready to use

3. Set up a Symfony project

Let’s start with our project. Type symfony new PROJECT_NAME and our Symfony binary will create a brand new Symfony Flex project.

And our project is ready to go!

Note: Use symfony new --full PROJECT_NAME to get the most common Symfony packages out-of-the-box!

4. Serve our project

Our Symfony project is ready to develop. Let’s start the local server and check if it works.

Use symfony serve to start a local development server and head to the returned URL (default http://localhost:8000).

Voila! We’re ready to code!

5. Go code! :)

Our project is finally set up. For troubleshooting head to the official Symfony documentation. Cheers!

--

--