Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

Say hello to redesigned Cloudways, an empowering Startup Program, enhanced Staging, a new Let’s Encrypt Wildcard SSL certificate feature, and more. GET STARTED

Using Symfony Flex On Cloudways for Symfony Application Management

Updated on  26th September

5 Min Read
Reading Time: 5 minutes

PHP has maintained its lead by introducing new features that try to keep up with the emerging trends in the dev world. In particular, frameworks such as Symfony ensures that developers have access to newest and latest tools for RAD (Rapid Application Development).

using symfony for RAD

This is why many managed PHP MySQL hosting solution providers including Cloudways have made PHP 7.1 available on their platforms. Since Cloudways supports Symfony 3.3, I decided to try out the Symfony Flex, the latest (proposed) way of managing Symfony applications. As per Symfony docs:

Flex is not a new Symfony version, but a tool that replaces and improves the Symfony Installer. Symfony Flex automates the most common tasks of Symfony applications, such as installing and removing bundles and other dependencies. Symfony Flex works for Symfony 3.3 and newer versions.

Internally, Symfony Flex is a Composer plugin that modifies the behavior of the require and update commands. When installing or updating dependencies in a Flex-enabled application, Symfony can perform tasks before and after the execution of Composer tasks.

In this initial overview of Symfony Flex, I will demonstrate the installation of Symfony Flex and management of a Symfony application on Cloudways managed PHP hosting solution. For the purpose of this article, I am assuming that you have already signed up at Cloudways and have already launched a PHP app. You can follow the following GIF for more information:

Install Symfony Flex

Symfony already provides a skeleton project that is ideal for installing a new Symfony Flex enabled application. This is a single composer.json file which automatically run composer install command. During the execution of the command, Symfony/flex is the first package that is installed. After that, Flex hooks into Composer processes. Fabien explained the workflow of Flex as:

When Composer installs (or updates) other dependencies, Symfony Flex looks for an associated recipe on the Symfony Flex server, and executes it

Now to install Flex enabled Symfony app on Cloudways, open SSH Terminal and go to your application folder using the cd command and run the following command:

This command will install the skeleton project consist symfony of 3.3.

install project

Notice that some commands (such as cache and symlink) are running automatically near the end of the process. This is because of a MAKEFILE which automates the process to some degree.

You might also like: Why Choose Symfony For Your Next Project?

The Directory Structure

Symfony 4.0 will have a new and better simplified directory structure which will let the developers compose applications structure. Symfony Flex is also based on this directory structure. Here is how this amazingly simple structure looks like:

directory structure

Notice the config folder which has bundles.php. Flex will register all the bundles automatically after installation. The public folder offers access to the application through the index.php file, while the src folder contains the controllers and Entities.

An API Project Using Symfony Flex

So far I have installed Flex and discussed the new Symfony 4. directory structure. As you know Fabien created an API project to demonstrate the power of Flex. I will now attempt to replicate the project on Cloudways. The good thing is that Flex knows about the aliases to install the respective Symfony bundles. It automatically locate the recipes, even if a bundle does not contain a recipe symfony detects Composer packages with the symfony-bundle type and automatically enables them for all environments.

You might also like: How To Create Simple REST API In Symfony 3.1

Let’s install the API project using the following command:

api in symfony flex

The bundle is successfully installed and doesn’t need any further configurations (Symfony will take care of it all). At this time,if you see the directory structure, you will notice that several folders ( bin, templates, translations and var) have been added. I will use bin/console for working with console commands. You can also install symfony console separately with composer req cli command.

Configure Database Credentials in .env File

Next, I will add database credentials to .env file (located in the root of the project). This file is globally available throughout the project and you can add further environment variables to it.

Note: DB credentials are available at the Application Access Details page.

The following is the addition to the .env file:

Create A Doctrine Entity  

I will now create a Doctrine entity hello.php (placed in src/Entity folder). Add the following basic code to the file:

Symfony will use the namespace App for requiring the source files. As you could see, I’ve simply added the name and ID to the class. Now run the update schema command to generate the table.

database schema

Remember that at this point, you don’t need to install an internal web server as Cloudways takes care of it. However, if you are working on a local machine, you can install the web server through the composer req server. Additionally, I will update the webroot of the application and add api/public to it.

Now in the Access Details Tab, click the application URL.

access detail

You should see your API application in action. In my case the URL is:

api platform

Wrapping it up!

As you could see from the above sample project, Symfony Flex has removed much of the complexity of Symfony application management. I strongly recommend that php developers should try it out for themselves so that they could understand how this great tool works for their applications. If you need help in trying out Symfony Flex, do leave a comment.

Share your opinion in the comment section. COMMENT NOW

Shahroze Nawaz

Shahroze is a PHP Community Manager at Cloudways - A Managed PHP Hosting Platform. He’s always in search of new frameworks and methods to implement them. Besides his coding life, he loves movies and playing soccer with friends. You can email him at

Create PHP websites without the worry of server management.

Deploy your PHP app on optimized PHP hosting servers.

Get Our Newsletter
Be the first to get the latest updates and tutorials.