Skip to content

Commit 66258b9

Browse files
committed
minor #8693 Fix server configuration for Symfony 4 (sgautier, michaelperrin)
This PR was merged into the 4.0 branch. Discussion ---------- Fix server configuration for Symfony 4 I started this PR from #8679 to add more fixes to it. There is still one thing that is not correct, about `.htaccess` files that Symfony 4 doesn't provide anymore. This should be part of an other PR (and maybe create a recipe to create these files, I will look into it). Commits ------- d343c01 Update server configuration for Symfony 4 2ee2ce2 Change web directory with public directory
2 parents cb132fd + d343c01 commit 66258b9

File tree

1 file changed

+20
-38
lines changed

1 file changed

+20
-38
lines changed

setup/web_server_configuration.rst

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ When using Apache, you can configure PHP as an
1515
:ref:`PHP FPM <web-server-apache-fpm>`. FastCGI also is the preferred way
1616
to use PHP :ref:`with Nginx <web-server-nginx>`.
1717

18-
.. sidebar:: The Web Directory
18+
.. sidebar:: The public directory
1919

20-
The web directory is the home of all of your application's public and
20+
The public directory is the home of all of your application's public and
2121
static files, including images, stylesheets and JavaScript files. It is
22-
also where the front controllers (``index.php`` and ``index.php``) live.
22+
also where the front controller (``index.php``) lives.
2323

24-
The web directory serves as the document root when configuring your
24+
The public directory serves as the document root when configuring your
2525
web server. In the examples below, the ``public/`` directory will be the
2626
document root. This directory is ``/var/www/project/public/``.
2727

@@ -42,8 +42,8 @@ The **minimum configuration** to get your application running under Apache is:
4242
ServerName domain.tld
4343
ServerAlias www.domain.tld
4444
45-
DocumentRoot /var/www/project/web
46-
<Directory /var/www/project/web>
45+
DocumentRoot /var/www/project/public
46+
<Directory /var/www/project/public>
4747
AllowOverride All
4848
Order Allow,Deny
4949
Allow from All
@@ -73,8 +73,8 @@ and increase web server performance:
7373
ServerName domain.tld
7474
ServerAlias www.domain.tld
7575
76-
DocumentRoot /var/www/project/web
77-
<Directory /var/www/project/web>
76+
DocumentRoot /var/www/project/public
77+
<Directory /var/www/project/public>
7878
AllowOverride None
7979
Order Allow,Deny
8080
Allow from All
@@ -123,7 +123,7 @@ Hence, you need to modify your ``Directory`` permission settings as follows:
123123

124124
.. code-block:: apache
125125
126-
<Directory /var/www/project/web>
126+
<Directory /var/www/project/public>
127127
Require all granted
128128
# ...
129129
</Directory>
@@ -193,8 +193,8 @@ use the ``SetHandler`` directive to pass requests for PHP files to PHP FPM:
193193
# regular expression must be changed accordingly:
194194
# ProxyPassMatch ^/path-to-app/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/project/public/$1
195195
196-
DocumentRoot /var/www/project/web
197-
<Directory /var/www/project/web>
196+
DocumentRoot /var/www/project/public
197+
<Directory /var/www/project/public>
198198
# enable the .htaccess rewrites
199199
AllowOverride All
200200
Require all granted
@@ -228,8 +228,8 @@ should look something like this:
228228
Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
229229
FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -host 127.0.0.1:9000 -pass-header Authorization
230230
231-
DocumentRoot /var/www/project/web
232-
<Directory /var/www/project/web>
231+
DocumentRoot /var/www/project/public
232+
<Directory /var/www/project/public>
233233
# enable the .htaccess rewrites
234234
AllowOverride All
235235
Order Allow,Deny
@@ -264,31 +264,14 @@ The **minimum configuration** to get your application running under Nginx is:
264264
265265
server {
266266
server_name domain.tld www.domain.tld;
267-
root /var/www/project/web;
267+
root /var/www/project/public;
268268
269269
location / {
270270
# try to serve file directly, fallback to index.php
271271
try_files $uri /index.php$is_args$args;
272272
}
273-
# DEV
274-
# This rule should only be placed on your development environment
275-
# In production, don't include this and don't deploy index.php or config.php
276-
location ~ ^/(app_dev|config)\.php(/|$) {
277-
fastcgi_pass unix:/var/run/php7.1-fpm.sock;
278-
fastcgi_split_path_info ^(.+\.php)(/.*)$;
279-
include fastcgi_params;
280-
# When you are using symlinks to link the document root to the
281-
# current version of your application, you should pass the real
282-
# application path instead of the path to the symlink to PHP
283-
# FPM.
284-
# Otherwise, PHP's OPcache may not properly detect changes to
285-
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
286-
# for more information).
287-
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
288-
fastcgi_param DOCUMENT_ROOT $realpath_root;
289-
}
290-
# PROD
291-
location ~ ^/app\.php(/|$) {
273+
274+
location ~ ^/index\.php(/|$) {
292275
fastcgi_pass unix:/var/run/php7.1-fpm.sock;
293276
fastcgi_split_path_info ^(.+\.php)(/.*)$;
294277
include fastcgi_params;
@@ -324,17 +307,16 @@ The **minimum configuration** to get your application running under Nginx is:
324307

325308
.. tip::
326309

327-
This executes **only** ``index.php``, ``index.php`` and ``config.php`` in
328-
the web directory. All other files ending in ".php" will be denied.
310+
This executes **only** ``index.php`` in the public directory. All other files
311+
ending in ".php" will be denied.
329312

330-
If you have other PHP files in your web directory that need to be executed,
313+
If you have other PHP files in your public directory that need to be executed,
331314
be sure to include them in the ``location`` block above.
332315

333316
.. caution::
334317

335318
After you deploy to production, make sure that you **cannot** access the ``index.php``
336-
or ``config.php`` scripts (i.e. ``http://example.com/index.php`` and ``http://example.com/config.php``).
337-
If you *can* access these, be sure to remove the ``DEV`` section from the above configuration.
319+
script (i.e. ``http://example.com/index.php``).
338320

339321
.. note::
340322

0 commit comments

Comments
 (0)