Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4ea4dfe

Browse filesBrowse files
committed
feature #3915 [Cookbook][Configuration] documentation of Apache + PHP-FPM (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [Cookbook][Configuration] documentation of Apache + PHP-FPM | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes | Applies to | all | Fixed tickets | #3749 Commits ------- 822b3bd document the usage of PHP-FPM on Apache
2 parents 6e90520 + 822b3bd commit 4ea4dfe
Copy full SHA for 4ea4dfe

File tree

Expand file treeCollapse file tree

1 file changed

+105
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+105
-2
lines changed

‎cookbook/configuration/web_server_configuration.rst

Copy file name to clipboardExpand all lines: cookbook/configuration/web_server_configuration.rst
+105-2Lines 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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.