|
16 | 16 | regular HTML pages. |
17 | 17 | </para> |
18 | 18 |
|
19 | | - <section xml:id="tutorial.requirements"> |
20 | | - <info><title>What do I need?</title></info> |
21 | | - <para> |
22 | | - In this tutorial we assume that your server has activated support |
23 | | - for PHP and that all files ending in <filename class="extension">.php</filename> |
24 | | - are handled by PHP. On most servers, this is the default extension |
25 | | - for PHP files, but ask your server administrator to be sure. If |
26 | | - your server supports PHP, then you do not need to do anything. Just |
27 | | - create your <filename class="extension">.php</filename> files, put them in your |
28 | | - web directory and the server will automatically parse them for you. |
29 | | - There is no need to compile anything nor do you need to install |
30 | | - any extra tools. Think of these PHP-enabled files as simple HTML |
31 | | - files with a whole new family of magical tags that let you do all |
32 | | - sorts of things. |
33 | | - </para> |
34 | | - <para> |
35 | | - Let us say you want to save precious bandwidth and develop locally. |
36 | | - In this case, you will want to install a web server, such as |
37 | | - <link xlink:href="&url.apache;">Apache</link>, and of course |
38 | | - <link xlink:href="&url.php.downloads;">PHP</link>. You will most likely |
39 | | - want to install a database as well, such as |
40 | | - <link xlink:href="&url.mysql.docs;">MySQL</link>. |
41 | | - </para> |
42 | | - <para> |
43 | | - You can either install these individually or choose a simpler way. Our |
44 | | - manual has <link linkend="install">installation instructions for |
45 | | - PHP</link> (assuming you already have some web server set up). If |
46 | | - you have problems with installing PHP yourself, we would suggest you ask |
47 | | - your questions on our <link xlink:href="&url.php.mailing-lists;">installation |
48 | | - mailing list</link>. If you choose to go on the simpler route, then |
49 | | - <link xlink:href="&url.installkits;">locate a pre-configured package</link> |
50 | | - for your operating system, which automatically installs all of these |
51 | | - with just a few mouse clicks. It is easy to setup a web server with PHP |
52 | | - support on any operating system, including MacOSX, Linux and Windows. |
53 | | - On Linux, you may find <link xlink:href="&url.rpmfind;">rpmfind</link> and |
54 | | - <link xlink:href="&url.rpmfind.pbone;">PBone</link> helpful for |
55 | | - locating RPMs. You may also want to visit <link |
56 | | - xlink:href="&url.apt-get;">apt-get</link> to find packages for Debian. |
57 | | - </para> |
58 | | - </section> |
59 | | - |
60 | 19 | <section xml:id="tutorial.firstpage"> |
61 | 20 | <info><title>Your first PHP-enabled page</title></info> |
| 21 | + <simpara> |
| 22 | + This tutorial assumes PHP is already installed. |
| 23 | + Installation instructions can be found on the |
| 24 | + <link xlink:href="&url.php.downloads;">download page</link>. |
| 25 | + </simpara> |
62 | 26 | <para> |
63 | | - Create a file named <filename>hello.php</filename> and put it |
64 | | - in your web server's root directory (<varname>DOCUMENT_ROOT</varname>) |
| 27 | + Create a file named <filename>hello.php</filename> |
65 | 28 | with the following content: |
66 | 29 | </para> |
67 | 30 | <para> |
|
74 | 37 | echo "Hello World!"; |
75 | 38 |
|
76 | 39 | ?> |
| 40 | +]]> |
| 41 | + </programlisting> |
| 42 | + <simpara> |
| 43 | + Using your terminal, navigate to the directory containing this file and |
| 44 | + start a development server with the following command: |
| 45 | + </simpara> |
| 46 | + <programlisting role="shell"> |
| 47 | +<![CDATA[ |
| 48 | +php -S localhost:8000 |
77 | 49 | ]]> |
78 | 50 | </programlisting> |
79 | 51 | <simpara> |
80 | 52 | Use your browser to access the file with your web server's URL, ending |
81 | | - with the <literal>/hello.php</literal> file reference. When developing locally this |
82 | | - URL will be something like <literal>http://localhost/hello.php</literal> |
83 | | - or <literal>http://127.0.0.1/hello.php</literal> but this depends on the |
84 | | - web server's configuration. If everything is configured correctly, this |
85 | | - file will be parsed by PHP and you will see the "Hello World" output displayed |
86 | | - in your browser. |
| 53 | + with the <literal>/hello.php</literal> file reference. |
| 54 | + According to the previous command executed, the URL will be |
| 55 | + <literal>http://localhost:8000/hello.php</literal>. |
| 56 | + If everything is configured correctly, this file will be parsed by PHP |
| 57 | + and you will see the "Hello World!" output displayed in your browser. |
87 | 58 | </simpara> |
88 | 59 | <simpara> |
89 | 60 | PHP can be embedded within a normal HTML web page. That means inside your HTML document |
@@ -130,20 +101,7 @@ echo "Hello World!"; |
130 | 101 | to pass on to PHP. Think of this as a normal HTML file which happens to have |
131 | 102 | a set of special tags available to you that do a lot of interesting things. |
132 | 103 | </para> |
133 | | - <para> |
134 | | - If you tried this example and it did not output anything, it prompted |
135 | | - for download, or you see the whole file as text, chances are that the |
136 | | - server you are on does not have PHP enabled, or is not configured properly. |
137 | | - Ask your administrator to enable it for you using the |
138 | | - <link linkend="install">Installation</link> chapter |
139 | | - of the manual. If you are developing locally, also read the |
140 | | - installation chapter to make sure everything is configured |
141 | | - properly. Make sure that you access the file via http with the server |
142 | | - providing you the output. If you just call up the file from your file |
143 | | - system, then it will not be parsed by PHP. If the problems persist anyway, |
144 | | - do not hesitate to use one of the many |
145 | | - <link xlink:href="&url.php.support;">PHP support</link> options. |
146 | | - </para> |
| 104 | + |
147 | 105 | <para> |
148 | 106 | The point of the example is to show the special PHP tag format. |
149 | 107 | In this example we used <literal><?php</literal> to indicate the |
@@ -206,7 +164,11 @@ echo "Hello World!"; |
206 | 164 | <info><title>Get system information from PHP</title></info> |
207 | 165 | <programlisting role="php"> |
208 | 166 | <![CDATA[ |
209 | | -<?php phpinfo(); ?> |
| 167 | +<?php |
| 168 | +
|
| 169 | +phpinfo(); |
| 170 | +
|
| 171 | +?> |
210 | 172 | ]]> |
211 | 173 | </programlisting> |
212 | 174 | </example> |
@@ -242,7 +204,9 @@ echo "Hello World!"; |
242 | 204 | <programlisting role="php"> |
243 | 205 | <![CDATA[ |
244 | 206 | <?php |
| 207 | +
|
245 | 208 | echo $_SERVER['HTTP_USER_AGENT']; |
| 209 | +
|
246 | 210 | ?> |
247 | 211 | ]]> |
248 | 212 | </programlisting> |
@@ -283,9 +247,11 @@ Mozilla/5.0 (Linux) Firefox/112.0 |
283 | 247 | <programlisting role="php"> |
284 | 248 | <![CDATA[ |
285 | 249 | <?php |
| 250 | +
|
286 | 251 | if (str_contains($_SERVER['HTTP_USER_AGENT'], 'Firefox')) { |
287 | 252 | echo 'You are using Firefox.'; |
288 | 253 | } |
| 254 | +
|
289 | 255 | ?> |
290 | 256 | ]]> |
291 | 257 | </programlisting> |
|
0 commit comments