Skip to content

Commit 07c64a3

Browse files
committed
modernize the web server configuration chapter
1 parent 09e26d1 commit 07c64a3

File tree

1 file changed

+4
-173
lines changed

1 file changed

+4
-173
lines changed

setup/web_server_configuration.rst

Lines changed: 4 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@ The preferred way to develop your Symfony application is to use
88
:doc:`Symfony Local Web Server </setup/symfony_server>`.
99

1010
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.
1813

1914
.. sidebar:: The public directory
2015

@@ -30,21 +25,9 @@ to use PHP :ref:`with Nginx <web-server-nginx>`.
3025
another location (e.g. ``public_html/``) make sure you
3126
:ref:`override the location of the public/ directory <override-web-dir>`.
3227

33-
.. _web-server-apache-mod-php:
34-
3528
Adding Rewrite Rules
3629
--------------------
3730

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-
4831
In production servers, you should move the ``.htaccess`` rules into the main
4932
Apache configuration file to improve performance. To do so, copy the
5033
``.htaccess`` contents inside the ``<Directory>`` configuration associated to
@@ -64,113 +47,6 @@ by ``AllowOverride None``):
6447
</Directory>
6548
</VirtualHost>
6649
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-
17450
Apache with PHP-FPM
17551
-------------------
17652

@@ -234,9 +110,9 @@ requests to PHP-FPM. Configure PHP-FPM to listen on a TCP or Unix socket, enable
234110
235111
DocumentRoot /var/www/project/public
236112
<Directory /var/www/project/public>
237-
# enable the .htaccess rewrites
238-
AllowOverride All
113+
AllowOverride None
239114
Require all granted
115+
FallbackResource /index.php
240116
</Directory>
241117
242118
# uncomment the following lines if you install assets as symlinks
@@ -249,51 +125,6 @@ requests to PHP-FPM. Configure PHP-FPM to listen on a TCP or Unix socket, enable
249125
CustomLog /var/log/apache2/project_access.log combined
250126
</VirtualHost>
251127
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-
297128
Nginx
298129
-----
299130

0 commit comments

Comments
 (0)