svn: /pear/peardoc/trunk/en/package/configuration/config/ avail-container/apache.xml examples/apache-read-config.txt examples/apache-read.php examples/apache-write.out examples/apache-write.php
[email protected] (Christian Weiske) Thu, 03 Mar 2011 08:33:01 +0000
| Newsgroups | php.pear.doc |
|---|---|
| Message-ID | <[email protected]> |
cweiske Thu, 03 Mar 2011 08:33:01 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=308885
Log:
examples for the apache config container
Changed paths:
U pear/peardoc/trunk/en/package/configuration/config/avail-container/apache.xml
A pear/peardoc/trunk/en/package/configuration/config/examples/apache-read-config.txt
U pear/peardoc/trunk/en/package/configuration/config/examples/apache-read.php
A pear/peardoc/trunk/en/package/configuration/config/examples/apache-write.out
U pear/peardoc/trunk/en/package/configuration/config/examples/apache-write.php
Modified: pear/peardoc/trunk/en/package/configuration/config/avail-container/apache.xml
===================================================================
--- pear/peardoc/trunk/en/package/configuration/config/avail-container/apache.xml 2011-03-03 08:32:38 UTC (rev 308884)
+++ pear/peardoc/trunk/en/package/configuration/config/avail-container/apache.xml 2011-03-03 08:33:01 UTC (rev 308885)
@@ -13,8 +13,19 @@
this container.
</para>
- <example>
- <title>Writing an apache configuration file</title>
+
+ <section>
+ <info>
+ <title>Writing an apache configuration file</title>
+ </info>
+
+ <para>
+ This example script will create a new apache configuration file
+ for a virtual host. It first adds a
+ <literal>Listen</literal> directive
+ and then a virtual host section containing its settings.
+ </para>
+
<programlisting role="php">
<xi:include parse="text"
xmlns:xi="http://www.w3.org/2001/XInclude"
@@ -23,20 +34,60 @@
<xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback>
</xi:include>
</programlisting>
- </example>
+ <example>
+ <title>Generated configuration file</title>
+ <programlisting role="ini">
+ <xi:include parse="text"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ href="&package.configuration.config.examples.apache-write.txt;"
+ >
+ <xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback>
+ </xi:include>
+ </programlisting>
+ </example>
- <example>
- <title>Generated configuration file</title>
- <programlisting role="ini">
- <xi:include parse="text"
- xmlns:xi="http://www.w3.org/2001/XInclude"
- href="&package.configuration.config.examples.apache-write.txt;"
- >
- <xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback>
- </xi:include>
- </programlisting>
- </example>
+ </section>
- <!-- FIXME: example file, example load, example save -->
+
+
+ <section>
+ <info>
+ <title>Reading an existing config file</title>
+ </info>
+
+ <para>
+ Our task is to open an existing Apache configuration file and
+ extract all <literal>Listen</literal> directives from it, using
+ the container's
+ <link linkend="package.configuration.config.config-container.getitem">getItem</link>
+ method.
+ </para>
+
+ <example>
+ <title>Config file</title>
+ <programlisting role="ini">
+ <xi:include parse="text"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ href="&package.configuration.config.examples.apache-read-config.txt;"
+ >
+ <xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback>
+ </xi:include>
+ </programlisting>
+ </example>
+
+ <example>
+ <title>PHP script</title>
+ <programlisting role="php">
+ <xi:include parse="text"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ href="&package.configuration.config.examples.apache-read.php;"
+ >
+ <xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback>
+ </xi:include>
+ </programlisting>
+ </example>
+
+ </section>
+
</section>
Added: pear/peardoc/trunk/en/package/configuration/config/examples/apache-read-config.txt
===================================================================
--- pear/peardoc/trunk/en/package/configuration/config/examples/apache-read-config.txt (rev 0)
+++ pear/peardoc/trunk/en/package/configuration/config/examples/apache-read-config.txt 2011-03-03 08:33:01 UTC (rev 308885)
@@ -0,0 +1,24 @@
+# If you just change the port or add more ports here, you will likely also
+# have to change the VirtualHost statement in
+# /etc/apache2/sites-enabled/000-default
+# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
+# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
+# README.Debian.gz
+
+NameVirtualHost *:80
+Listen 80
+Listen 82
+
+<IfModule mod_ssl.c>
+ # If you add NameVirtualHost *:443 here, you will also have to change
+ # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
+ # to <VirtualHost *:443>
+ # Server Name Indication for SSL named virtual hosts is currently not
+ # supported by MSIE on Windows XP.
+ Listen 443
+</IfModule>
+
+<IfModule mod_gnutls.c>
+ Listen 443
+</IfModule>
+
Modified: pear/peardoc/trunk/en/package/configuration/config/examples/apache-read.php
===================================================================
--- pear/peardoc/trunk/en/package/configuration/config/examples/apache-read.php 2011-03-03 08:32:38 UTC (rev 308884)
+++ pear/peardoc/trunk/en/package/configuration/config/examples/apache-read.php 2011-03-03 08:33:01 UTC (rev 308885)
@@ -1,3 +1,18 @@
<?php
+require_once 'Config.php';
+$file = dirname(__FILE__) . '/apache-read-config.txt';
+
+$conf = new Config();
+$root = $conf->parseConfig($file, 'apache');
+if (PEAR::isError($root)) {
+ echo 'Error reading config: ' . $root->getMessage() . "\n";
+ exit(1);
+}
+
+$i = 0;
+while ($item = $root->getItem('directive', 'Listen', null, null, $i++)) {
+ echo $item->name . ': ' . $item->content . "\n";
+}
+
?>
\ No newline at end of file
Added: pear/peardoc/trunk/en/package/configuration/config/examples/apache-write.out
===================================================================
--- pear/peardoc/trunk/en/package/configuration/config/examples/apache-write.out (rev 0)
+++ pear/peardoc/trunk/en/package/configuration/config/examples/apache-write.out 2011-03-03 08:33:01 UTC (rev 308885)
@@ -0,0 +1,7 @@
+Listen 82
+
+# My virtual host
+<VirtualHost 127.0.0.1:82>
+ DocumentRoot /usr/share/www
+ ServerName my-pear.example.org
+</VirtualHost>
Modified: pear/peardoc/trunk/en/package/configuration/config/examples/apache-write.php
===================================================================
--- pear/peardoc/trunk/en/package/configuration/config/examples/apache-write.php 2011-03-03 08:32:38 UTC (rev 308884)
+++ pear/peardoc/trunk/en/package/configuration/config/examples/apache-write.php 2011-03-03 08:33:01 UTC (rev 308885)
@@ -3,8 +3,11 @@
$conf = new Config();
$root = $conf->getRoot();
+
+$root->createDirective('Listen', '82');
+$root->createBlank();
+
$root->createComment('My virtual host');
-
$vhost = $root->createSection('VirtualHost', array('127.0.0.1:82'));
$vhost->createDirective('DocumentRoot', '/usr/share/www');
$vhost->createDirective('ServerName', 'my-pear.example.org');