@@ -8,13 +8,8 @@ The preferred way to develop your Symfony application is to use
8
8
:doc: `Symfony Local Web Server </setup/symfony_server >`.
9
9
10
10
However, when running the application in the production environment, you'll need
11
- to use a fully-featured web server. This article describes several ways to use
12
- Symfony with Apache or Nginx.
13
-
14
- When using Apache, you can configure PHP as an
15
- :ref: `Apache module <web-server-apache-mod-php >` or with FastCGI using
16
- :ref: `PHP FPM <web-server-apache-fpm >`. FastCGI also is the preferred way
17
- to use PHP :ref: `with Nginx <web-server-nginx >`.
11
+ to use a fully-featured web server. This article describes how to use Symfony
12
+ with Apache or Nginx.
18
13
19
14
.. sidebar :: The public directory
20
15
@@ -30,147 +25,6 @@ to use PHP :ref:`with Nginx <web-server-nginx>`.
30
25
another location (e.g. ``public_html/ ``) make sure you
31
26
:ref: `override the location of the public/ directory <override-web-dir >`.
32
27
33
- .. _web-server-apache-mod-php :
34
-
35
- Adding Rewrite Rules
36
- --------------------
37
-
38
- The easiest way is to install the ``apache `` :ref: `Symfony pack <symfony-packs >`
39
- by executing the following command:
40
-
41
- .. code-block :: terminal
42
-
43
- $ composer require symfony/apache-pack
44
-
45
- This pack installs a ``.htaccess `` file in the ``public/ `` directory that contains
46
- the rewrite rules needed to serve the Symfony application.
47
-
48
- In production servers, you should move the ``.htaccess `` rules into the main
49
- Apache configuration file to improve performance. To do so, copy the
50
- ``.htaccess `` contents inside the ``<Directory> `` configuration associated to
51
- the Symfony application ``public/ `` directory (and replace ``AllowOverride All ``
52
- by ``AllowOverride None ``):
53
-
54
- .. code-block :: apache
55
-
56
- <VirtualHost *:80>
57
- # ...
58
- DocumentRoot /var/www/project/public
59
-
60
- <Directory /var/www/project/public>
61
- AllowOverride None
62
-
63
- # Copy .htaccess contents here
64
- </Directory>
65
- </VirtualHost>
66
-
67
- Apache with mod_php/PHP-CGI
68
- ---------------------------
69
-
70
- The **minimum configuration ** to get your application running under Apache is:
71
-
72
- .. code-block :: apache
73
-
74
- <VirtualHost *:80>
75
- ServerName domain.tld
76
- ServerAlias www.domain.tld
77
-
78
- DocumentRoot /var/www/project/public
79
- <Directory /var/www/project/public>
80
- AllowOverride All
81
- Order Allow,Deny
82
- Allow from All
83
- </Directory>
84
-
85
- # uncomment the following lines if you install assets as symlinks
86
- # or run into problems when compiling LESS/Sass/CoffeeScript assets
87
- # <Directory /var/www/project>
88
- # Options FollowSymlinks
89
- # </Directory>
90
-
91
- ErrorLog /var/log/apache2/project_error.log
92
- CustomLog /var/log/apache2/project_access.log combined
93
- </VirtualHost>
94
-
95
- .. tip ::
96
-
97
- If your system supports the ``APACHE_LOG_DIR `` variable, you may want
98
- to use ``${APACHE_LOG_DIR}/ `` instead of hardcoding ``/var/log/apache2/ ``.
99
-
100
- Use the following **optimized configuration ** to disable ``.htaccess `` support
101
- and increase web server performance:
102
-
103
- .. code-block :: apache
104
-
105
- <VirtualHost *:80>
106
- ServerName domain.tld
107
- ServerAlias www.domain.tld
108
-
109
- DocumentRoot /var/www/project/public
110
- DirectoryIndex /index.php
111
-
112
- <Directory /var/www/project/public>
113
- AllowOverride None
114
- Order Allow,Deny
115
- Allow from All
116
-
117
- FallbackResource /index.php
118
- </Directory>
119
-
120
- # uncomment the following lines if you install assets as symlinks
121
- # or run into problems when compiling LESS/Sass/CoffeeScript assets
122
- # <Directory /var/www/project>
123
- # Options FollowSymlinks
124
- # </Directory>
125
-
126
- # optionally disable the fallback resource for the asset directories
127
- # which will allow Apache to return a 404 error when files are
128
- # not found instead of passing the request to Symfony
129
- <Directory /var/www/project/public/bundles>
130
- DirectoryIndex disabled
131
- FallbackResource disabled
132
- </Directory>
133
- ErrorLog /var/log/apache2/project_error.log
134
- CustomLog /var/log/apache2/project_access.log combined
135
-
136
- # optionally set the value of the environment variables used in the application
137
- #SetEnv APP_ENV prod
138
- #SetEnv APP_SECRET <app-secret-id>
139
- #SetEnv DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"
140
- </VirtualHost>
141
-
142
- .. caution ::
143
-
144
- Use ``FallbackResource `` on Apache 2.4.25 or higher, due to a bug which was
145
- fixed on that release causing the root ``/ `` to hang.
146
-
147
- .. tip ::
148
-
149
- If you are using **php-cgi **, Apache does not pass HTTP basic username and
150
- password to PHP by default. To work around this limitation, you should use
151
- the following configuration snippet:
152
-
153
- .. code-block :: apache
154
-
155
- RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
156
-
157
- Using mod_php/PHP-CGI with Apache 2.4
158
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
159
-
160
- In Apache 2.4, ``Order Allow,Deny `` has been replaced by ``Require all granted ``.
161
- Hence, you need to modify your ``Directory `` permission settings as follows:
162
-
163
- .. code-block :: apache
164
-
165
- <Directory /var/www/project/public>
166
- Require all granted
167
- # ...
168
- </Directory>
169
-
170
- For advanced Apache configuration options, read the official `Apache documentation `_.
171
-
172
- .. _web-server-apache-fpm :
173
-
174
28
Apache with PHP-FPM
175
29
-------------------
176
30
@@ -234,9 +88,9 @@ requests to PHP-FPM. Configure PHP-FPM to listen on a TCP or Unix socket, enable
234
88
235
89
DocumentRoot /var/www/project/public
236
90
<Directory /var/www/project/public>
237
- # enable the .htaccess rewrites
238
- AllowOverride All
91
+ AllowOverride None
239
92
Require all granted
93
+ FallbackResource /index.php
240
94
</Directory>
241
95
242
96
# uncomment the following lines if you install assets as symlinks
@@ -249,51 +103,6 @@ requests to PHP-FPM. Configure PHP-FPM to listen on a TCP or Unix socket, enable
249
103
CustomLog /var/log/apache2/project_access.log combined
250
104
</VirtualHost>
251
105
252
- PHP-FPM with Apache 2.2
253
- ~~~~~~~~~~~~~~~~~~~~~~~
254
-
255
- On Apache 2.2 or lower, you cannot use ``mod_proxy_fcgi ``. You have to use
256
- the `FastCgiExternalServer `_ directive instead. Therefore, your Apache configuration
257
- should look something like this:
258
-
259
- .. code-block :: apache
260
-
261
- <VirtualHost *:80>
262
- ServerName domain.tld
263
- ServerAlias www.domain.tld
264
-
265
- AddHandler php7-fcgi .php
266
- Action php7-fcgi /php7-fcgi
267
- Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
268
- FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -host 127.0.0.1:9000 -pass-header Authorization
269
-
270
- DocumentRoot /var/www/project/public
271
- <Directory /var/www/project/public>
272
- # enable the .htaccess rewrites
273
- AllowOverride All
274
- Order Allow,Deny
275
- Allow from all
276
- </Directory>
277
-
278
- # uncomment the following lines if you install assets as symlinks
279
- # or run into problems when compiling LESS/Sass/CoffeeScript assets
280
- # <Directory /var/www/project>
281
- # Options FollowSymlinks
282
- # </Directory>
283
-
284
- ErrorLog /var/log/apache2/project_error.log
285
- CustomLog /var/log/apache2/project_access.log combined
286
- </VirtualHost>
287
-
288
- If you prefer to use a Unix socket, you have to use the ``-socket `` option
289
- instead:
290
-
291
- .. code-block :: apache
292
-
293
- FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/run/php/php7.4-fpm.sock -pass-header Authorization
294
-
295
- .. _web-server-nginx :
296
-
297
106
Nginx
298
107
-----
299
108
0 commit comments