# Installation
You have multiple ways to install Twig.
### Installing the Twig PHP package
### Installing via Composer (recommended)
Install [Composer](https://getcomposer.org/download/) [https://getcomposer.org/download/] and run the following command to get the latest version:
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>composer require twig/twig:~1.0
</pre></div></td></tr></table>
### Installing from the tarball release
1. Download the most recent tarball from the [download page](https://github.com/twigphp/Twig/tags) [https://github.com/twigphp/Twig/tags]
1. Verify the integrity of the tarball [http://fabien.potencier.org/article/73/signing-project-releases](http://fabien.potencier.org/article/73/signing-project-releases)
1. Unpack the tarball
1. Move the files somewhere in your project
### Installing the development version
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>git clone git://github.com/twigphp/Twig.git
</pre></div></td></tr></table>
### Installing the PEAR package
Note
Using PEAR for installing Twig is deprecated and Twig 1.15.1 was the lastversion published on the PEAR channel; use Composer instead.
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2</pre></div></td><td class="code"><div class="highlight"><pre>pear channel-discover pear.twig-project.org
pear install twig/Twig
</pre></div></td></tr></table>
### Installing the C extension
New in version 1.4: The C extension was added in Twig 1.4.
Note
The C extension is **optional** but it brings some nice performanceimprovements. Note that the extension is not a replacement for the PHPcode; it only implements a small part of the PHP code to improve theperformance at runtime; you must still install the regular PHP code.
Twig comes with a C extension that enhances the performance of the Twigruntime engine; install it like any other PHP extensions:
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5</pre></div></td><td class="code"><div class="highlight"><pre>cd ext/twig
phpize
./configure
make
make install
</pre></div></td></tr></table>
Note
You can also install the C extension via PEAR (note that this method isdeprecated and newer versions of Twig are not available on the PEARchannel):
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2</pre></div></td><td class="code"><div class="highlight"><pre>pear channel-discover pear.twig-project.org
pear install twig/CTwig
</pre></div></td></tr></table>
For Windows:
1. Setup the build environment following the [PHP documentation](https://wiki.php.net/internals/windows/stepbystepbuild) [https://wiki.php.net/internals/windows/stepbystepbuild]
1. Put Twig's C extension source code into `C:\php-sdk\phpdev\vcXX\x86\php-source-directory\ext\twig`
1. Use the `configure --disable-all --enable-cli --enable-twig=shared` command instead of step 14
1. `nmake`
1. Copy the `C:\php-sdk\phpdev\vcXX\x86\php-source-directory\Release_TS\php_twig.dll` file to your PHP setup.
Tip
For Windows ZendServer, ZTS is not enabled as mentioned in [Zend ServerFAQ](http://www.zend.com/en/products/server/faq#faqD6) [http://www.zend.com/en/products/server/faq#faqD6].
You have to use `configure --disable-all --disable-zts --enable-cli--enable-twig=shared` to be able to build the twig C extension forZendServer.
The built DLL will be available in`C:\\php-sdk\\phpdev\\vcXX\\x86\\php-source-directory\\Release`
Finally, enable the extension in your `php.ini` configuration file:
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2</pre></div></td><td class="code"><div class="highlight"><pre>extension=twig.so #For Unix systems
extension=php_twig.dll #For Windows systems
</pre></div></td></tr></table>
And from now on, Twig will automatically compile your templates to takeadvantage of the C extension. Note that this extension does not replace thePHP code but only provides an optimized version of the`Twig_Template::getAttribute()` method.
- Twig
- Introduction
- Installation
- Twig for Template Designers
- Twig for Developers
- Extending Twig
- Twig Internals
- Deprecated Features
- Recipes
- Coding Standards
- Tags
- autoescape
- block
- do
- embed
- extends
- filter
- flush
- for
- from
- if
- import
- include
- macro
- sandbox
- set
- spaceless
- use
- verbatim
- Filters
- abs
- batch
- capitalize
- convert_encoding
- date
- date_modify
- default
- escape
- first
- format
- join
- json_encode
- keys
- last
- length
- lower
- merge
- nl2br
- number_format
- raw
- replace
- reverse
- round
- slice
- sort
- split
- striptags
- title
- trim
- upper
- url_encode
- Functions
- attribute
- block
- constant
- cycle
- date
- dump
- include
- max
- min
- parent
- random
- range
- source
- template_from_string
- Tests
- constant
- defined
- divisible by
- empty
- even
- iterable
- null
- odd
- same as