44Installing & Setting up the Symfony Framework
55=============================================
66
7- This article explains how to install Symfony in different ways and how to solve
8- the most common issues that may appear during the installation process.
7+ This article explains how to install Symfony and solve the most common issues
8+ that may appear during the installation process.
99
1010.. seealso ::
1111
1212 Do you prefer video tutorials? Check out the `Joyful Development with Symfony `_
1313 screencast series from KnpUniversity.
1414
15+ .. _installation-creating-the-app :
16+
1517Creating Symfony Applications
1618-----------------------------
1719
18- Symfony provides a dedicated application called the **Symfony Installer ** to ease
19- the creation of Symfony applications. This installer is a PHP 5.4 compatible
20- executable that needs to be installed on your system only once:
21-
22- .. code-block :: terminal
23-
24- # Linux and macOS systems
25- $ sudo mkdir -p /usr/local/bin
26- $ sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
27- $ sudo chmod a+x /usr/local/bin/symfony
28-
29- # Windows systems
30- c:\> php -r "file_put_contents('symfony', file_get_contents('https://symfony.com/installer'));"
31-
32- .. note ::
33-
34- In Linux and macOS, a global ``symfony `` command is created. In Windows,
35- move the ``symfony `` file to a directory that's included in the ``PATH ``
36- environment variable and create a ``symfony.bat `` file to create the global
37- command or move it to any other directory convenient for you:
38-
39- .. code-block :: terminal
40-
41- # for example, if WAMP is used ...
42- c:\> move symfony c:\wamp\bin\php
43- # create symfony.bat in the same folder
44- c:\> cd c:\wamp\bin\php
45- c:\> (echo @ECHO OFF & echo php "%~dp0symfony" %*) > symfony.bat
46- # ... then, execute the command as:
47- c:\> symfony
48-
49- # moving it to your projects folder ...
50- c:\> move symfony c:\projects
51- # ... then, execute the command as
52- c:\> cd projects
53- c:\projects\> php symfony
54-
55- .. _installation-creating-the-app :
56-
57- Once the Symfony Installer is installed, create your first Symfony application
58- with the ``new `` command:
20+ Symfony applications are created with `Composer `_, the package manager used by
21+ modern PHP applications. If you don't have Composer installed in your computer,
22+ start by :doc: `installing Composer globally </setup/composer >`. Then, execute
23+ this command to create a new empty Symfony application based on its latest
24+ stable version:
5925
6026.. code-block :: terminal
6127
62- $ symfony new my_project_name
63-
64- This command creates a new directory called ``my_project_name/ `` that contains
65- an empty project based on the most recent stable Symfony version available. In
66- addition, the installer checks if your system meets the technical requirements
67- to execute Symfony applications. If not, you'll see the list of changes needed
68- to meet those requirements.
69-
70- .. note ::
71-
72- If the installer doesn't work for you or doesn't output anything, make sure
73- that the PHP `Phar extension `_ is installed and enabled on your computer.
74-
75- .. note ::
76-
77- If the SSL certificates are not properly installed in your system, you
78- may get this error:
28+ $ composer create-project symfony/skeleton my-project
7929
80- cURL error 60: SSL certificate problem: unable to get local issuer certificate.
81-
82- You can solve this issue as follows:
83-
84- #. Download a file with the updated list of certificates from
85- https://curl.haxx.se/ca/cacert.pem
86- #. Move the downloaded ``cacert.pem `` file to some safe location in your system
87- #. Update your ``php.ini `` file and configure the path to that file:
88-
89- .. code-block :: ini
90-
91- ; Linux and macOS systems
92- curl.cainfo = " /path/to/cacert.pem"
93-
94- ; Windows systems
95- curl.cainfo = " C:\path\to\cacert.pem"
30+ .. tip ::
9631
97- Basing your Project on a Specific Symfony Version
98- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32+ If your Internet connection is slow, you may think that Composer is not
33+ doing anything. If that's your case, add the ``-vvv `` flag to the previous
34+ command to display a detailed output of everything that Composer is doing.
9935
100- In case your project needs to be based on a specific Symfony version, use the
101- optional second argument of the ``new `` command:
36+ If your project needs to be based on a specific Symfony version, use the
37+ optional third argument of the ``create-project `` command:
10238
10339.. code-block :: terminal
10440
10541 # use the most recent version in any Symfony branch
106- $ symfony new my_project_name 2.8
107- $ symfony new my_project_name 3.1
42+ $ composer create-project symfony/skeleton my-project "3.3.*"
10843
10944 # use a specific Symfony version
110- $ symfony new my_project_name 2.8.3
111- $ symfony new my_project_name 3.1.5
45+ $ composer create-project symfony/skeleton my-project "3.3.5"
11246
11347 # use a beta or RC version (useful for testing new Symfony versions)
114- $ symfony new my_project 2.7.0-BETA1
115- $ symfony new my_project 2.7.0-RC1
116-
117- # use the most recent 'lts' version (Long Term Support version)
118- $ symfony new my_project_name lts
119-
120- Each version has its *own * documentation, which you can select on any documentation
121- page.
48+ $ composer create-project symfony/skeleton my-project 3.3.0-BETA1
12249
12350 .. note ::
12451
12552 Read the :doc: `Symfony Release process </contributing/community/releases >`
12653 to better understand why there are several Symfony versions and which one
12754 to use for your projects.
12855
129- Creating Symfony Applications with Composer
130- -------------------------------------------
131-
132- If you still use PHP 5.3 or can't use the Symfony installer for any reason, you
133- can create Symfony applications with `Composer `_, the dependency manager used by
134- modern PHP applications.
135-
136- If you don't have Composer installed in your computer, start by
137- :doc: `installing Composer globally </setup/composer >`. Then, execute the
138- ``create-project `` command to create a new Symfony application based on its
139- latest stable version:
140-
141- .. code-block :: terminal
142-
143- $ composer create-project symfony/framework-standard-edition my_project_name
144-
145- You can also install any other Symfony version by passing a second argument to
146- the ``create-project `` command:
147-
148- .. code-block :: terminal
149-
150- $ composer create-project symfony/framework-standard-edition my_project_name "2.8.*"
151-
152- .. tip ::
153-
154- If your Internet connection is slow, you may think that Composer is not
155- doing anything. If that's your case, add the ``-vvv `` flag to the previous
156- command to display a detailed output of everything that Composer is doing.
157-
15856Running the Symfony Application
15957-------------------------------
16058
161- Symfony leverages the internal PHP web server (available since PHP 5.4) to run
162- applications while developing them. Therefore, running a Symfony application is
163- a matter of browsing to the project directory and executing this command :
59+ Symfony provides a utility called `` server `` that leverages the internal PHP web
60+ server to run applications while developing them. First, install that utility
61+ in your application :
16462
16563.. code-block :: terminal
16664
167- $ cd my_project_name /
168- $ php bin/console server:run
65+ $ cd my-project /
66+ $ composer require server
16967
170- Then, open your browser and access the ``http://localhost:8000/ `` URL to see the
171- Welcome Page of Symfony:
68+ Then, whenever you want to run the application, execute this command:
17269
173- .. image :: /_images/quick_tour/welcome.png
174- :align: center
175- :alt: Symfony Welcome Page
176- :class: with-browser
70+ .. code-block :: terminal
17771
178- If you see a blank page or an error page instead of the Welcome Page, there is
179- a directory permission misconfiguration. The solution to this problem is
180- explained in the :doc: `/setup/file_permissions `.
72+ $ php bin/console server:run
18173
182- When you are finished working on your Symfony application, stop the server by
183- pressing ``Ctrl+C `` from the terminal or command console.
74+ Open your browser, access the ``http://localhost:8000/ `` URL and you'll see the
75+ application running. When you are finished working on your Symfony application,
76+ stop the server by pressing ``Ctrl+C `` from the terminal or command console.
18477
18578.. tip ::
18679
18780 PHP's internal web server is great for developing, but should **not ** be
18881 used on production. Instead, use Apache or Nginx.
18982 See :doc: `/setup/web_server_configuration `.
19083
191- Checking Symfony Application Configuration and Setup
192- ----------------------------------------------------
84+ Checking Symfony Requirements
85+ -----------------------------
19386
194- The Symfony Installer checks if your system is ready to run Symfony applications.
195- However, the PHP configuration for the command console can be different from the
196- PHP web configuration. For that reason, Symfony provides a visual configuration
197- checker. Access the following URL to check your configuration and fix any issue
198- before moving on:
87+ In addition to PHP 7.1, Symfony has other `technical requirements `_ that your
88+ server must meet. Symfony provides a tool called "Requirements Checker" (or
89+ ``req-checker ``) to check those requirements:
19990
200- .. code-block :: text
91+ .. code-block :: terminal
92+
93+ $ cd my-project/
94+ $ composer require req-checker
20195
202- http://localhost:8000/config.php
96+ The ``req-checker `` utility adds two PHP scripts in your application:
97+ ``bin/check.php `` and ``public/check.php ``. Run the first one in the command
98+ console and the second one in the browser. This is needed because PHP can define
99+ a different configuration for both the command console and the web server, so
100+ you need to check both.
203101
204- Fixing Permissions Problems
205- ---------------------------
102+ Once you've fixed all the reported issues, uninstall the requirements checker:
206103
207- If you have any file permission errors or see a white screen, then read
208- :doc: `/setup/file_permissions ` for more information.
104+ .. code-block :: terminal
105+
106+ $ composer remove req-checker
209107
210108 .. _installation-updating-vendors :
211109
212110Updating Symfony Applications
213111-----------------------------
214112
215- At this point, you've created a fully-functional Symfony application! Every Symfony
216- app depends on a number of third-party libraries stored in the `` vendor/ `` directory
217- and managed by Composer.
113+ At this point, you've created a fully-functional Symfony application! Every
114+ Symfony app depends on a number of third-party libraries stored in the
115+ `` vendor/ `` directory and managed by Composer.
218116
219- Updating those libraries frequently is a good practice to prevent bugs and
117+ Updating those libraries frequently is a good practice to fix bugs and prevent
220118security vulnerabilities. Execute the ``update `` Composer command to update them
221119all at once (this can take up to several minutes to complete depending on the
222120complexity of your project):
@@ -226,68 +124,64 @@ complexity of your project):
226124 $ cd my_project_name/
227125 $ composer update
228126
229- .. tip ::
230-
231- Symfony provides a command to check whether your project's dependencies
232- contain any known security vulnerability:
127+ .. _install-existing-app :
233128
234- .. code-block :: terminal
129+ Installing an Existing Symfony Application
130+ ------------------------------------------
235131
236- $ php bin/console security:check
132+ When working collaboratively in a Symfony application, it's uncommon to create
133+ a new Symfony application as explained in the previous sections. Instead,
134+ someone else has already created and submitted it to a shared repository.
237135
238- A good security practice is to execute this command regularly to be able to
239- update or replace compromised dependencies as soon as possible.
136+ It's recommended to not submit some files (``.env ``) and directories (``vendor/ ``,
137+ cache, logs) to the repository, so you'll have to do the following when
138+ installing an existing Symfony application:
240139
241- .. _ installing-a-symfony2-distribution :
140+ .. code-block :: terminal
242141
243- Installing the Symfony Demo or Other Distributions
244- --------------------------------------------------
142+ # clone the project to download its contents
143+ $ cd projects/
144+ $ git clone ...
245145
246- You've already downloaded the ` Symfony Standard Edition `_: the default starting project
247- for all Symfony apps. You'll use this project throughout the documentation to build
248- your app!
146+ # make Composer install the project's dependencies into vendor/
147+ $ cd my- project/
148+ $ composer install
249149
250- Symfony also provides some other projects and starting skeletons that you can use:
150+ Checking for Security Vulnerabilities
151+ -------------------------------------
251152
252- `The Symfony Demo Application `_
253- This is a fully-functional application that shows the recommended way to develop
254- Symfony applications. The app has been conceived as a learning tool for Symfony
255- newcomers and its source code contains tons of comments and helpful notes.
153+ Symfony provides a utility called "Security Checker" (or ``sec-checker ``) to
154+ check whether your project's dependencies contain any known security
155+ vulnerability. Run this command to install it in your application:
256156
257- `The Symfony CMF Standard Edition `_
258- The `Symfony CMF `_ is a project that helps make it easier for developers to add
259- CMS functionality to their Symfony applications. This is a starting project
260- containing the Symfony CMF.
157+ .. code-block :: terminal
261158
262- `The Symfony REST Edition `_
263- Shows how to build an application that provides a RESTful API using the
264- `FOSRestBundle `_ and several other related Bundles.
159+ $ cd my-project/
160+ $ composer require sec-checker
265161
266- .. _install-existing-app :
162+ From now on, this command will be run automatically whenever you install or
163+ update any dependency in the application.
267164
268- Installing an Existing Symfony Application
269- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165+ Installing the Symfony Demo application
166+ ---------------------------------------
270167
271- When working collaboratively in a Symfony application, it's uncommon to create
272- a new Symfony application as explained in the previous sections. Instead,
273- someone else has already created and submitted it to a shared repository .
168+ ` The Symfony Demo Application `_ is a fully-functional application that shows the
169+ recommended way to develop Symfony applications. It's a great learning tool for
170+ Symfony newcomers and its code contains tons of comments and helpful notes .
274171
275- It's recommended to not submit some files (:ref: `parameters.yml <config-parameters-yml >`)
276- and directories (``vendor/ ``, cache, logs) to the repository, so you'll have to do
277- the following when installing an existing Symfony application:
172+ Run the following command to download and install the Symfony Demo application:
278173
279174.. code-block :: terminal
280175
281- # clone the project to download its contents
282- $ cd projects/
283- $ git clone ...
176+ $ composer create-project symfony/symfony-demo my-project
284177
285- # make Composer install the project's dependencies into vendor/
286- $ cd my_project_name/
287- $ composer install
178+ Now, enter the ``my-project/ `` directory, run the internal web server and
179+ browse ``http://127.0.0.1:8000 ``:
180+
181+ .. code-block :: terminal
288182
289- # now Composer will ask you for the values of any undefined parameter
290- $ ...
183+ $ cd my-project
184+ $ php bin/console server:start
291185
292186 Keep Going!
293187-----------
@@ -315,10 +209,5 @@ Go Deeper with Setup
315209
316210.. _`Joyful Development with Symfony` : http://knpuniversity.com/screencast/symfony
317211.. _`Composer` : https://getcomposer.org/
318- .. _`Phar extension` : http://php.net/manual/en/intro.phar.php
319- .. _`Symfony Standard Edition` : https://github.com/symfony/symfony-standard
212+ .. _`technical requirements` : https://symfony.com/doc/current/reference/requirements.html
320213.. _`The Symfony Demo application` : https://github.com/symfony/symfony-demo
321- .. _`The Symfony CMF Standard Edition` : https://github.com/symfony-cmf/standard-edition
322- .. _`Symfony CMF` : http://cmf.symfony.com/
323- .. _`The Symfony REST Edition` : https://github.com/gimler/symfony-rest-edition
324- .. _`FOSRestBundle` : https://github.com/FriendsOfSymfony/FOSRestBundle
0 commit comments