Symfony Framework
A leading PHP framework for creating websites and web applications, built on top of Symfony components</ p>
Symfony component
A set of decoupled and reusable components to build the best PHP applications, such as MySQL, Prestashop, and Laravel</ p>
Symfony Community
A passionate team of over 600000 developers from over 120 countries, all dedicated to helping PHP surpass the impossible</ p>
One major advantage of using frameworks is that the amount of code required to develop such projects is minimal
- 20 PHP classes src/for websites</ li>
- 550 lines of PHP logic code (LLOC) reported by PHNLOC</ li>
- 40 lines of configuration adjustments in 3 files (through properties and YAML), mainly used to configure backend design</ li>
- 20 lines Development infrastructure configuration (Docker)</ li>
- 100 lines of production infrastructure configuration (Platform. sh)</ li>
- 5 explicit environment variables</ li>
Install and set up Symfony framework
Technical Requirements
Install PHP 8.0.2 or higher and these PHP extensions (installed and enabled by default in most PHP 8 installations): Ctype, iconv, PCRE, Session, SimpleXML, and Tokenizer</ p>
Install Composer for installing PHP packages</ p>
Alternatively, you can install Symfony CLI. This will create a binary file called symfony, which provides all the tools needed to develop and run Symfony applications locally</ p>
The symfony binary file also provides a tool to check if your computer meets all requirements. Open your console terminal and run the following command:
symfony check:requirements
Create Symfony application
Open your console terminal and run these commands to create a new Symfony application:
symfony new my_project_directory --webapp
symfony new my_project_directory
The only difference between these two commands is the default number of software packages installed. The webapp option will install all the packages you typically need to build a web application, so the installation size will be larger</ p>
If you are not using Symfony binary files, run the following command to create a new Symfony application using Composer:
composer create-project symfony/skeleton my_project_directory
cd my_project_directory
composer require webapp
composer create-project symfony/skeleton my_project_directory
No matter which command you run to create a Symfony application. They will all create a new mysproject-directory/directory, download some dependencies into it, and even generate the basic directory and files you need to start with</ p>
Create an existing Symfony project
In addition to creating new Symfony projects, you will also handle projects already created by other developers. In this case, you only need to obtain the project code and install the dependencies using Composer. Assuming your team is using Git, please use the following command to set up your project:
cd projects/
git clone ...</ span>
cd my-project/
composer install
You may also need to customize your. env file and perform some other project specific tasks (such as creating a database). When using an existing Symfony application for the first time, running this command to display project information may be useful:
php bin/console about
Run Symfony application
In a production environment, you should install a web server like Nginx or Apache and configure it to run Symfony. If you are not using Symfony’s local web server for development, you can also use this method</ p>
However, for local development, the most convenient way to run Symfony is to use a local web server provided by binary files. Symfony provides support for HTTP/2, concurrent requests, TLS/SSL, and automatic generation of security certificates on this local server</ p>
Open your console terminal, enter your new project directory, and start the local web server as follows:
cd my-project/
symfony server:start
Open a browser and navigate to http://localhost:8000/ If everything is normal, you will see a welcome page. Ctrl+C later, when you finish your work, stop the server by pressing from the terminal</ p>
Configuration file
Symfony applications use files stored in the config/directory for configuration, which has the following default structure:
your-project/
├─ config/
│ ├─ packages/
│ ├─ bundles.php
│ ├─ routes.yaml
│ └─ services.yaml
├─ ...</ code>
The routes. YAML file defines the routing configuration; The Services.YAML file is used to configure the services of the service container; The bundles. php file enables/disables packages in the application</ p>
You will mainly work in the config/packages/directory. This directory stores the configuration of each package installed in the application. Packages (also known as “bundles” in Symfony and “plugins/modules” in other projects) add ready-made functionality to your project</ p>
When using Symfony Flex enabled by default in Symfony applications, the package will automatically update the bundles. php file and create a new file during installation. Config/packages/For example, this is the default file created for the “API Platform” package:
# config/packages/api_platform.yaml
api_platform:
mapping:
paths: ['%kernel.project_dir%/src/Entity']
Splitting the configuration into many small files can be daunting for some Symfony beginners. However, you will quickly get used to them and rarely need to change these files after installing the package</ p>
Symfony Deployment Fundamentals
The typical steps taken when deploying Symfony applications include:
- Upload your code to the production server</ li>
- Install your vendor dependencies (usually done through Composer, may be done before uploading)</ li>
Run database migration or similar tasks to update any changed data structures</ li>
Clear (optionally, preheat) your cache</ li>
Deployment may also include other tasks, such as:
- Mark a specific version of the code as a release in the source code control repository</ li>
- Create a temporary staging area to “offline” build updated settings</ li>
- Run any available tests to ensure code and/or server stability</ li>
Remove any unnecessary files from the directory to keep the production environment clean</ li>
Clear external cache systems (such as Memcached or Redis)</ li>
—END—
Open source license: MIT License