Spring naar hoofd-inhoud

How to Install TYPO3 Using Composer (in Less Than 5 Minutes)

During the last TYPO3 User Experience Week (T3UXW) it became apparent that some participants weren't aware of the benefits of a composer-based TYPO3 installation. Today I would like to use the opportunity to demonstrate the setup of a new TYPO3 installation with only a couple of commands, easing the way to TYPO3 as much as possible.

Prerequisites

This guide assumes that you have access to the shell of your system and that you have installed composer.
If you have not installed composer yet, please click here and check how to install composer on your Operating System.

Compose your code

cd /path/to/your/htdocs/directory

Be aware that during the installation a subfolder called "web" will be created. Everything publicly accessible needs to be stored in that folder while confidential files, like configuration, must be stored outside of said "web" folder.
(Hint: If you want to change the name of the "web" folder, this is  very simple. I will get to that at a later point in this article.)

composer init

This starts the composer configuration generator. You will be asked a couple of informations, all of them could be edited later on.

  • Package name: A key to describe your project. E.g. "typo3inc/testcomposersetup".
  • Description: In this case I simply use: "This project is about to show how easy it is to create a composer based TYPO3 installation."
  • Author: The author name goes here.
  • Minimum Stability: Possible values are dev, alpha, beta, RC and stable.
  • Package Type: Project
  • License: Can be any type of string.
  • "Would you like to define your dependencies (require) interactively?": Yes
  • typo3/cms (as version constraint you could either enter "8" to stay on the LTS version or leave the field blank to always get the newest sprint release)
  • "Would you like to define your dev dependencies (require-dev) interactively?": No
  • "Do you confirm generation?": Yes

Now inspect the content of the directory, you'll find a file named composer.json.
Remember, I told you that it is possible to change the web folder name? Here is how it is done.
Add the following part to your composer.json file:

"extra": {
       "typo3/cms": {
           "web-dir": "web/public"
       }
}

The option “web-dir” allows us to define another path/name for the web folder, in this example the web folder name is changed to “web/public”. If you are on a case sensitive system, be sure to stick with upper and lower casing as you define here. 

Now let composer do its magic.

composer install

Depending on your coffee maker and your internet connection you might be able to go grab a quick cup of joe, but be quick about it, because even with cold caches it should not take longer than 2 minutes.
Now open your install tool in the browser and there you are. (Remember, the folder with your installation is the web folder. Configure your web server accordingly.)

More automation

I think we have about two minutes left so let's prepare the database connection.

composer require helhum/dotenv-connector

This composer package provides an easy way to store configuration outside of your web root.
Create a file called ".env" in the parent of your web folder and enter (and complete) the following lines:

TYPO3_INSTALL_DB_DRIVER=<your custom driver>
TYPO3_INSTALL_DB_HOST=<your host e.g. localhost>
TYPO3_INSTALL_DB_USER=<your db user for this project>
TYPO3_INSTALL_DB_PASSWORD=<the users password>
TYPO3_INSTALL_DB_PORT=<your custom port or omit this setting>
TYPO3_INSTALL_DB_DBNAME=<the db of your project>
TYPO3_INSTALL_DB_UNIX_SOCKET=<your custom socket or omit this setting>

When you go back to the install tool, most of the database configuration is already done.

Conclusion

Not only did we prepare a TYPO3 installation in less than 5 minutes, you also should have caught a glimpse of what would happen if you create the composer.json and a customized .env file to provision a hundred TYPO3 installations at once.

You'll find answers to other frequently asked technical questions, instructional clips and all sorts of helpful videos on our TYPO3 YouTube channel. Come along and join us there. If you find this useful, please share the link on your network.