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 The C extension is only compatible and useful for **PHP5**. 59 60Twig comes with a C extension that enhances the performance of the Twig 61runtime engine; install it like any other PHP extensions: 62 63.. code-block:: bash 64 65 cd ext/twig 66 phpize 67 ./configure 68 make 69 make install 70 71.. note:: 72 73 You can also install the C extension via PEAR (note that this method is 74 deprecated and newer versions of Twig are not available on the PEAR 75 channel): 76 77 .. code-block:: bash 78 79 pear channel-discover pear.twig-project.org 80 pear install twig/CTwig 81 82For Windows: 83 841. Setup the build environment following the `PHP documentation`_ 852. Put Twig's C extension source code into ``C:\php-sdk\phpdev\vcXX\x86\php-source-directory\ext\twig`` 863. Use the ``configure --disable-all --enable-cli --enable-twig=shared`` command instead of step 14 874. ``nmake`` 885. Copy the ``C:\php-sdk\phpdev\vcXX\x86\php-source-directory\Release_TS\php_twig.dll`` file to your PHP setup. 89 90.. tip:: 91 92 For Windows ZendServer, ZTS is not enabled as mentioned in `Zend Server 93 FAQ`_. 94 95 You have to use ``configure --disable-all --disable-zts --enable-cli 96 --enable-twig=shared`` to be able to build the twig C extension for 97 ZendServer. 98 99 The built DLL will be available in 100 ``C:\\php-sdk\\phpdev\\vcXX\\x86\\php-source-directory\\Release`` 101 102Finally, enable the extension in your ``php.ini`` configuration file: 103 104.. code-block:: ini 105 106 extension=twig.so #For Unix systems 107 extension=php_twig.dll #For Windows systems 108 109And from now on, Twig will automatically compile your templates to take 110advantage of the C extension. Note that this extension does not replace the 111PHP code but only provides an optimized version of the 112``\Twig\Template::getAttribute()`` method. 113 114.. _`download page`: https://github.com/twigphp/Twig/tags 115.. _`Composer`: https://getcomposer.org/download/ 116.. _`PHP documentation`: https://wiki.php.net/internals/windows/stepbystepbuild 117.. _`Zend Server FAQ`: https://www.zend.com/en/products/server/faq#faqD6 118