File: nginx.xml

package info (click to toggle)
php-doc 20241205~git.dfcbb86%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 70,956 kB
  • sloc: xml: 968,269; php: 23,883; javascript: 671; sh: 177; makefile: 37
file content (288 lines) | stat: -rw-r--r-- 7,383 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<sect1 xml:id="install.unix.nginx" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <title>Nginx 1.4.x on Unix systems</title>

 <para>
  This documentation will cover installing and configuring PHP with
  PHP-FPM for a Nginx 1.4.x HTTP server.
 </para>

 <para>
  This guide will assume that you have built Nginx from source and therefore
  all binaries and configuration files are located at
  <literal>/usr/local/nginx</literal>. If this is not the case and you have
  obtained Nginx through other means then please refer to the
  <link xlink:href="&url.nginx;">Nginx Wiki</link> in order to translate
  this manual to your setup.
 </para>

 <para>
  This guide will cover the basics of configuring an Nginx server to
  process PHP applications and serve them on port 80, it is recommended
  that you study the Nginx and PHP-FPM documentation if you wish to
  optimise your setup past the scope of this documentation.
 </para>

 <para>
  Please note that throughout this documentation version numbers have been
  replaced with an 'x' to ensure this documentation stays correct in the future,
  please replace these as necessary with the corresponding version numbers.
 </para>

 <orderedlist>
  <listitem>
   <para>
    It is recommended that you visit the Nginx Wiki
    <link xlink:href="&url.nginx.wiki.install;">install</link> page 
    in order to obtain and install Nginx on your system.
   </para>
  </listitem>

  <listitem>
   <para>
    Obtain and unpack the PHP source:
   </para>

   <informalexample xml:id="install.unix.nginx.extract.php">
    <screen>
<![CDATA[
tar zxf php-x.x.x
]]>
    </screen>
   </informalexample>
  </listitem>

  <listitem>
   <para>
    Configure and build PHP.  This is where you customize PHP
    with various options, like which extensions will be enabled. Run
    ./configure --help for a list of available options.  In our example
    we'll do a simple configure with PHP-FPM and MySQLi support.
   </para>

   <informalexample xml:id="install.unix.nginx.build.php">
    <screen>
<![CDATA[
cd ../php-x.x.x
./configure --enable-fpm --with-mysqli
make
sudo make install
]]>
    </screen>
   </informalexample>
  </listitem>

  <listitem>
   <para>
    Obtain and move configuration files to their correct locations
   </para>

   <informalexample xml:id="install.unix.nginx.configure.php">
    <screen>
<![CDATA[
cp php.ini-development /usr/local/php/php.ini
cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf
cp sapi/fpm/php-fpm /usr/local/bin
]]>
    </screen>
   </informalexample>
  </listitem>

  <listitem>
   <para>
    It is important that we prevent Nginx from passing requests to the
    PHP-FPM backend if the file does not exist, allowing us to prevent
    arbitrarily script injection.
   </para>
   <para>
    We can fix this by setting the
    <link linkend="ini.cgi.fix-pathinfo">cgi.fix_pathinfo</link>
    directive to <literal>0</literal> within our php.ini file.
   </para>
   <para>
    Load up php.ini:
   </para>

   <informalexample xml:id="install.unix.nginx.configure.ini">
    <screen>
<![CDATA[
vim /usr/local/php/php.ini
]]>
    </screen>
   </informalexample>

   <para>
    Locate <literal>cgi.fix_pathinfo=</literal> and modify it as follows:
   </para>

   <informalexample xml:id="install.unix.nginx.configure.pathinfo">
    <screen>
<![CDATA[
cgi.fix_pathinfo=0
]]>
    </screen>
   </informalexample>
  </listitem>

  <listitem>
   <para>
    php-fpm.conf must be modified to specify that php-fpm must run as the user
    www-data and the group www-data before we can start the service:
   </para>

   <informalexample xml:id="install.unix.nginx.modify.phpfpm">
    <screen>
<![CDATA[
vim /usr/local/etc/php-fpm.d/www.conf
]]>
    </screen>
   </informalexample>

   <para>
    Find and modify the following: 
   </para>

   <informalexample xml:id="install.unix.nginx.modify.phpfpm.usergroup">
    <screen>
<![CDATA[
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = www-data
group = www-data
]]>
    </screen>
   </informalexample>

   <para>
    The php-fpm service can now be started:
   </para>

   <informalexample xml:id="install.unix.nginx.start.phpfpm">
    <screen>
<![CDATA[
/usr/local/bin/php-fpm
]]>
    </screen>
   </informalexample>

   <para>
    This guide will not configure php-fpm any further, if you are interested
    in further configuring php-fpm then please consult the documentation.
   </para>
  </listitem>

  <listitem>
   <para>
    Nginx must now be configured to support the processing of PHP applications:
   </para>

   <informalexample xml:id="install.unix.nginx.configure.nginx">
    <programlisting>
<![CDATA[
vim /usr/local/nginx/conf/nginx.conf
]]>
    </programlisting>
   </informalexample>

   <para>
    Modify the default location block to be aware it must attempt
    to serve .php files:
   </para>

   <informalexample xml:id="install.unix.nginx.configure.nginx.location">
    <programlisting role="nginx-conf">
<![CDATA[
location / {
    root   html;
    index  index.php index.html index.htm;
}
]]>
    </programlisting>
   </informalexample>

   <para>
    The next step is to ensure that .php files are passed to the
    PHP-FPM backend. Below the commented default PHP location block,
    enter the following:
   </para>

   <informalexample xml:id="install.unix.nginx.configure.nginx.php">
    <programlisting role="nginx-conf">
<![CDATA[
location ~* \.php$ {
    fastcgi_index   index.php;
    fastcgi_pass    127.0.0.1:9000;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
}
]]>
    </programlisting>
   </informalexample>

   <para>
    Restart Nginx.
   </para>

   <informalexample xml:id="install.unix.nginx.restart.nginx">
    <screen>
<![CDATA[
sudo /usr/local/nginx/sbin/nginx -s stop
sudo /usr/local/nginx/sbin/nginx
]]>
    </screen>
   </informalexample>
  </listitem>

  <listitem>
   <para>
    Create a test file
   </para>

   <informalexample xml:id="install.unix.nginx.test.nginx.php">
    <screen>
<![CDATA[
rm /usr/local/nginx/html/index.html
echo "<?php phpinfo(); ?>" >> /usr/local/nginx/html/index.php
]]>
    </screen>
   </informalexample>

   <para>
    Now navigate to http://localhost. The phpinfo() should now be shown.
   </para>
  </listitem>
 </orderedlist>

 <para>
  Following the steps above you will have a running Nginx web server with
  support for PHP as an <literal>FPM</literal> <literal>SAPI</literal> module.  Of course there are
  many more configuration options available for Nginx and PHP.  For more
  information type <command>./configure --help</command> in the corresponding
  source tree.
 </para>

</sect1>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->