Skip to content

Commit bc9eb63

Browse files
[TASK] Extension installation with composer (#5653)
* [TASK] Extension installation with composer Releases: main, 13.4, 12.4 * [TASK] Extension installation with composer Releases: main, 13.4, 12.4 * [TASK] Language checks Releases: main --------- Co-authored-by: Sarah McCarthy <[email protected]>
1 parent 927ca2b commit bc9eb63

File tree

5 files changed

+439
-21
lines changed

5 files changed

+439
-21
lines changed
Lines changed: 378 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,378 @@
1+
:navigation-title: Composer
2+
3+
.. include:: /Includes.rst.txt
4+
.. _extensions-composer:
5+
6+
========================================
7+
TYPO3 extension management with Composer
8+
========================================
9+
10+
.. seealso::
11+
For a beginner-friendly introduction on extension management with Composer,
12+
see:
13+
14+
* `Getting Started Guide: Working with extensions <https://docs.typo3.org/permalink/t3start:extensions-index>`_
15+
16+
.. contents:: Table of contents
17+
18+
.. _extensions-composer-installation:
19+
20+
Install or require an extension with Composer
21+
=============================================
22+
23+
Composer distinguishes between **requiring** and **installing** an
24+
extension. By default you can require any package registered on
25+
https://packagist.org/ and compatible with your current requirements.
26+
27+
.. _extensions-composer-require:
28+
29+
Composer require
30+
----------------
31+
32+
When you use the command `composer require` or its abbreviated, shortened version
33+
`composer req` the requirement will be added to the file :file:`composer.json` and Composer
34+
installs the latest version that satisfies the version constraints in
35+
:file:`composer.json`, and then writes the resolved version to :file:`composer.lock`.
36+
37+
For example, to install the extension :composer:`georgringer/news`:
38+
39+
.. code-block:: bash
40+
41+
# Install the news extension
42+
composer require georgringer/news
43+
44+
If necessary you can also require the extension by adding a version requirement:
45+
46+
.. code-block:: bash
47+
48+
# Install the news extension in version 12.3.0 or any minor level above
49+
composer require georgringer/news:"^12.3"
50+
51+
# Install the news extension from the main branch
52+
composer require georgringer/news:"dev-main"
53+
54+
.. seealso::
55+
56+
* `command "composer require" <https://getcomposer.org/doc/03-cli.md#require-r>`_
57+
* `"Writing Version Constraints" in the Composer documentation
58+
<https://getcomposer.org/doc/articles/versions.md#writing-version-constraints>`_
59+
for more version constraint examples.
60+
61+
62+
Composer will then download the extension into the :path:`vendor` folder and
63+
execute any additional installation steps.
64+
65+
You can now commit the files :file:`composer.json` and :file:`composer.lock`
66+
to `Git <https://docs.typo3.org/permalink/t3coreapi:version-control>`_.
67+
68+
.. _extensions-composer-install:
69+
70+
Composer install
71+
----------------
72+
73+
If the same project is installed on other systems — such as a co-worker’s
74+
computer or the production server (if you are working with
75+
`Git and Composer deployment <https://docs.typo3.org/permalink/t3coreapi:deployment-git-composer>`_) —
76+
you do not need to run `composer require` again. Instead, use
77+
`composer install` to install the exact versions defined in
78+
:file:`composer.lock`:
79+
80+
81+
.. code-block:: bash
82+
83+
git update
84+
85+
# Install versions that have been changed
86+
composer install
87+
88+
# Rerun the setup for all extensions
89+
vendor/bin/typo3 extension:setup
90+
91+
.. seealso::
92+
93+
* `command "composer install" <https://getcomposer.org/doc/03-cli.md#install-i>`_
94+
95+
.. _extensions-composer-list:
96+
97+
List extensions
98+
---------------
99+
100+
Just like in the TYPO3 core, extensions are individual Composer packages.
101+
You can list all installed packages, including extensions, using the following command:
102+
103+
.. code-block:: bash
104+
105+
composer info
106+
107+
This will display a list of all installed packages along with their names and version numbers.
108+
109+
.. seealso::
110+
111+
* `command "composer info" <https://getcomposer.org/doc/03-cli.md#show-info>`_
112+
113+
.. _extensions-composer-extension-setup:
114+
115+
Extension setup
116+
---------------
117+
118+
Many extensions make TYPO3-specific changes to your system that Composer cannot
119+
detect. For example, an extension might define its own
120+
database tables in the TCA or require static data to be imported.
121+
122+
123+
You can run the following command to set up specific or all extensions:
124+
125+
.. code-block:: bash
126+
127+
# Setup the extension with key "news"
128+
vendor/bin/typo3 extension:setup --extension=news
129+
130+
# Setup all extensions
131+
vendor/bin/typo3 extension:setup
132+
133+
You can also :ref:`Automate extension setup <extensions-composer-extension-setup>`.
134+
135+
.. tip::
136+
137+
The Composer package name (for example, `georgringer/news`) and the TYPO3
138+
extension key (for example `news`) are **not the same**.
139+
140+
The **extension key** is defined in the extension’s :file:`composer.json`
141+
under the key
142+
`extra.typo3/cms.extension-key <https://docs.typo3.org/permalink/t3coreapi:ext-composer-json-property-extension-key>`_.
143+
144+
145+
.. _extensions-composer-extension-setup-automate:
146+
147+
Automate extension setup
148+
------------------------
149+
150+
You can run the :ref:`extension setup command <extensions-composer-extension-setup>`
151+
automatically after each require / install / update command by adding it to
152+
the `script` section of your project's :file:`composer.json`:
153+
154+
.. literalinclude:: _repositories.json
155+
:caption: composer.json (Excerpt)
156+
157+
.. seealso::
158+
159+
* `Composer scripts <https://getcomposer.org/doc/articles/scripts.md>`_
160+
161+
.. _extensions-composer-installation-custom:
162+
163+
Installing a custom extension or site package via Composer
164+
==========================================================
165+
166+
In most projects there will be one special extension per site, called a site
167+
package, that contains the theme and configuration for that site.
168+
169+
There could also be custom extensions only for a specific domain in that
170+
project.
171+
172+
Both these types of extensions should be placed in the :path:`packages` folder
173+
and required in Composer as local (`@dev`) versions. This will create a symlink from
174+
:path:`packages` to :path:`vendor`, allowing the extensions to be used
175+
like any other package.
176+
177+
178+
#. Place the extension into the folder :path:`packages` so that its `composer.json`
179+
can be found at :file:`packages/ext_key/composer.json`
180+
#. Require the extension using Composer and specifying the `@dev` version:
181+
182+
.. code-block:: bash
183+
184+
# Require a custom site package
185+
composer require myvendor/my-site-package:"@dev"
186+
187+
# Require a custom extension
188+
composer require myvendor/my-local-extension:"@dev"
189+
190+
Composer install will work as described in
191+
:ref:`extensions-composer-install` if the extension is available on the system
192+
where you run the `composer install` command.
193+
194+
You will usually commit the
195+
files :file:`composer.json`, :file:`composer.lock` and the content of the
196+
:path:`packages` folder to the same Git repository.
197+
198+
.. seealso::
199+
200+
* `"Creating a site package", Getting started tutorial <https://docs.typo3.org/permalink/t3start:creating-a-site-package>`_
201+
* `"Site package installation", Site Package Tutorial <https://docs.typo3.org/permalink/t3sitepackage:extension-installation>`_
202+
* `Extension development <https://docs.typo3.org/permalink/t3coreapi:extension-development>`_
203+
204+
.. _extensions-composer-installation-source:
205+
206+
Installing extensions from a different source
207+
=============================================
208+
209+
You can define `Composer repositories <https://getcomposer.org/doc/05-repositories.md>`_
210+
to install packages (including TYPO3 extensions) from different sources like
211+
`Git <https://getcomposer.org/doc/05-repositories.md#vcs>`_, a `local
212+
path <https://getcomposer.org/doc/05-repositories.md#path>`_ and
213+
`Private Packagist <https://getcomposer.org/doc/05-repositories.md#private-packagist>`_.
214+
215+
After adding the repository to your project's :file:`composer.json`, you can
216+
require the extension using the standard `composer require` command.
217+
218+
.. literalinclude:: _codesnippets/_repositories.json
219+
:caption: composer.json (Excerpt)
220+
221+
.. _extensions-composer-update:
222+
223+
Extension update via Composer
224+
=============================
225+
226+
.. attention::
227+
228+
The command `composer update` cannot easily be reverted. We recommend
229+
using `Version control (Git) <https://docs.typo3.org/permalink/t3coreapi:version-control>`_
230+
and committing both files :file:`composer.json` and :file:`composer.lock` before
231+
running an update command.
232+
233+
If you are not using Git, make a backup of these two files before the update.
234+
235+
The following command updates all installed Composer packages (both TYPO3
236+
extensions and other PHP packages/libraries) to the newest version that the
237+
current constraints in your :file:`composer.json` allow. It will write the
238+
new versions to file :file:`composer.lock`:
239+
240+
.. code-block:: bash
241+
242+
# Warning: Make a backup of composer.json and composer.lock before proceeding!
243+
composer update
244+
245+
If you want to do a major Upgrade, for example from :composer:`georgringer/news`
246+
Version 11.x to 12.x, you can require that extension with a different version number:
247+
248+
.. code-block:: bash
249+
250+
# Attention make a backup of the composer.json and composer.lock first!!
251+
composer require georgringer/news:"^12"
252+
253+
.. seealso::
254+
255+
* `command "composer update" <https://getcomposer.org/doc/03-cli.md#update-u-upgrade>`_
256+
* `command "composer require" <https://getcomposer.org/doc/03-cli.md#require-r>`_
257+
* `"Writing Version Constraints" in the Composer documentation
258+
<https://getcomposer.org/doc/articles/versions.md#writing-version-constraints>`_
259+
260+
.. _extensions-composer-downgrade:
261+
262+
Downgrading an extension
263+
------------------------
264+
265+
If an extension does not work after upgrade you can downgrade the extension
266+
by requiring a specific version:
267+
268+
.. code-block:: bash
269+
270+
# Attention make a backup of the composer.json and composer.lock first!!
271+
composer require georgringer/news:"12.0.42"
272+
273+
The extension will remain locked to the specified version and will not be
274+
updated until you change the version constraint using the `composer require`
275+
command.
276+
277+
278+
.. _extensions-composer-update-revert:
279+
280+
Reverting extension updates
281+
---------------------------
282+
283+
As a last resort you can revert any changes you have made by restoring the files
284+
:file:`composer.json` and :file:`composer.lock` and running the command
285+
`composer install`:
286+
287+
.. code-block:: bash
288+
289+
# restore composer.json and composer.lock
290+
git stash
291+
292+
# Reinstall previously used versions
293+
composer install
294+
295+
.. seealso::
296+
297+
* `command "composer install" <https://getcomposer.org/doc/03-cli.md#install-i>`_
298+
299+
.. _extensions-composer-remove:
300+
301+
Removing an extension via Composer
302+
==================================
303+
304+
You can remove an extension requirement from your project's
305+
:file:`composer.json` by using the command `composer remove`, but bear in mind that the
306+
extension will only be uninstalled if it is no longer required by any
307+
of the installed packages.
308+
309+
.. code-block:: bash
310+
311+
# Check the extension is not in use first!
312+
# composer remove georgringer/news
313+
314+
Composer will not check if the extension is currently in use. Composer can only
315+
check if the extension is listed in the `require` section of the
316+
:file:`composer.json` file of another extension.
317+
318+
.. seealso::
319+
320+
* `command "composer remove" <https://getcomposer.org/doc/03-cli.md#remove-rm-uninstall>`_
321+
322+
323+
.. _extensions-composer-remove-used:
324+
325+
Check if the extension is in use
326+
--------------------------------
327+
328+
Manually verify whether the extension is still in use before uninstalling it.
329+
330+
* Does the extension have `Site sets <https://docs.typo3.org/permalink/t3coreapi:site-sets>`_
331+
that are required by a site configuration or another extension's site set?
332+
* Are you using any plugins or content elements provided by the extension?
333+
Tip: Extension :composer:`fixpunkt/backendtools` lists all plugins and
334+
content elements that are in use.
335+
* Have you included any TypoScript provided by the extension? Or tables
336+
defined by its TCA? Does it include `Middleware <https://docs.typo3.org/permalink/t3coreapi:request-handling>`_,
337+
`Console commands (CLI) <https://docs.typo3.org/permalink/t3coreapi:symfony-console-commands>`_
338+
or any other functionality that your project relies on?
339+
340+
.. _extensions-composer-remove-why:
341+
342+
Why an extension cannot be uninstalled
343+
--------------------------------------
344+
345+
If Composer refuses to remove an extension with `composer remove` you can
346+
run the following command to find out what other packages require the Extension
347+
you want to remove:
348+
349+
.. code-block:: bash
350+
351+
# Show which package requires the extension
352+
composer why georgringer/news
353+
354+
.. seealso::
355+
356+
* `command "composer why" <https://getcomposer.org/doc/03-cli.md#depends-why>`_
357+
358+
In very stubborn cases the following tricks can help:
359+
360+
Ensure you have a backup of the files :file:`composer.json` and
361+
:file:`composer.lock` or have committed them to Git.
362+
363+
Then delete the :path:`vendor` folder (it will be restored by Composer), delete
364+
:file:`composer.lock` and run `composer install`. This will reinstall
365+
your requirements from your :file:`composer.json`. Deleting the Composer cache
366+
first might also help.
367+
368+
.. code-block:: bash
369+
370+
composer clear-cache
371+
rm -rf vendor/
372+
rm composer.lock
373+
composer install
374+
375+
.. seealso::
376+
377+
* `command "composer install" <https://getcomposer.org/doc/03-cli.md#install-i>`_
378+
* `command "composer clear-cache" <https://getcomposer.org/doc/03-cli.md#clear-cache-clearcache-cc>`_
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"repositories": [
3+
{
4+
"type": "vcs",
5+
"url": "[email protected]:vendor/my-private-repo.git"
6+
},
7+
{
8+
"type": "artifact",
9+
"url": "path/to/directory/with/zips/"
10+
},
11+
{
12+
"type": "path",
13+
"url": "../../local_packages/my_custom_extension/"
14+
},
15+
{
16+
"type": "path",
17+
"url": "site_packages/*"
18+
}
19+
]
20+
}

0 commit comments

Comments
 (0)