The TYPO3 community loves the composer, Do you too? In modern TYPO3 development & deployment, a composer is an important tool for productive and quality work. Here, I want to write an easy guide from beginners to advanced level TYPO3 composers.
Composer - A dependency manager for PHP, It's a widely accepted tool by the PHP community. Do you like how UNIX based systems easily install and update software using simple commands on CLI? Like `apt-get install package`, similarly in TYPO3 `composer install extension`. Then, You will also like the TYPO3 composer to easily install and update your TYPO3 as well as extensions too.
A creative artist works on his next composition because he was not satisfied with his previous one.- Dmitri Shostakovich
What/Why/How is the Composer?
Definition of Composer
The official definition, “Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.”
This thought isn't new and the Composer is firmly derived by the node's npm and ruby's bundler.
Let’s say:
- You've got a project that relies upon various libraries.
- A portion of those libraries relies upon other libraries.
Composer:
- Empowers you to use the libraries you rely upon.
- Discovers which renditions of which packages can and should be installed, and installs them (which means it downloads them to your project).
- You can upgrade every dependency with a single command.
If you don’t know, what’s composer is, then I recommend you get familiarized with the composer by official documentation. https://getcomposer.org/
Why: Composer vs Non-Composer
Using a composer, Your life will be saved with productive and quality work. Here are some important benefits of a composer as below.
- Dependable Access
- Streamlined Build Process
- Full Support for Docker
- Secure Solution
- Dissemination and Sharing
- Artifactory High Availability
- Support and Monitoring
- General, End-to-End Solution
Of course, to learn about composer based TYPO3 installation will require bit learning curves, but I’m sure your hard work will pay off.
At our regular #T3POLL series. Recently, I’ve tried to know the people’s opinion on TYPO3 composer support in TYPO3 projects at different social media platforms.
At one of the active groups of TYPO3 at facebook, people loved “Composer”. Good thing is that most people loved and recommended the Composer based TYPO3. You can see a poll result and comments at https://www.facebook.com/groups/typo3/permalink/3211414308906535/
How TYPO3 Composer Works?
You will need to understand two perspectives: client and server.
Composer Client
That’s very simple - The end users like you and me who used the composer using our CLI command line ;)
Composer Packages Server
There are two types of composer packagist repositories.
Public Packages Composer Server
Packagist.org Guys provide a public repository for OpenSource projects. By default, Composer tries to find the packages from such a public composer server.
Private Packages Composer Server
Let's see how to build Your Private TYPO3 Composer Packages & Server. When we launched our t3planet.com venture, One of the first demands from our customers was Support Composer for premium TYPO3 products too.
Team T3Planet took the challenge and was super excited to make TYPO3 Satis Private packages for Composer.
At the moment, For your private TYPO3 packages and extensions, we have two solutions;
Option 1.SaaS Solution by Packagist.com
Option 2. Self-Hosted Solution with Satis
How can we set up TYPO3 Private Packages?
- Step 1. What is Satis? Installation of Satis
- Step 2. Configure satis.json
- Step 3. Generate Satis For Composer Packages
- Step 4. Test-drive with Your TYPO3 Private Packages with Composer
- Step 5. Webhook between your TYPO3 Private Repositories & Satis
- Step 6. Setup Cron to Crawl Automatic TYPO3 Private Packages
- Step 7. Secure Your TYPO3 Private Packages at Composer-Server
- Bonus! Individual TYPO3 Package’s Authentication Access
Do you want to get answers to the above questions and setup?
Explore our popular article 7 Easy Steps to Satis - TYPO3 Private Packages for Composer
What’re Packages in Composer?
Are there any resources to learn TYPO3 Composer?
TYPO3 have many resources to learn composer, I recommend to read my recent blog 10 Resources to Learn TYPO3 Composer
Which are Best TYPO3 Local Development?
Recently I wrote a blog for the same, Read at 10 Best TYPO3 Local Development Tools & Techniques
How to Install/Update Composer?
What is the Prerequisite for TYPO3 Composer?
To install and configure the composer, Please make sure you have at least PHP 7.2 or later
// Check your PHP version, It should be 7.2 or later
php -v
How to Install TYPO3 Composer?
To install the composer is very easy, Choose your favorite way to install and configure a composer from below options.
Option 1. Official Guide from Getcomposer.org
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Option 2. Using Standard Application Install
sudo apt-get update
sudo apt-get install composer
composer -v
Option 3. Using Curl + Application Get
sudo apt-get update
sudo apt-get install curl php-cli git
curl -sS https://getcomposer.org/installer | sudo php - --install-dir = / usr / local / bin --filename = composer
Enable & configure Composer-Command
Once you install composer, I recommend to run the following commands, so you can run “composer command”
// Move composer.phar to bin to run as composer command
mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer
// Before above commands
/usr/local/bin/composer -v
// After the above commands
composer -v
How to update TYPO3 Composer version?
Composer guys continuously release new versions, so by the time, you can run a self-update command to keep an up-to-date version of the composer (and of course, keep learning what’s new in composer).
// Update your composer version to the latest
composer self-update.
TYPO3 Composer Commands
You should learn TYPO3 composer commands, Try to practice at least these commands.
composer update vendorname/extensionname
composer require vendorname/extensionname
composer install vendorname/extensionname
composer remove vendorname/extensionname
composer outdated
Step-by-step Guide to TYPO3 Composer Install
You can initiate, create, and install TYPO3 using composer in various ways, here are some of them as below.
Option 1: (Recommend) Create TYPO3 Composer Project
// Go to your www folder
cd www
// Install latest TYPO3 v10 (It will create “YourProjectName” folder with downloading TYPO3 code)
composer create-project “typo3/cms-base-distribution:^10” YourProjectName --prefer-dist
// Create FIRST_INSTALL file
touch public/FIRST_INSTALL
Once you everything setup, TYPO3 composer installation directory structure will be looks like this;
├── .gitignore
├── composer.json
├── composer.lock
├── LICENSE
├── public
├── README.md
├── var
└── vendor
Option 2: Standard Composer Require
composer require typo3/cms
Option 3: Using TYPO3 Git Clone
When you work as a team, Your partner can easily download and install using TYPO3 Git.
git clone https://github.com/example/example-site
cd example-site
composer install
Option 4: Custom TYPO3 Composer Install
get.TYPO3.org is providing cool features as a helper of TYPO3 composer to choose what TYPO3 packages should be included or excluded.
Download your custom and favorite TYPO3 Composer Packages using the TYPO3 packages helper tool. Explore TYPO3 Composer Helper.
By default, TYPO3 has three kinds of TYPO3 composer packages as below.
TYPO3 Full Composer
composer require "typo3/cms-about:^10.4" "typo3/cms-adminpanel:^10.4" "typo3/cms-backend:^10.4" "typo3/cms-belog:^10.4" "typo3/cms-beuser:^10.4" "typo3/cms-core:^10.4" "typo3/cms-dashboard:^10.4" "typo3/cms-extbase:^10.4" "typo3/cms-extensionmanager:^10.4" "typo3/cms-filelist:^10.4" "typo3/cms-fluid:^10.4" "typo3/cms-fluid-styled-content:^10.4" "typo3/cms-form:^10.4" "typo3/cms-frontend:^10.4" "typo3/cms-impexp:^10.4" "typo3/cms-info:^10.4" "typo3/cms-install:^10.4" "typo3/cms-lowlevel:^10.4" "typo3/cms-opendocs:^10.4" "typo3/cms-recordlist:^10.4" "typo3/cms-recycler:^10.4" "typo3/cms-redirects:^10.4" "typo3/cms-reports:^10.4" "typo3/cms-rte-ckeditor:^10.4" "typo3/cms-scheduler:^10.4" "typo3/cms-seo:^10.4" "typo3/cms-setup:^10.4" "typo3/cms-tstemplate:^10.4" "typo3/cms-viewpage:^10.4"
TYPO3 Minimal Composer
composer require "typo3/cms-backend:^10.4" "typo3/cms-core:^10.4" "typo3/cms-extbase:^10.4" "typo3/cms-extensionmanager:^10.4" "typo3/cms-filelist:^10.4" "typo3/cms-fluid:^10.4" "typo3/cms-frontend:^10.4" "typo3/cms-install:^10.4" "typo3/cms-recordlist:^10.4"
TYPO3 Default Composer
composer require "typo3/cms-about:^10.4" "typo3/cms-adminpanel:^10.4" "typo3/cms-backend:^10.4" "typo3/cms-belog:^10.4" "typo3/cms-beuser:^10.4" "typo3/cms-core:^10.4" "typo3/cms-dashboard:^10.4" "typo3/cms-extbase:^10.4" "typo3/cms-extensionmanager:^10.4" "typo3/cms-filelist:^10.4" "typo3/cms-fluid:^10.4" "typo3/cms-fluid-styled-content:^10.4" "typo3/cms-form:^10.4" "typo3/cms-frontend:^10.4" "typo3/cms-impexp:^10.4" "typo3/cms-info:^10.4" "typo3/cms-install:^10.4" "typo3/cms-lowlevel:^10.4" "typo3/cms-opendocs:^10.4" "typo3/cms-recordlist:^10.4" "typo3/cms-recycler:^10.4" "typo3/cms-redirects:^10.4" "typo3/cms-reports:^10.4" "typo3/cms-rte-ckeditor:^10.4" "typo3/cms-scheduler:^10.4" "typo3/cms-seo:^10.4" "typo3/cms-setup:^10.4" "typo3/cms-tstemplate:^10.4" "typo3/cms-viewpage:^10.4"
Option 5: Docker & DDEV TYPO3 Composer Install
Docker and DDEV guys can initiate the TYPO3 project with;
mkdir MyTYPO3Site
cd MyTYPO3Site
ddev config --project-type=typo3 --docroot=public --create-docroot=true
ddev start
ddev composer create "typo3/cms-base-distribution:^10" --prefer-dist
ddev exec touch public/FIRST_INSTALL
ddev launch
IMPORTANT:
Please make sure to point your document root to the "public" folder. Otherwise, you should access your TYPO3 site eg., yourdomain.com/public/
Mathias has created cool TYPO3 composer video at, Watch now
How to composer update TYPO3 core?
That’s the beauty of Composer within a single command, Your TYPO3 core will be updated ;)
// Update TYPO3 core to latest version
composer update typo3/cms --with-all-dependencies
// Update TYPO3 to particular version
composer update typo3/cms ^10.4
Sample Composer.json
Composer.json contains two major things:
- The vendor name is Vendorname
- The extension key is my_extension
Subsequently:
- The namespace will be Vendorname\MyExtension
- The package name will be vendorname/my-extension
// Sample composer.json
{
"name": "vendor/ext-key",
"description": "Basic composer.json attributes",
"keywords": ["typo3", "extension", "composer"],
"homepage": "http://yoursite.com",
"authors": [
{
"name": "Your Name",
"email": "YourEmail"
}
],
"license": "GPL-2.0-or-later",
"type": "typo3-cms-extension",
"require": {
"typo3/cms-core": "^9.5 || ^10.4",
"typo3/cms-frontend": "^9.5 || ^10.3"
},
"replace": {
"typo3-ter/ext-key": "self.version"
},
"autoload": {
"psr-4": {
"Vendor\\ExtKey\\": "Classes/"
}
},
"extra": {
"typo3/cms": {
"extension-key": "ext_key"
}
}
}
Do you know?
How's composer.json for TYPO3 core? Explore TYPO3 core’s composer.json
TYPO3 is Flexible with Split-tree
The TYPO3 core team made a great decision by splitting the whole TYPO3, It means - TYPO3’s all system extensions are independent.
The beauty of Split-tree, You can easily independently install and configure each system TYPO3 extensions with Composer.
Starting with TYPO3 v9.0, each system extension can be installed separately (not activated yet) via the composer using “typo3/cms-{extension-name}” as in “typo3/cms-backend”.
// Explore the TYPO3’s system extensions
tree web/typo3/sysext -L 1
public/typo3/sysext
├── about
├── backend
├── belog
├── beuser
├── core
├── dashboard
├── extbase
├── extensionmanager
├── felogin
├── filelist
├── fluid
├── fluid_styled_content
├── form
├── frontend
├── impexp
├── indexed_search
├── info
├── install
├── recordlist
├── reports
├── rte_ckeditor
├── seo
├── setup
├── sys_note
├── t3editor
├── tstemplate
└── viewpage
27 directories, 0 files
Explore Split-tree of TYPO3 v9
// typo3/minimal
tree . -L 4 -I vendor
.
├── composer.json
├── composer.lock
└── public
├── index.php
└── typo3
├── index.php
├── install.php
└── sysext
├── backend
├── core
├── documentation
├── extbase
├── extensionmanager
├── filelist
├── fluid
├── frontend
├── install
├── lang
├── recordlist
└── saltedpasswords
15 directories, 5 files
Explore Split-tree of TYPO3 8 LTS
// typo3/minimal
tree . -L 3 -I vendor
.
├── composer.json
├── composer.lock
└── typo3
└── sysext
├── backend
├── core
├── cshmanual
├── extbase
├── extensionmanager
├── filelist
├── fluid
├── frontend
├── install
├── lang
├── recordlist
├── saltedpasswords
└── sv
15 directories, 2 files
How to Install/Update TYPO3 and Extensions?
So, You want to install the TYPO3 Extension from TYPO3 extensions repository (TER) using your composer based TYPO3 installation.
Step 1. Go to TYPO3 Extension Page eg., https://extensions.typo3.org/extension/ns_backup
Step 2. Find composer Support eg., composer req nitsan/ns-backup
Sometimes, if a particular developer did not link TER and Packagist, then you can directly find at Packagist with TYPO3-CMS-Extension
Practical Example to Install Extension using TYPO3 Composer.
// Syntax
composer require <packagename>
./vendor/bin/typo3 extension:activate <extension key>
// Example
composer require georgringer/news
./vendor/bin/typo3 extension:activate news
// After Installation of TYPO3 Extension, Check your composer.json should add an entry of your installed TYPO3 extension
"require": {
"typo3/cms": "~7.6.0",
"georgringer/news": "^4.0.0"
}
How to TYPO3 extensions composer update?
Whenever you want to update your particular TYPO3 extension, You just need to run “composer update” command as below.
// Remove your TYPO3 extension
composer remove nitsan/ns-backup
Tip: Don’t forget to commit your updated composer.lock to your version control system.
How to provide support for a composer to my TYPO3 extensions?
Sounds good decision my friend, In the TYPO3 community, most of the TYPO3 developers provide support for composers.
And, That’s quite easy, Here are the quick steps to provide support for a composer to your TYPO3 extensions.
Step 1. Prepare composer.json
At your TYPO3 extension, create a composer.json file, Here is the working sample.
// composer.json
{
"name": "nitsan/ns-backup",
"type": "typo3-cms-extension",
"description": "First-ever feature-rich TYPO3 backup solution with manual and scheduled backup.",
"homepage": "https://extensions.typo3.org/extension/ns_backup/",
"license": "GPL-2.0+",
"keywords": [
"TYPO3",
"Backup"
],
"support": {
"issues": "https://github.com/nitsan-technologies/ns_backup/issues"
},
"require": {
"typo3/cms-core": ">=8.0.0"
},
"autoload": {
"psr-4": {
"NITSAN\\NsBackup\\": "Classes"
}
},
"replace": {
"typo3-ter/ns-backup": "self.version"
},
"config": {
"vendor-dir": ".Build/vendor/",
"bin-dir": ".Build/bin/"
},
"extra": {
"typo3/cms": {
"cms-package-dir": "{$vendor-dir}/typo3/cms",
"web-dir": ".Build/public",
"extension-key": "ns_backup"
}
}
}
Step 2. Set up your Git repository
You will need to push your TYPO3 extension at your cool Git tools like Github, Gitlab, etc.
Step 3. Connect your Git to Packagist
Login to https://packagist.org/
Submit your package at https://packagist.org/packages/submit
Step 4. Get Packagist API Token
Go to https://packagist.org/profile/ and Composer API Token
Step 5. Set API at Git Repository Webhook
Now, configure Composer API token to your Git repository. Now whenever you will release the next version, then a new version will automatically grab by Packagist.org.
Step 6. TER Enable TYPO3 Composer
Last but not least, If you have uploaded your TYPO3 extension at TER, then you just need to enable the TYPO3 composer.
I recommend reading one my famous blog Publish and Maintain your TER TYPO3 Extensions with Composer + Git + Packagist
Helpful Learn TYPO3 Composer Blogs
Apart from TYPO3 official documentation, Please find some of the most popular blogs which will help you to learn TYPO3 composer from beginners to advanced.
Tips & Tricks on TYPO3 Composer
Most of the topics on the TYPO3 composer are covered in this article, But still want to share some bonus tips as below.
Tip #1 No-run composer at Production
Never run composer in production or live TYPO3 site eg., Update TYPO3 extensions. There is a chance to break the installation. It’s always good practice to update or maintain stuff complete at the local or staging server.
Tip #2 Set PHP version
As a part of best practice, I recommend to always define “PHP version” in your composer to make compatibility with different server’s PHP versions.
// composer.json
"config": {
"platform": {
"php": "7.2"
},
},
Tip #3 Understand the Importance of composer.lock
After updating any packages, you always should commit your composer.lock to your version control system and your co-workers should run composer install after checking out the updates.
Tip #4 Update Single-package vs All-package
Please be careful while you update your TYPO3 Instance. If you are sure, all your package’s dependencies are accurate then you can update all-packages on one command, otherwise you should consider updating one by one package - TYPO3 extension.
// Update ALL Packages
composer update
// Update One-by-one Single Package
composer update vendor/packagename
Tip #5 Composer Update TYPO3 Sysext at Once
Did you know, you can update all TYPO3 sysext with a single command like;
// Update all sysext TYPO3 core extensions
composer update typo3/cms-* --with-dependencies
Be careful, This command may cause negative effects if you do not have proper version constraints in your composer.json. You always should prefer to update your packages separately.
Tip #6 Add Your Own Composer TYPO3 Repositories
Do you want to add your own TYPO3 composer repository eg., Github? You can simply configure multiple repositories into the composer using repositories > type > vcs.
// composer.json
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/username/repo"
},
],
"require": {
"vendor/repo": "dev-master",
},
}
Tip #7 Define Your Custom Public Folder
By default, TYPO3 composer create “public” folder as document root, If you want to set different folder then just configure > extra > typo3/cms > web-direct
// composer.json
"extra": {
"typo3/cms": {
"cms-package-dir": "{$vendor-dir}/typo3/cms",
"web-dir": "web"
}
}
// You will get “web” folder at TYPO3 root
$ ls -la
drwxr-xr-x .git
-rw-r--r-- .gitignore
-rw-r--r-- composer.json
-rw-r--r-- composer.lock
drwxr-xr-x vendor
drwxr-xr-x web
// “web” folder contains TYPO3
$ls -la web
drwxrwsr-x fileadmin
lrwxr-xr-x index.php
lrwxr-xr-x typo3
drwxr-xr-x typo3conf
drwxrwsr-x typo3temp
drwxrwsr-x uploads
Tip #8 Testing TYPO3 Extensions using Composer
Add packages with --dev attribute to add packages only to your local development environment. This is very useful for packages, you do not need or do not want to have on your live server, e.g. PHPUnit or Testing-Frameworks.
composer require typo3/testing-framework:^2.0 --dev
During your deployment routine, you should run the composer install with attribute --no-dev. So the dev requirements are not installed.
composer install --no-dev
Tip #9 Keep Check Outdated TYPO3 extensions
// to see a list of available updates.
composer outdated
// to see a list of available updates for directly required packages.
composer outdated -D
Tip #10 Autoload Classes in TYPO3 Composer
In composer mode, the autoloader checks for (classmap and PSR-4) autoloading information inside your extensions’ composer.json.
composer dumpautoload
Dump the class loading information manually and check that the autoload information is updated. Typically you would check vendor/composer to hold files like autoload_classmap.php and autoload_psr4.php etc.
$ tree vendor/composer
.
├── ClassLoader.php
├── LICENSE
├── autoload_classmap.php
├── autoload_files.php
├── autoload_namespaces.php
├── autoload_psr4.php
├── autoload_real.php
├── autoload_static.php
├── include_paths.php
└── installed.json
// composer.json
"autoload": {
"psr-4": {
"DanielGoerz\\MyExtension\\": "web/typo3conf/ext/my_extension/Classes/"
}
}
"autoload": {
"classmap": [
"web/typo3conf/ext/my_legacy_ext/"
]
}
composer dump-autoload
Tip #11 Quick Install TYPO3 Patch
Do you want to quickly install a TYPO3 patch using a composer? That’s quite easy as below.
// composer.json
"extra": {
"patches": {
"typo3/cms-core": {
"BUGFIX unique for fields with l10n_mode=exclude": "Build/Patches/c1ce767_core.diff"
},
"typo3/cms-frontend": {
"BUGFIX unique for fields with l10n_mode=exclude": "Build/Patches/c1ce767_frontend.diff"
}
}
},
// Install TYPO3 core patch
composer require cweagans/composer-patches
composer install
Tip #12 Deactivate TYPO3 Composer Mode
Step 1. Go to /vendor/typo3/autoload-include.php
Step 2. TYPO3_COMPOSER_MODE = FALSE
// TYPO3 is installed via composer. Flag this with a constant.
if (!defined('TYPO3_COMPOSER_MODE')) {
define('TYPO3_COMPOSER_MODE', FALSE);
}
Tip #13 TYPO3 Migrate Non-composer to Composer
Yeah, so you are in love with the TYPO3 Composer? and Do you want to migrate your non-Composer to Composer-based TYPO3 installation?
Explore official documentation of Migrate TYPO3 Project to Composer
Tip #14 Setup Premium TYPO3 Packages
Do you want your private or premium TYPO3 packages for your customers or internal private TYPO3 projects? You can easily implement it, Explore our popular article 7 Easy Steps to Satis - TYPO3 Private Packages for Composer
Tip #15 More Secure Your TYPO3
Did you know the magical and secure TYPO3 architecture of Helmut?
// composer.json
"extra": {
"typo3/cms": {
"root-dir": "private",
"web-dir": "public"
}
}
// install typo3-secure-web
composer require helhum/typo3-secure-web
I recommend reading a step-by-step guide to Secure Your TYPO3 and Server Architecture
Tip #16 TYPO3 Composer Generator
For the TYPO3 developers or integrators who want to create custom TYPO3 Extensions will require to manually initiate composer.json, Team T3Planet developed cool TYPO3 composer generator solution.
You can generate TYPO3 composer.json for your TYPO3 extension by;
- Uploading your TYPO3 extension’s ext_emconf.php
- By filling up the form of creating TYPO3 composer
- Download sample TYPO3 composer.json
Conclusion!
Thanks for reading such a long article :)
I hope you like, learn, and explore in-depth about TYPO3 composers. Let's have a quick recap.
- Understand the basic fundamentals and architecture of Composer, Keep try and practice all composer commands like create, require, install, update, etc., Also keep exploring tips and techniques of TYPO3 composer.
- For your upcoming TYPO3 projects, Start with Composer based installation of TYPO3 and Extensions.
- If you are developing TYPO3 extensions for TER, then you should consider supporting the composer for all TYPO3 extensions.
Do you have any suggestions or feedback? or, Are you facing any issues in your TYPO3 composer project? I'll be very happy to help you, Write down the comment box below.
Have a Happy & Productive TYPO3 Composer Project!
Hey Andreas,
Thanks for your feedback and appreciation. That's very easy, You can easily install and configure your local TYPO3 extension in composer.
Cheers,
Sanjay
thanks for your answer, thanks for caring :) I will take a close look at the link. In fact I am very new to developing Typo3 extensions ;)
Kind regards
Andreas