4
4
Installing & Setting up the Symfony Framework
5
5
=============================================
6
6
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.
9
9
10
10
.. seealso ::
11
11
12
12
Do you prefer video tutorials? Check out the `Joyful Development with Symfony `_
13
13
screencast series from KnpUniversity.
14
14
15
+ .. _installation-creating-the-app :
16
+
15
17
Creating Symfony Applications
16
18
-----------------------------
17
19
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 "readfile('https://symfony.com/installer');" > symfony
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 to create the global command or move it to any other
37
- 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
- # ... then, execute the command as:
44
- c:\> symfony
45
-
46
- # moving it to your projects folder ...
47
- c:\> move symfony c:\projects
48
- # ... then, execute the command as
49
- c:\> cd projects
50
- c:\projects\> php symfony
51
-
52
- .. _installation-creating-the-app :
53
-
54
- Once the Symfony Installer is installed, create your first Symfony application
55
- 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:
56
25
57
26
.. code-block :: terminal
58
27
59
- $ symfony new my_project_name
60
-
61
- This command creates a new directory called ``my_project_name/ `` that contains
62
- an empty project based on the most recent stable Symfony version available. In
63
- addition, the installer checks if your system meets the technical requirements
64
- to execute Symfony applications. If not, you'll see the list of changes needed
65
- to meet those requirements.
66
-
67
- .. note ::
68
-
69
- If the installer doesn't work for you or doesn't output anything, make sure
70
- that the PHP `Phar extension `_ is installed and enabled on your computer.
71
-
72
- .. note ::
73
-
74
- If the SSL certificates are not properly installed in your system, you
75
- may get this error:
28
+ $ composer create-project symfony/skeleton my-project
76
29
77
- cURL error 60: SSL certificate problem: unable to get local issuer certificate.
78
-
79
- You can solve this issue as follows:
80
-
81
- #. Download a file with the updated list of certificates from
82
- https://curl.haxx.se/ca/cacert.pem
83
- #. Move the downloaded ``cacert.pem `` file to some safe location in your system
84
- #. Update your ``php.ini `` file and configure the path to that file:
85
-
86
- .. code-block :: ini
87
-
88
- ; Linux and macOS systems
89
- curl.cainfo = " /path/to/cacert.pem"
90
-
91
- ; Windows systems
92
- curl.cainfo = " C:\path\to\cacert.pem"
30
+ .. tip ::
93
31
94
- Basing your Project on a Specific Symfony Version
95
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
96
35
97
- In case your project needs to be based on a specific Symfony version, use the
98
- 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:
99
38
100
39
.. code-block :: terminal
101
40
102
41
# use the most recent version in any Symfony branch
103
- $ symfony new my_project_name 2.8
104
- $ symfony new my_project_name 3.1
42
+ $ composer create-project symfony/skeleton my-project "3.3.*"
105
43
106
44
# use a specific Symfony version
107
- $ symfony new my_project_name 2.8.3
108
- $ symfony new my_project_name 3.1.5
45
+ $ composer create-project symfony/skeleton my-project "3.3.5"
109
46
110
47
# use a beta or RC version (useful for testing new Symfony versions)
111
- $ symfony new my_project 2.7.0-BETA1
112
- $ symfony new my_project 2.7.0-RC1
113
-
114
- # use the most recent 'lts' version (Long Term Support version)
115
- $ symfony new my_project_name lts
116
-
117
- Each version has its *own * documentation, which you can select on any documentation
118
- page.
48
+ $ composer create-project symfony/skeleton my-project 3.3.0-BETA1
119
49
120
50
.. note ::
121
51
122
52
Read the :doc: `Symfony Release process </contributing/community/releases >`
123
53
to better understand why there are several Symfony versions and which one
124
54
to use for your projects.
125
55
126
- Creating Symfony Applications with Composer
127
- -------------------------------------------
128
-
129
- If you still use PHP 5.3 or can't use the Symfony installer for any reason, you
130
- can create Symfony applications with `Composer `_, the dependency manager used by
131
- modern PHP applications.
132
-
133
- If you don't have Composer installed in your computer, start by
134
- :doc: `installing Composer globally </setup/composer >`. Then, execute the
135
- ``create-project `` command to create a new Symfony application based on its
136
- latest stable version:
137
-
138
- .. code-block :: terminal
139
-
140
- $ composer create-project symfony/framework-standard-edition my_project_name
141
-
142
- You can also install any other Symfony version by passing a second argument to
143
- the ``create-project `` command:
144
-
145
- .. code-block :: terminal
146
-
147
- $ composer create-project symfony/framework-standard-edition my_project_name "2.8.*"
148
-
149
- .. tip ::
150
-
151
- If your Internet connection is slow, you may think that Composer is not
152
- doing anything. If that's your case, add the ``-vvv `` flag to the previous
153
- command to display a detailed output of everything that Composer is doing.
154
-
155
56
Running the Symfony Application
156
57
-------------------------------
157
58
158
- Symfony leverages the internal PHP web server (available since PHP 5.4) to run
159
- applications while developing them. Therefore, running a Symfony application is
160
- 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 :
161
62
162
63
.. code-block :: terminal
163
64
164
- $ cd my_project_name /
165
- $ php bin/console server:run
65
+ $ cd my-project /
66
+ $ composer require server
166
67
167
- Then, open your browser and access the ``http://localhost:8000/ `` URL to see the
168
- Welcome Page of Symfony:
68
+ Then, whenever you want to run the application, execute this command:
169
69
170
- .. image :: /_images/quick_tour/welcome.png
171
- :align: center
172
- :alt: Symfony Welcome Page
173
- :class: with-browser
70
+ .. code-block :: terminal
174
71
175
- If you see a blank page or an error page instead of the Welcome Page, there is
176
- a directory permission misconfiguration. The solution to this problem is
177
- explained in the :doc: `/setup/file_permissions `.
72
+ $ php bin/console server:run
178
73
179
- When you are finished working on your Symfony application, stop the server by
180
- 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.
181
77
182
78
.. tip ::
183
79
184
80
PHP's internal web server is great for developing, but should **not ** be
185
81
used on production. Instead, use Apache or Nginx.
186
82
See :doc: `/setup/web_server_configuration `.
187
83
188
- Checking Symfony Application Configuration and Setup
189
- ----------------------------------------------------
84
+ Checking Symfony Requirements
85
+ -----------------------------
190
86
191
- The Symfony Installer checks if your system is ready to run Symfony applications.
192
- However, the PHP configuration for the command console can be different from the
193
- PHP web configuration. For that reason, Symfony provides a visual configuration
194
- checker. Access the following URL to check your configuration and fix any issue
195
- 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:
196
90
197
- .. code-block :: text
91
+ .. code-block :: terminal
92
+
93
+ $ cd my-project/
94
+ $ composer require req-checker
198
95
199
- 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.
200
101
201
- Fixing Permissions Problems
202
- ---------------------------
102
+ Once you fix all the reported issues, uninstall the requirements checker:
203
103
204
- If you have any file permission errors or see a white screen, then read
205
- :doc: `/setup/file_permissions ` for more information.
104
+ .. code-block :: terminal
105
+
106
+ $ composer remove req-checker
206
107
207
108
.. _installation-updating-vendors :
208
109
209
110
Updating Symfony Applications
210
111
-----------------------------
211
112
212
- At this point, you've created a fully-functional Symfony application! Every Symfony
213
- app depends on a number of third-party libraries stored in the `` vendor/ `` directory
214
- 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.
215
116
216
- 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
217
118
security vulnerabilities. Execute the ``update `` Composer command to update them
218
119
all at once (this can take up to several minutes to complete depending on the
219
120
complexity of your project):
@@ -223,68 +124,64 @@ complexity of your project):
223
124
$ cd my_project_name/
224
125
$ composer update
225
126
226
- .. tip ::
227
-
228
- Symfony provides a command to check whether your project's dependencies
229
- contain any known security vulnerability:
127
+ .. _install-existing-app :
230
128
231
- .. code-block :: terminal
129
+ Installing an Existing Symfony Application
130
+ ------------------------------------------
232
131
233
- $ 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.
234
135
235
- A good security practice is to execute this command regularly to be able to
236
- 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:
237
139
238
- .. _ installing-a-symfony2-distribution :
140
+ .. code-block :: terminal
239
141
240
- Installing the Symfony Demo or Other Distributions
241
- --------------------------------------------------
142
+ # clone the project to download its contents
143
+ $ cd projects/
144
+ $ git clone ...
242
145
243
- You've already downloaded the ` Symfony Standard Edition `_: the default starting project
244
- for all Symfony apps. You'll use this project throughout the documentation to build
245
- your app!
146
+ # make Composer install the project's dependencies into vendor/
147
+ $ cd my- project/
148
+ $ composer install
246
149
247
- Symfony also provides some other projects and starting skeletons that you can use:
150
+ Checking for Security Vulnerabilities
151
+ -------------------------------------
248
152
249
- `The Symfony Demo Application `_
250
- This is a fully-functional application that shows the recommended way to develop
251
- Symfony applications. The app has been conceived as a learning tool for Symfony
252
- 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:
253
156
254
- `The Symfony CMF Standard Edition `_
255
- The `Symfony CMF `_ is a project that helps make it easier for developers to add
256
- CMS functionality to their Symfony applications. This is a starting project
257
- containing the Symfony CMF.
157
+ .. code-block :: terminal
258
158
259
- `The Symfony REST Edition `_
260
- Shows how to build an application that provides a RESTful API using the
261
- `FOSRestBundle `_ and several other related Bundles.
159
+ $ cd my-project/
160
+ $ composer require sec-checker
262
161
263
- .. _install-existing-app :
162
+ From now on, this command will be run automatically whenever you install or
163
+ update any dependency in the application.
264
164
265
- Installing an Existing Symfony Application
266
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165
+ Installing the Symfony Demo application
166
+ ---------------------------------------
267
167
268
- When working collaboratively in a Symfony application, it's uncommon to create
269
- a new Symfony application as explained in the previous sections. Instead,
270
- 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 .
271
171
272
- It's recommended to not submit some files (:ref: `parameters.yml <config-parameters-yml >`)
273
- and directories (``vendor/ ``, cache, logs) to the repository, so you'll have to do
274
- the following when installing an existing Symfony application:
172
+ Run the following command to download and install the Symfony Demo application:
275
173
276
174
.. code-block :: terminal
277
175
278
- # clone the project to download its contents
279
- $ cd projects/
280
- $ git clone ...
176
+ $ composer create-project symfony/symfony-demo my-project
281
177
282
- # make Composer install the project's dependencies into vendor/
283
- $ cd my_project_name/
284
- $ 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
285
182
286
- # now Composer will ask you for the values of any undefined parameter
287
- $ ...
183
+ $ cd my-project
184
+ $ php bin/console server:start
288
185
289
186
Keep Going!
290
187
-----------
@@ -312,10 +209,5 @@ Go Deeper with Setup
312
209
313
210
.. _`Joyful Development with Symfony` : http://knpuniversity.com/screencast/symfony
314
211
.. _`Composer` : https://getcomposer.org/
315
- .. _`Phar extension` : http://php.net/manual/en/intro.phar.php
316
- .. _`Symfony Standard Edition` : https://github.com/symfony/symfony-standard
212
+ .. _`technical requirements` : https://symfony.com/doc/current/reference/requirements.html
317
213
.. _`The Symfony Demo application` : https://github.com/symfony/symfony-demo
318
- .. _`The Symfony CMF Standard Edition` : https://github.com/symfony-cmf/standard-edition
319
- .. _`Symfony CMF` : http://cmf.symfony.com/
320
- .. _`The Symfony REST Edition` : https://github.com/gimler/symfony-rest-edition
321
- .. _`FOSRestBundle` : https://github.com/FriendsOfSymfony/FOSRestBundle
0 commit comments