1Installation
2============
3
4You have multiple ways to install Twig.
5
6Installing the Twig PHP package
7-------------------------------
8
9Installing via Composer (recommended)
10~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11
12Install `Composer`_ and run the following command to get the latest version:
13
14.. code-block:: bash
15
16    composer require twig/twig:~1.0
17
18Installing from the tarball release
19~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20
211. Download the most recent tarball from the `download page`_
222. Verify the integrity of the tarball http://fabien.potencier.org/article/73/signing-project-releases
233. Unpack the tarball
244. Move the files somewhere in your project
25
26Installing the development version
27~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28
29.. code-block:: bash
30
31    git clone git://github.com/twigphp/Twig.git
32
33Installing the PEAR package
34~~~~~~~~~~~~~~~~~~~~~~~~~~~
35
36.. note::
37
38    Using PEAR for installing Twig is deprecated and Twig 1.15.1 was the last
39    version published on the PEAR channel; use Composer instead.
40
41.. code-block:: bash
42
43    pear channel-discover pear.twig-project.org
44    pear install twig/Twig
45
46Installing the C extension
47--------------------------
48
49.. versionadded:: 1.4
50    The C extension was added in Twig 1.4.
51
52.. note::
53
54    The C extension is **optional** but it brings some nice performance
55    improvements. Note that the extension is not a replacement for the PHP
56    code; it only implements a small part of the PHP code to improve the
57    performance at runtime; you must still install the regular PHP code.
58
59Twig comes with a C extension that enhances the performance of the Twig
60runtime engine; install it like any other PHP extensions:
61
62.. code-block:: bash
63
64    cd ext/twig
65    phpize
66    ./configure
67    make
68    make install
69
70.. note::
71
72    You can also install the C extension via PEAR (note that this method is
73    deprecated and newer versions of Twig are not available on the PEAR
74    channel):
75
76    .. code-block:: bash
77
78        pear channel-discover pear.twig-project.org
79        pear install twig/CTwig
80
81For Windows:
82
831. Setup the build environment following the `PHP documentation`_
842. Put Twig's C extension source code into ``C:\php-sdk\phpdev\vcXX\x86\php-source-directory\ext\twig``
853. Use the ``configure --disable-all --enable-cli --enable-twig=shared`` command instead of step 14
864. ``nmake``
875. Copy the ``C:\php-sdk\phpdev\vcXX\x86\php-source-directory\Release_TS\php_twig.dll`` file to your PHP setup.
88
89.. tip::
90
91    For Windows ZendServer, ZTS is not enabled as mentioned in `Zend Server
92    FAQ`_.
93
94    You have to use ``configure --disable-all --disable-zts --enable-cli
95    --enable-twig=shared`` to be able to build the twig C extension for
96    ZendServer.
97
98    The built DLL will be available in
99    ``C:\\php-sdk\\phpdev\\vcXX\\x86\\php-source-directory\\Release``
100
101Finally, enable the extension in your ``php.ini`` configuration file:
102
103.. code-block:: ini
104
105    extension=twig.so #For Unix systems
106    extension=php_twig.dll #For Windows systems
107
108And from now on, Twig will automatically compile your templates to take
109advantage of the C extension. Note that this extension does not replace the
110PHP code but only provides an optimized version of the
111``Twig_Template::getAttribute()`` method.
112
113.. _`download page`:     https://github.com/twigphp/Twig/tags
114.. _`Composer`:          https://getcomposer.org/download/
115.. _`PHP documentation`: https://wiki.php.net/internals/windows/stepbystepbuild
116.. _`Zend Server FAQ`:   http://www.zend.com/en/products/server/faq#faqD6
117