Frameworks are a powerful tool for quickly building web applications. Learning how to use frameworks will help you to build your projects better and faster. One of the most popular PHP frameworks is called Symfony, which is known to be the hardest to learn from all others PHP frameworks.
Before we start to talk about all the features that Symfony offers, let’s start with the answer to the question, what is Symfony?
Symfony is a set of PHP Components, a Web Application framework, a Philosophy, and a Community — all working together in harmony.
Which means that you can use Symfony components on a project that is not Symfony-based. One of the examples is the Laravel framework, which is based on Symfony components such as Finder, HttpKernel, Process, Routing, Console etc.
To start with your first Symfony 4 project, make sure you already have Composer installed on your system. To check if you already have it, open your terminal and type
if you get something like:
Composer version 1.7.3 2018-11-01 10:05:06
inside your terminal, then you have Composer installed and you are ready, if not, you will have to install Composer first. There are two ways to start Symfony 4 project. If you are building traditional web application, open your terminal and run
composer create-project symfony/website-skeleton name_your_project
or if you are building a microservice, console applicaton or API
composer create-project symfony/skeleton name_your_project
Once you run one of these two commands, composer will clone the symfony project and then runs composer install to download it’s dependencies. Once it’s finished, at the bottom of terminal, you will get clear instructions what to do next.
* Run your application:
1. Change to the project directory
2. Create your code repository with the git init command
3. Run composer require server --dev to install the development web server,
or configure another supported web server https://symfony.com/doc/current/setup/web_server_configuration.html
* Read the documentation at https://symfony.com/doc
* Modify your DATABASE_URL config in .env
* Configure the driver (mysql) and
server_version (5.7) in config/packages/doctrine.yaml
How to test?
* Write test cases in the tests/ folder
* Run php bin/phpunit
Move into the new directory:
You can run our app immediately by executing:
php -S 127.0.0.1:8000 -t public
Now open your browser and look at 127.0.0.1:8000
Congrats! You just started your first Symfony 4 project. Each time you start a new project, Symfony will provide you with a perfect .gitignore file. No need to worry about that. Just run:
git add .
and you are all set!