Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 30 additions & 64 deletions chapters/tutorial.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,15 @@
regular HTML pages.
</para>

<section xml:id="tutorial.requirements">
<info><title>What do I need?</title></info>
<para>
In this tutorial we assume that your server has activated support
for PHP and that all files ending in <filename class="extension">.php</filename>
are handled by PHP. On most servers, this is the default extension
for PHP files, but ask your server administrator to be sure. If
your server supports PHP, then you do not need to do anything. Just
create your <filename class="extension">.php</filename> files, put them in your
web directory and the server will automatically parse them for you.
There is no need to compile anything nor do you need to install
any extra tools. Think of these PHP-enabled files as simple HTML
files with a whole new family of magical tags that let you do all
sorts of things.
</para>
<para>
Let us say you want to save precious bandwidth and develop locally.
In this case, you will want to install a web server, such as
<link xlink:href="&url.apache;">Apache</link>, and of course
<link xlink:href="&url.php.downloads;">PHP</link>. You will most likely
want to install a database as well, such as
<link xlink:href="&url.mysql.docs;">MySQL</link>.
</para>
<para>
You can either install these individually or choose a simpler way. Our
manual has <link linkend="install">installation instructions for
PHP</link> (assuming you already have some web server set up). If
you have problems with installing PHP yourself, we would suggest you ask
your questions on our <link xlink:href="&url.php.mailing-lists;">installation
mailing list</link>. If you choose to go on the simpler route, then
<link xlink:href="&url.installkits;">locate a pre-configured package</link>
for your operating system, which automatically installs all of these
with just a few mouse clicks. It is easy to setup a web server with PHP
support on any operating system, including MacOSX, Linux and Windows.
On Linux, you may find <link xlink:href="&url.rpmfind;">rpmfind</link> and
<link xlink:href="&url.rpmfind.pbone;">PBone</link> helpful for
locating RPMs. You may also want to visit <link
xlink:href="&url.apt-get;">apt-get</link> to find packages for Debian.
</para>
</section>

<section xml:id="tutorial.firstpage">
<info><title>Your first PHP-enabled page</title></info>
<simpara>
This tutorial assumes PHP is already installed.
Installation instructions can be found on the
<link xlink:href="&url.php.downloads;">download page</link>.
</simpara>
<para>
Create a file named <filename>hello.php</filename> and put it
in your web server's root directory (<varname>DOCUMENT_ROOT</varname>)
Create a file named <filename>hello.php</filename>
with the following content:
</para>
<para>
Expand All @@ -74,16 +37,24 @@
echo "Hello World!";

?>
]]>
</programlisting>
<simpara>
Using your terminal, navigate to the directory containing this file and
start a development server with the following command:
</simpara>
<programlisting role="shell">
<![CDATA[
php -S localhost:8000
]]>
</programlisting>
<simpara>
Use your browser to access the file with your web server's URL, ending
with the <literal>/hello.php</literal> file reference. When developing locally this
URL will be something like <literal>http://localhost/hello.php</literal>
or <literal>http://127.0.0.1/hello.php</literal> but this depends on the
web server's configuration. If everything is configured correctly, this
file will be parsed by PHP and you will see the "Hello World" output displayed
in your browser.
with the <literal>/hello.php</literal> file reference.
According to the previous command executed, the URL will be
<literal>http://localhost:8000/hello.php</literal>.
If everything is configured correctly, this file will be parsed by PHP
and you will see the "Hello World!" output displayed in your browser.
</simpara>
<simpara>
PHP can be embedded within a normal HTML web page. That means inside your HTML document
Expand Down Expand Up @@ -130,20 +101,7 @@ echo "Hello World!";
to pass on to PHP. Think of this as a normal HTML file which happens to have
a set of special tags available to you that do a lot of interesting things.
</para>
<para>
If you tried this example and it did not output anything, it prompted
for download, or you see the whole file as text, chances are that the
server you are on does not have PHP enabled, or is not configured properly.
Ask your administrator to enable it for you using the
<link linkend="install">Installation</link> chapter
of the manual. If you are developing locally, also read the
installation chapter to make sure everything is configured
properly. Make sure that you access the file via http with the server
providing you the output. If you just call up the file from your file
system, then it will not be parsed by PHP. If the problems persist anyway,
do not hesitate to use one of the many
<link xlink:href="&url.php.support;">PHP support</link> options.
</para>

<para>
The point of the example is to show the special PHP tag format.
In this example we used <literal>&lt;?php</literal> to indicate the
Expand Down Expand Up @@ -206,7 +164,11 @@ echo "Hello World!";
<info><title>Get system information from PHP</title></info>
<programlisting role="php">
<![CDATA[
<?php phpinfo(); ?>
<?php

phpinfo();

?>
]]>
</programlisting>
</example>
Expand Down Expand Up @@ -242,7 +204,9 @@ echo "Hello World!";
<programlisting role="php">
<![CDATA[
<?php

echo $_SERVER['HTTP_USER_AGENT'];

?>
]]>
</programlisting>
Expand Down Expand Up @@ -283,9 +247,11 @@ Mozilla/5.0 (Linux) Firefox/112.0
<programlisting role="php">
<![CDATA[
<?php

if (str_contains($_SERVER['HTTP_USER_AGENT'], 'Firefox')) {
echo 'You are using Firefox.';
}

?>
]]>
</programlisting>
Expand Down