Skip to content

Commit 876557a

Browse files
Simplifiying the "A simple tutorial" page (#4953)
* doc: Simplifiying the "A simple tutorial" page by removing the Apache and MySQL pre-requisites and using php's builtin server * Apply suggestions from code review Co-authored-by: Tim Düsterhus <[email protected]> * Update chapters/tutorial.xml Co-authored-by: Tim Düsterhus <[email protected]> * Adding closing tag to examples * Removing trailing whitespace --------- Co-authored-by: Tim Düsterhus <[email protected]>
1 parent 170b6cd commit 876557a

File tree

1 file changed

+30
-64
lines changed

1 file changed

+30
-64
lines changed

chapters/tutorial.xml

Lines changed: 30 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,15 @@
1616
regular HTML pages.
1717
</para>
1818

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-
6019
<section xml:id="tutorial.firstpage">
6120
<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>
6226
<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>
6528
with the following content:
6629
</para>
6730
<para>
@@ -74,16 +37,24 @@
7437
echo "Hello World!";
7538
7639
?>
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
7749
]]>
7850
</programlisting>
7951
<simpara>
8052
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.
8758
</simpara>
8859
<simpara>
8960
PHP can be embedded within a normal HTML web page. That means inside your HTML document
@@ -130,20 +101,7 @@ echo "Hello World!";
130101
to pass on to PHP. Think of this as a normal HTML file which happens to have
131102
a set of special tags available to you that do a lot of interesting things.
132103
</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+
147105
<para>
148106
The point of the example is to show the special PHP tag format.
149107
In this example we used <literal>&lt;?php</literal> to indicate the
@@ -206,7 +164,11 @@ echo "Hello World!";
206164
<info><title>Get system information from PHP</title></info>
207165
<programlisting role="php">
208166
<![CDATA[
209-
<?php phpinfo(); ?>
167+
<?php
168+
169+
phpinfo();
170+
171+
?>
210172
]]>
211173
</programlisting>
212174
</example>
@@ -242,7 +204,9 @@ echo "Hello World!";
242204
<programlisting role="php">
243205
<![CDATA[
244206
<?php
207+
245208
echo $_SERVER['HTTP_USER_AGENT'];
209+
246210
?>
247211
]]>
248212
</programlisting>
@@ -283,9 +247,11 @@ Mozilla/5.0 (Linux) Firefox/112.0
283247
<programlisting role="php">
284248
<![CDATA[
285249
<?php
250+
286251
if (str_contains($_SERVER['HTTP_USER_AGENT'], 'Firefox')) {
287252
echo 'You are using Firefox.';
288253
}
254+
289255
?>
290256
]]>
291257
</programlisting>

0 commit comments

Comments
 (0)