Skip to content

Commit cd07f5f

Browse files
committed
Merge branch '2.4' into 2.5
* 2.4: 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 [symfony#3940] Adding php example for an array of emails Conflicts: cookbook/console/sending_emails.rst
2 parents bb39863 + 850b93b commit cd07f5f

File tree

14 files changed

+213
-24
lines changed

14 files changed

+213
-24
lines changed

.travis.yml

+5
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

+1-1
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

+6-6
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

+105-2
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ from the ``router`` service and override its settings::
8585
Using Memory Spooling
8686
---------------------
8787

88-
.. versionadded: 2.3
88+
.. versionadded:: 2.3
8989
When using Symfony 2.3+ and SwiftmailerBundle 2.3.5+, the memory spool is now
9090
handled automatically in the CLI and the code below is not necessary anymore.
9191

cookbook/index.rst

+1
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

+3-1
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

+5
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@
202202

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

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

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

cookbook/security/target_path.rst

+6-5
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

+8-7
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ edit a particular object. Here's an example implementation:
6161
// src/Acme/DemoBundle/Security/Authorization/Voter/PostVoter.php
6262
namespace Acme\DemoBundle\Security\Authorization\Voter;
6363
64-
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
6564
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
6665
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
6766
use Symfony\Component\Security\Core\User\UserInterface;
@@ -100,44 +99,46 @@ edit a particular object. Here's an example implementation:
10099
// this isn't a requirement, it's just one easy way for you to
101100
// design your voter
102101
if(1 !== count($attributes)) {
103-
throw new InvalidArgumentException(
102+
throw new \InvalidArgumentException(
104103
'Only one attribute is allowed for VIEW or EDIT'
105104
);
106105
}
107106
108107
// set the attribute to check against
109108
$attribute = $attributes[0];
110109
111-
// get current logged in user
112-
$user = $token->getUser();
113-
114110
// check if the given attribute is covered by this voter
115111
if (!$this->supportsAttribute($attribute)) {
116112
return VoterInterface::ACCESS_ABSTAIN;
117113
}
118114
115+
// get current logged in user
116+
$user = $token->getUser();
117+
119118
// make sure there is a user object (i.e. that the user is logged in)
120119
if (!$user instanceof UserInterface) {
121120
return VoterInterface::ACCESS_DENIED;
122121
}
123122
124123
switch($attribute) {
125-
case 'view':
124+
case self::VIEW:
126125
// the data object could have for example a method isPrivate()
127126
// which checks the Boolean attribute $private
128127
if (!$post->isPrivate()) {
129128
return VoterInterface::ACCESS_GRANTED;
130129
}
131130
break;
132131
133-
case 'edit':
132+
case self::EDIT:
134133
// we assume that our data object has a method getOwner() to
135134
// get the current owner user entity for this data object
136135
if ($user->getId() === $post->getOwner()->getId()) {
137136
return VoterInterface::ACCESS_GRANTED;
138137
}
139138
break;
140139
}
140+
141+
return VoterInterface::ACCESS_DENIED;
141142
}
142143
}
143144

cookbook/web_server/built_in.rst

+60
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

+7
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

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ to run Symfony:
7373
7474
$ php app/console server:run
7575
76+
.. seealso::
77+
78+
Read more about the internal server :doc:`in the cookbook </cookbook/web_server/built_in>`.
79+
7680
If you get the error `There are no commands defined in the "server" namespace.`,
7781
then you are probably using PHP 5.3. That's ok! But the built-in web server is
7882
only available for PHP 5.4.0 or higher. If you have an older version of PHP or

reference/configuration/framework.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ would be ``/images/logo.png?version=5``.
430430

431431
URL rewrite rules could then be used to disregard the version prefix before
432432
serving the asset. Alternatively, you could copy assets to the appropriate
433-
version path as part of your deployment process and forgo any URL rewriting.
433+
version path as part of your deployment process and forgot any URL rewriting.
434434
The latter option is useful if you would like older asset versions to remain
435435
accessible at their original URL.
436436

0 commit comments

Comments
 (0)