Skip to content

Commit 850b93b

Browse files
committed
Merge branch '2.3' into 2.4
* 2.3: Added comma after "For example" Improved clarity of explanation around overriding setTargetPath() Removed redundant POST request exclusion info Revert "missing backtik" typo, replaced form by from replaced forgo by forgot removed unnecessary parentheses missing backtik cleaned up the code example fixed wrongly linked dependency fixed directive syntax add cookbook article for the server:run command document the usage of PHP-FPM on Apache Avoiding builds for the git notes [#3940] Adding php example for an array of emails
2 parents 303ff29 + 041105c commit 850b93b

File tree

14 files changed

+214
-25
lines changed

14 files changed

+214
-25
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ install:
88
- "pip install -q -r requirements.txt --use-mirrors"
99

1010
script: sphinx-build -nW -b html -d _build/doctrees . _build/html
11+
12+
branches:
13+
except:
14+
- github-comments
15+

components/http_foundation/introduction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ on how this is used in the Symfony2 framework, see
177177
:ref:`the Symfony2 book <book-fundamentals-attributes>`.
178178

179179
Finally, the raw data sent with the request body can be accessed using
180-
:method:`Symfony\\Component\\HttpFoundation\\Request::getContent()`::
180+
:method:`Symfony\\Component\\HttpFoundation\\Request::getContent`::
181181

182182
$content = $request->getContent();
183183

components/translation/introduction.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ Loader too. The default loaders are:
7373
* :class:`Symfony\\Component\\Translation\\Loader\\CsvFileLoader` - to load
7474
catalogs from CSV files.
7575
* :class:`Symfony\\Component\\Translation\\Loader\\IcuDatFileLoader` - to load
76-
catalogs form resource bundles.
76+
catalogs from resource bundles.
7777
* :class:`Symfony\\Component\\Translation\\Loader\\IcuResFileLoader` - to load
78-
catalogs form resource bundles.
78+
catalogs from resource bundles.
7979
* :class:`Symfony\\Component\\Translation\\Loader\\IniFileLoader` - to load
80-
catalogs form ini files.
80+
catalogs from ini files.
8181
* :class:`Symfony\\Component\\Translation\\Loader\\MoFileLoader` - to load
82-
catalogs form gettext files.
82+
catalogs from gettext files.
8383
* :class:`Symfony\\Component\\Translation\\Loader\\PhpFileLoader` - to load
8484
catalogs from PHP files.
8585
* :class:`Symfony\\Component\\Translation\\Loader\\PoFileLoader` - to load
86-
catalogs form gettext files.
86+
catalogs from gettext files.
8787
* :class:`Symfony\\Component\\Translation\\Loader\\QtFileLoader` - to load
88-
catalogs form QT XML files.
88+
catalogs from QT XML files.
8989
* :class:`Symfony\\Component\\Translation\\Loader\\XliffFileLoader` - to load
9090
catalogs from Xliff files.
9191
* :class:`Symfony\\Component\\Translation\\Loader\\JsonFileLoader` - to load

cookbook/configuration/web_server_configuration.rst

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ front controllers live. For more details, see the :ref:`the-web-directory`.
1111
The web directory services as the document root when configuring your web
1212
server. In the examples below, this directory is in ``/var/www/project/web/``.
1313

14-
Apache2
15-
-------
14+
Apache2 with mod_php/PHP-CGI
15+
----------------------------
1616

1717
For advanced Apache configuration options, see the official `Apache`_
1818
documentation. The minimum basics to get your application running under Apache2
@@ -63,6 +63,107 @@ following configuration snippet:
6363
Require all granted
6464
</Directory>
6565
66+
Apache2 with PHP-FPM
67+
--------------------
68+
69+
To make use of PHP5-FPM with Apache, you first have to ensure that you have
70+
the FastCGI process manager ``php-fpm`` binary and Apache's FastCGI module
71+
installed (for example, on a Debian based system you have to install the
72+
``libapache2-mod-fastcgi`` and ``php5-fpm`` packages).
73+
74+
PHP-FPM uses so called *pools* to handle incoming FastCGI requests. You can
75+
configure an arbitrary number of pools in the FPM configuration. In a pool
76+
you configure either a TCP socket (IP and port) or a unix domain socket to
77+
listen on. Each pool can also be run under a different UID and GID:
78+
79+
.. code-block:: ini
80+
81+
; a pool called www
82+
[www]
83+
user = www-data
84+
group = www-data
85+
86+
; use a unix domain socket
87+
listen = /var/run/php5-fpm.sock
88+
89+
; or listen on a TCP socket
90+
listen = 127.0.0.1:9000
91+
92+
Using mod_proxy_fcgi with Apache 2.4
93+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94+
95+
If you are running Apache 2.4, you can easily use ``mod_proxy_fcgi`` to pass
96+
incoming requests to PHP-FPM. Configure PHP-FPM to listen on a TCP socket
97+
(``mod_proxy`` currently `does not support unix sockets`_), enable ``mod_proxy``
98+
and ``mod_proxy_fcgi`` in your Apache configuration and use the ``ProxyPassMatch``
99+
directive to pass requests for PHP files to PHP FPM:
100+
101+
.. code-block:: apache
102+
103+
<VirtualHost *:80>
104+
ServerName domain.tld
105+
ServerAlias www.domain.tld
106+
107+
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/project/web/$1
108+
109+
DocumentRoot /var/www/project/web
110+
<Directory /var/www/project/web>
111+
# enable the .htaccess rewrites
112+
AllowOverride All
113+
Require all granted
114+
</Directory>
115+
116+
ErrorLog /var/log/apache2/project_error.log
117+
CustomLog /var/log/apache2/project_access.log combined
118+
</VirtualHost>
119+
120+
.. caution::
121+
122+
When you run your Symfony application on a subpath of your document root,
123+
the regular expression used in ``ProxyPassMatch`` directive must be changed
124+
accordingly:
125+
126+
.. code-block:: apache
127+
128+
ProxyPassMatch ^/path-to-app/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/project/web/$1
129+
130+
PHP-FPM with Apache 2.2
131+
~~~~~~~~~~~~~~~~~~~~~~~
132+
133+
On Apache 2.2 or lower, you cannot use ``mod_proxy_fcgi``. You have to use
134+
the `FastCgiExternalServer`_ directive instead. Therefore, your Apache configuration
135+
should look something like this:
136+
137+
.. code-block:: apache
138+
139+
<VirtualHost *:80>
140+
ServerName domain.tld
141+
ServerAlias www.domain.tld
142+
143+
AddHandler php5-fcgi .php
144+
Action php5-fcgi /php5-fcgi
145+
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
146+
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
147+
148+
DocumentRoot /var/www/project/web
149+
<Directory /var/www/project/web>
150+
# enable the .htaccess rewrites
151+
AllowOverride All
152+
Order allow,deny
153+
Allow from all
154+
</Directory>
155+
156+
ErrorLog /var/log/apache2/project_error.log
157+
CustomLog /var/log/apache2/project_access.log combined
158+
</VirtualHost>
159+
160+
If you prefer to use a unix socket, you have to use the ``-socket`` option
161+
instead:
162+
163+
.. code-block:: apache
164+
165+
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
166+
66167
Nginx
67168
-----
68169

@@ -110,4 +211,6 @@ are:
110211
be sure to include them in the ``location`` block above.
111212

112213
.. _`Apache`: http://httpd.apache.org/docs/current/mod/core.html#documentroot
214+
.. _`does not support unix sockets`: https://issues.apache.org/bugzilla/show_bug.cgi?id=54101
215+
.. _`FastCgiExternalServer`: http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiExternalServer
113216
.. _`Nginx`: http://wiki.nginx.org/Symfony

cookbook/console/sending_emails.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ and per Command.
2020
Configuring the Request Context globally
2121
----------------------------------------
2222

23-
.. versionadded: 2.2
23+
.. versionadded:: 2.2
2424
The ``base_url`` parameter was introduced in Symfony 2.2.
2525

2626
To configure the Request Context - which is used by the URL Generator - you can
@@ -88,7 +88,7 @@ from the ``router`` service and override its settings::
8888
Using Memory Spooling
8989
---------------------
9090

91-
.. versionadded: 2.3
91+
.. versionadded:: 2.3
9292
When using Symfony 2.3+ and SwiftmailerBundle 2.3.5+, the memory spool is now
9393
handled automatically in the CLI and the code below is not necessary anymore.
9494

cookbook/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The Cookbook
2929
templating/index
3030
testing/index
3131
validation/index
32+
web_server/index
3233
web_services/index
3334
workflow/index
3435

cookbook/logging/monolog_email.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ it is broken down.
2929
from_email: [email protected]
3030
3131
# or list of recipients
32-
# to_email: [developer_1@example.com, developer_2@example.com, ...]
32+
# to_email: [dev1@example.com, dev2@example.com, ...]
3333
subject: An Error Occurred!
3434
level: debug
3535
@@ -82,6 +82,8 @@ it is broken down.
8282
'type' => 'swift_mailer',
8383
'from_email' => '[email protected]',
8484
'to_email' => '[email protected]',
85+
// or a list of recipients
86+
// 'to_email' => array('[email protected]', '[email protected]', ...),
8587
'subject' => 'An Error Occurred!',
8688
'level' => 'debug',
8789
),

cookbook/map.rst.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@
201201

202202
* :doc:`/cookbook/validation/custom_constraint`
203203

204+
* :doc:`/cookbook/web_server/index`
205+
206+
* :doc:`/cookbook/web_server/built_in`
207+
* (configuration) :doc:`/cookbook/configuration/web_server_configuration`
208+
204209
* :doc:`/cookbook/web_services/index`
205210

206211
* :doc:`/cookbook/web_services/php_soap_extension`

cookbook/security/target_path.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ the name of the firewall, defined in ``security.yml``). Upon a successful
1010
login, the user is redirected to this path, as to help them continue from the
1111
last known page they visited.
1212

13-
On some occasions, this is unexpected. For example when the last request
14-
URI was an HTTP POST against a route which is configured to allow only a POST
15-
method, the user is redirected to this route only to get a 404 error.
13+
In some situations, this is not ideal. For example, when the last request
14+
URI was an XMLHttpRequest which returned a non-HTML or partial HTML response,
15+
the user is redirected back to a page which the browser cannot render.
1616

1717
To get around this behavior, you would simply need to extend the ``ExceptionListener``
1818
class and override the default method named ``setTargetPath()``.
@@ -56,9 +56,10 @@ Next, create your own ``ExceptionListener``::
5656
{
5757
protected function setTargetPath(Request $request)
5858
{
59-
// Do not save target path for XHR and non-GET requests
59+
// Do not save target path for XHR requests
6060
// You can add any more logic here you want
61-
if ($request->isXmlHttpRequest() || 'GET' !== $request->getMethod()) {
61+
// Note that non-GET requests are already ignored
62+
if ($request->isXmlHttpRequest()) {
6263
return;
6364
}
6465

cookbook/security/voters_data_permission.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ edit a particular object. Here's an example implementation::
5959
// src/Acme/DemoBundle/Security/Authorization/Voter/PostVoter.php
6060
namespace Acme\DemoBundle\Security\Authorization\Voter;
6161

62-
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
6362
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
6463
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
6564
use Symfony\Component\Security\Core\User\UserInterface;
@@ -98,44 +97,46 @@ edit a particular object. Here's an example implementation::
9897
// this isn't a requirement, it's just one easy way for you to
9998
// design your voter
10099
if(1 !== count($attributes)) {
101-
throw new InvalidArgumentException(
100+
throw new \InvalidArgumentException(
102101
'Only one attribute is allowed for VIEW or EDIT'
103102
);
104103
}
105104

106105
// set the attribute to check against
107106
$attribute = $attributes[0];
108107

109-
// get current logged in user
110-
$user = $token->getUser();
111-
112108
// check if the given attribute is covered by this voter
113109
if (!$this->supportsAttribute($attribute)) {
114110
return VoterInterface::ACCESS_ABSTAIN;
115111
}
116112

113+
// get current logged in user
114+
$user = $token->getUser();
115+
117116
// make sure there is a user object (i.e. that the user is logged in)
118117
if (!$user instanceof UserInterface) {
119118
return VoterInterface::ACCESS_DENIED;
120119
}
121120

122121
switch($attribute) {
123-
case 'view':
122+
case self::VIEW:
124123
// the data object could have for example a method isPrivate()
125124
// which checks the Boolean attribute $private
126125
if (!$post->isPrivate()) {
127126
return VoterInterface::ACCESS_GRANTED;
128127
}
129128
break;
130129

131-
case 'edit':
130+
case self::EDIT:
132131
// we assume that our data object has a method getOwner() to
133132
// get the current owner user entity for this data object
134133
if ($user->getId() === $post->getOwner()->getId()) {
135134
return VoterInterface::ACCESS_GRANTED;
136135
}
137136
break;
138137
}
138+
139+
return VoterInterface::ACCESS_DENIED;
139140
}
140141
}
141142

cookbook/web_server/built_in.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.. index::
2+
single: Web Server; Built-in Web Server
3+
4+
How to Use PHP's built-in Web Server
5+
====================================
6+
7+
Since PHP 5.4 the CLI SAPI comes with a `built-in web server`_. It can be used
8+
to run your PHP applications locally during development, for testing or for
9+
application demonstrations. This way, you don't have to bother configuring
10+
a full-featured web server such as
11+
:doc:`Apache or Nginx </cookbook/configuration/web_server_configuration>`.
12+
13+
.. caution::
14+
15+
The built-in web server is meant to be run in a controlled environment.
16+
It is not designed to be used on public networks.
17+
18+
Starting the Web Server
19+
-----------------------
20+
21+
Running a Symfony application using PHP's built-in web server is as easy as
22+
executing the ``server:run`` command:
23+
24+
.. code-block:: bash
25+
26+
$ php app/console server:run
27+
28+
This starts a server at ``localhost:8000`` that executes your Symfony application.
29+
The command will wait and will respond to incoming HTTP requests until you
30+
terminate it (this is usually done by pressing Ctrl and C).
31+
32+
By default, the web server listens on port 8000 on the loopback device. You
33+
can change the socket passing an ip address and a port as a command-line argument:
34+
35+
.. code-block:: bash
36+
37+
$ php app/console server:run 192.168.0.1:8080
38+
39+
Command Options
40+
---------------
41+
42+
The built-in web server expects a "router" script (read about the "router"
43+
script on `php.net`_) as an argument. Symfony already passes such a router
44+
script when the command is executed in the ``prod`` or in the ``dev`` environment.
45+
Use the ``--router`` option in any other environment or to use another router
46+
script:
47+
48+
.. code-block:: bash
49+
50+
$ php app/console server:run --env=test --router=app/config/router_test.php
51+
52+
If your application's document root differs from the standard directory layout,
53+
you have to pass the correct location using the ``--docroot`` option:
54+
55+
.. code-block:: bash
56+
57+
$ php app/console server:run --docroot=public_html
58+
59+
.. _`built-in web server`: http://www.php.net/manual/en/features.commandline.webserver.php
60+
.. _`php.net`: http://php.net/manual/en/features.commandline.webserver.php#example-401

cookbook/web_server/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Web Server
2+
==========
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
built_in

quick_tour/the_big_picture.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ to run Symfony:
5757
5858
$ php app/console server:run
5959
60+
.. seealso::
61+
62+
Read more about the internal server :doc:`in the cookbook </cookbook/web_server/built_in>`.
63+
6064
If you get the error `There are no commands defined in the "server" namespace.`,
6165
then you are probably using PHP 5.3. That's ok! But the built-in web server is
6266
only available for PHP 5.4.0 or higher. If you have an older version of PHP or

0 commit comments

Comments
 (0)