Setting up a New Craft CMS 3 Project
Tags: webdev, devops, craftcms
Published: 2020-02-19 22:12:29

---
title: Setting up a New Craft CMS 3 Project
published: true
date: 2017-12-05 19:45:00 UTC
tags: webdev,devops,craftcms
canonical_url: https://nystudio107.com/blog/setting-up-a-craft-cms-3-project
---

# Setting up a New Craft CMS 3 Project

### With the release of Craft CMS 3, you might want to kick the tires. Here is how to set up a Craft CMS 3 project

Andrew Welch / [nystudio107](https://nystudio107.com)

![Craft Cms 3 Rc 1](https://nystudio107-ems2qegf7x6qiqq.netdna-ssl.com/img/blog/_1200x675_crop_center-center_82_line/1732/craft-cms-3-rc-1.jpg)

Now that [Craft CMS 3 has been released](http://craftcms.com/news/craft-3), you’re like­ly eager to give it a go. This arti­cle is some­thing you might want to read first, to give you a roadmap for set­ting up your project.

This arti­cle will dis­cuss set­ting up a _new_ Craft 3 project so you can exper­i­ment with it. It will _not_ cov­er updat­ing an exist­ing Craft 2.x project to Craft 3; expect that to come in a future article.

![Release Candidate Features Frozen](https://nystudio107-ems2qegf7x6qiqq.netdna-ssl.com/img/blog/_1200x675_crop_center-center_82_line/release-candidate-features-frozen.jpg)

This makes it an _excel­lent_ time to start get­ting famil­iar with it, whether you’re a fron­tend devel­op­er, a plu­g­in devel­op­er, or both. With the fea­ture set frozen, you’re work­ing against a known quantity.

I won’t rehash what is new in Craft 3; if you’re inter­est­ed in that, check out the [Craft 3 Beta Exec­u­tive Sum­ma­ry](https://dev.to/gaijinity/craft-3-beta-executive-summary-g88-temp-slug-5487712) article.

The canon­i­cal ref­er­ence will always be the Craft CMS doc­u­men­ta­tion for [Serv­er Require­ments](https://github.com/craftcms/docs/blob/master/en/requirements.md), [Instal­la­tion](https://github.com/craftcms/docs/blob/master/en/installation.md), [Con­fig­u­ra­tion](https://github.com/craftcms/docs/blob/master/en/configuration.md), and [Direc­to­ry Struc­ture](https://github.com/craftcms/docs/blob/master/en/directory-structure.md). But there are a few tips, tricks, and hints I’d like to add to the sub­ject as well.

So, let’s dive in!

## Should I Use Craft 3 in Production?

**N.B.** Since [Craft CMS 3 was released](http://craftcms.com/news/craft-3) on April 4<sup>th</sup> 2018, the answer is: **def­i­nite­ly yes** , you should be using Craft CMS 3.x in pro­duc­tion. The bal­ance of this sec­tion is left in for his­tor­i­cal reasons.

One of the most com­mon­ly asked ques­tions with the release of Craft CMS 3 RC1 is:

<aside>
                                Should I Use Craft <span>3</span> in Production?
                            </aside>

The answer is _it depends_. I per­son­al­ly am using Craft 3 RC1 in pro­duc­tion for a client site, as well as a for a new project of my own.

The biggest draw­back is that your favorite plu­g­in may not be port­ed yet, but Craft is flex­i­ble enough that you can gen­er­al­ly do with­out many plu­g­ins if you have to. There are also quite a few [Craft 3 plu­g­ins](https://plugins.craftcms.com/) avail­able already.

I think it makes sense to at the very least fire up a test site to kick Craft 3 RC1’s tires. For some client sites, I think it’s also very rea­son­able to start using it now as well. The speed and infra­struc­ture improve­ments are well worth it.

## Changes from Craft 2.x

There are a few changes in terms of how things are set up in Craft 3 com­pared to Craft 2.x, and all for the bet­ter in my opinion.

![Changes Craft 2 To Craft 3](https://nystudio107-ems2qegf7x6qiqq.netdna-ssl.com/img/blog/_1200x675_crop_center-center_82_line/changes-craft-2-to-craft-3.jpg)

Some of these changes will take some get­ting used to:

- Craft 3 now uses [Com­pos­er](https://getcomposer.org/) for instal­la­tion & updat­ing of Craft and any plu­g­ins you might have
- The default direc­to­ry struc­ture has some changes; but these are just sug­ges­tions. You can use what­ev­er you like
- Plu­g­ins writ­ten for Craft 2.x _will not work_ with Craft 3, they will need to be updat­ed by developers
- Craft 3 now uses a [php­dotenv](https://github.com/vlucas/phpdotenv) <kbd>.env</kbd> file by default for han­dling envi­ron­men­tal-spe­cif­ic things like pass­words, data­base names, etc.
- There are some minor tem­plate changes for you to make; most are just dep­re­ca­tions, so they still work, but you’ll need to update them by the time Craft 4 rolls around

## Com­pos­er

The first major change is that Craft 3 relies on [Com­pos­er](https://getcomposer.org/doc/) for things like instal­la­tion and updates of both Craft CMS itself, and any plu­g­ins you may be using.

- [Com­pos­er](https://getcomposer.org/doc/) is a tool that allows for the instal­la­tion of PHP pack­ages, much like <kbd>npm</kbd> and <kbd>yarn</kbd> for JavaScript
- [Pack​ag​ist​.org](https://packagist.org/) is a web­site that’s a pub­lic list­ing of Com­pos­er pack­ages, sim­i­lar to [npmjs​.com](https://www.npmjs.com/) for JavaScript

If you don’t have Com­pos­er installed on your <kbd>local</kbd> dev set­up yet, here are [instruc­tions on how to Install Com­pos­er](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos).

Pix­el & Ton­ic has men­tioned that they plan to allow a non-Com­pos­er instal­la­tion path, but as devel­op­ers it actu­al­ly makes our lives much eas­i­er to embrace Composer.

So if you aren’t famil­iar with Com­pos­er, invest­ing some time to learn it now will pay div­i­dends down the road. Let’s dive in!

![Craft 3 Cms Composer](https://nystudio107-ems2qegf7x6qiqq.netdna-ssl.com/img/blog/_1200x675_crop_center-center_82_line/craft-3-cms-composer.jpg)

To install a new Craft 3 project, all we need to do is the following:

```

composer create-project craftcms/craft PATH

```

Let’s break this down:

- <kbd>composer</kbd> is just the [glob­al­ly installed Com­pos­er](https://github.com/craftcms/docs/blob/master/en/installation.md#1-install-composer) command
- <kbd>create-project</kbd> tells Com­pos­er that we want to [cre­ate a new project](https://getcomposer.org/doc/03-cli.md#create-project) from an exist­ing tem­plate (more on this later)
- <kbd>craftcms/craft</kbd> is the [pack​ag​ist​.org](https://packagist.org/) pack­age we want to use as a tem­plate when cre­at­ing our project
- <kbd>PATH</kbd> is the rel­a­tive or absolute path to where we want our project cre­at­ed; nor­mal­ly it’d be some­thing like <kbd>craft3</kbd> or <kbd>~/webdev/sites/mysitename</kbd> or what have you

So out of my [Home­stead VM](https://dev.to/gaijinity/local-development-with-vagrant-homestead-5gb0-temp-slug-2094211) that I use for local devel­op­ment, the com­mand I’d run is:

```

vagrant@homestead ~/sites $ composer create-project craftcms/craft crafttest

```

A whole bunch of text will fly by, but let’s talk about what’s actu­al­ly hap­pen­ing. Com­pos­er is going out to [pack​ag​ist​.org](https://packagist.org/) to look for a pack­age named <kbd>craftcms/craft</kbd> and then it’s essen­tial­ly <kbd>git clone</kbd>​’ing that repos­i­to­ry, but with­out actu­al­ly pulling down the <kbd>.git</kbd> data.

We’re cre­at­ing a new project, after all, so we want to use the pack­age as a tem­plate to get the files in it as a start­ing point.

Have a look at the actu­al [craftcms/​craft repos­i­to­ry on GitHub​.com](https://github.com/craftcms/craft), and you’ll see that there isn’t a whole lot to it, real­ly. It’s just some Craft con­fig­u­ra­tion files, <kbd>composer.json</kbd>, etc. So it’s just a bare bones project that gets made for us as a start­ing point.

Then it will run a <kbd>composer install</kbd> to install any of the Com­pos­er pack­ages that <kbd>craftcms/craft</kbd> claims as depen­den­cies, much like <kbd>npm install</kbd> or <kbd>yarn</kbd> does for npm packages. 

The crit­i­cal thing to under­stand here is that the <kbd>craftcms/craft</kbd> pack­age is just scaf­fold­ing that Pix­el & Ton­ic set up with what they think is a nice start­ing point for your new Craft 3 project. This actu­al­ly could be any pack​ag​ist​.org pack­age that is of <kbd>"type": "project"</kbd>!

For instance, I have set up a pack­age <kbd>nystudio107/craft</kbd> that allows me to set up Craft 3 with the direc­to­ry struc­ture and depen­den­cies that I want, and I can start a new Craft 3 project with _my_ scaf­fold­ing by doing:

```

vagrant@homestead ~/sites $ composer create-project nystudio107/craft crafttest

```

The [nystudio107/​craft](https://github.com/nystudio107/craft) project pack­age does every­thing the Pix­el & Ton­ic [craftcms/​craft](https://github.com/craftcms/craft) project pack­age does, and then installs a num­ber of tools and scaf­fold­ing that I use, and has been described in arti­cles in this blog. So it makes a great start­ing point.

Not only is this pret­ty use­ful should you want to set up your own scaf­fold­ing, it’s a key point to under­stand what’s going on. Let’s have a look at the <kbd>composer.json</kbd> file that comes with the <kbd>craftcms/craft</kbd> package:

```

{
  "name": "craftcms/craft",
  "description": "Craft CMS",
  "keywords": [
    "craft",
    "cms",
    "craftcms",
    "project"
  ],
  "license": "MIT",
  "homepage": "https://craftcms.com/",
  "type": "project",
  "support": {
    "email": "support@craftcms.com",
    "issues": "https://github.com/craftcms/cms/issues",
    "forum": "https://craftcms.stackexchange.com/",
    "source": "https://github.com/craftcms/cms",
    "docs": "https://craftcms.com/docs",
    "rss": "https://craftcms.com/changelog.rss"
  },
  "require": {
    "craftcms/cms": "^3.0.0",
    "vlucas/phpdotenv": "^2.4.0"
  },
  "autoload": {
    "psr-4": {
      "modules\\": "modules/"
    }
  },
  "config": {
    "optimize-autoloader": true,
    "platform": {
      "php": "7.0"
    }
  },
  "scripts": {
    "post-create-project-cmd": [
      "@php -r \"copy('.env.example', '.env');\"",
      "@php -r \"unlink('composer.json');\"",
      "@php -r \"unlink('LICENSE.md');\"",
      "@php -r \"unlink('README.md');\"",
      "@php -r \"rename('composer.json.default', 'composer.json');\"",
      "@composer dump-autoload -o",
      "@php craft setup/welcome"
    ]
  }
}

```

So this is pret­ty inter­est­ing! The <kbd>craftcms/craft</kbd> project pack­age lists <kbd>craftcms/cms</kbd> as a depen­den­cy. It can get a lit­tle con­fus­ing, so remember:

- <kbd>craftcms/craft</kbd> is the starter project scaf­fold­ing pack­age for your Craft 3 projects
- <kbd>craftcms/cms</kbd> is the actu­al Craft 3 pack­age that con­tains all of the code that col­lec­tive­ly makes up Craft CMS

So Craft itself is just anoth­er Com­pos­er pack­age that gets pulled in. It works the same way for any plu­g­ins you might want to use, you can just add them to your <kbd>composer.json</kbd> and they’ll get installed as PHP packages.

Of course, Craft pro­vides a nice GUI for doing all of this as well, but it’s use­ful to under­stand how things work under the hood.

If you want to do a deep-dive on Com­pos­er, I’d sug­gest check­ing out the arti­cles [Com­pos­er Sta­bil­i­ty Flags](https://igor.io/2013/02/07/composer-stability-flags.html) & [Com­pos­er Autoload Fea­tures](http://alanstorm.com/composer_autoloader_part_1/) (there are sev­er­al parts to this arti­cle, make sure to read them all!).

Also extreme­ly use­ful for under­stand­ing Composer/​Packagist semver nam­ing is the [Pack­ag­ist Semver Check­er](https://semver.mwl.be/#?package=craftcms%2Fcms&version=%5E3.0.0-RC1&minimum-stability=RC).

## Craft 3 Ini­tial Setup

Okay, so after we’ve cre­at­ed a Craft 3 project, now we need to do a lit­tle bit of work set­ting it up.

![Craft 3 Cms Setup Instructions](https://nystudio107-ems2qegf7x6qiqq.netdna-ssl.com/img/blog/_992x702_crop_center-center_100_line/craft-3-cms-setup-instructions.jpg)

At the tail end of the instal­la­tion, you’ll see a mes­sage like this from Craft:

```

Generating a security key...
done (UDRBoBjQAzfgY5J9S-543Ie0PrxwCwZG)

Welcome to Craft CMS! Run the following command if you want to setup Craft from your terminal:

    ~/sites/crafttest/craft setup

```

The **secu­ri­ty key** that it gen­er­ates is just a ran­dom string of char­ac­ters (like a pass­word) that’s unique on a per-project basis. For mul­ti-envi­ron­ment setups, you’ll want to be using the same secu­ri­ty key in each environment.

Craft uses this for encrypt­ing data, so it’s just a unique seed that’s set in <kbd>general.php</kbd>.

If you run the com­mand <kbd>~/sites/crafttest/craft setup</kbd> (or what­ev­er it out­puts for your project), it’ll set up your <kbd>.env</kbd> file for you:

```

vagrant@homestead ~/sites $ ~/sites/crafttest/craft setup
Which database driver are you using? [mysql,pgsql,?]: mysql
Database server name or IP address: [localhost]
Database port: [3306]
Database username: [root] homestead
Database password:
Database name: crafttest
Database table prefix:
Testing database credentials... success!
Saving database credentials to your .env file...
done

```

Your (emp­ty) data­base needs to have been cre­at­ed already, just like on Craft 2.x. It’ll then ask you if you want to install Craft now. If you say **yes** , it’s essen­tial­ly just a com­mand line equiv­a­lent of the famil­iar set­up wizard:

```

Install Craft now? (yes|no) [yes]:

Username: [admin]
Email: andrew@nystudio107.com
Password:
Confirm:
Site name: crafttest
Site URL: http://crafttest.dev
Site language: [en-US]

```

Of course, you don’t have to do it this way. You can say **no** , and install it by going to the <kbd>http://mysite.dev/admin</kbd> URL just as you did for Craft 2.x if you like.

Either way, you’ll now have a [php­dotenv](https://github.com/vlucas/phpdotenv) <kbd>.env</kbd> file in your project root that has your cre­den­tials in it:

```

vagrant@homestead ~/sites $ cat crafttest/.env
# The environment Craft is currently running in ('dev', 'staging', 'production', etc.)
ENVIRONMENT="dev"

# The secure key Craft will use for hashing and encrypting data
SECURITY_KEY="UDRBoBjQAzfgY5J9S-543Ie0PrxwCwZG"

# The database driver that will used ('mysql' or 'pgsql')
DB_DRIVER="mysql"

# The database server name or IP address (usually this is 'localhost' or '127.0.0.1')
DB_SERVER="localhost"

# The database username to connect with
DB_USER="homestead"

# The database password to connect with
DB_PASSWORD="secret"

# The name of the database to select
DB_DATABASE="crafttest"

# The database schema that will be used (PostgreSQL only)
DB_SCHEMA="public"

# The prefix that should be added to generated table names (only necessary if multiple things are sharing the same database)
DB_TABLE_PREFIX=""

# The port to connect to the database with. Will default to 5432 for PostgreSQL and 3306 for MySQL.
DB_PORT="3306"

```

Remem­ber, this file is nev­er checked into git, so we’ll need a man­u­al­ly cre­at­ed <kbd>.env</kbd> file for each envi­ron­ment we deploy Craft to, includ­ing our <kbd>staging</kbd> and <kbd>live</kbd> pro­duc­tion servers.

The con­stants in the <kbd>.env</kbd> file are parsed, and set as [PHP Envi­ron­ment vari­ables](http://php.net/manual/en/reserved.variables.environment.php) that are read by the <kbd>general.php</kbd>, <kbd>db.php</kbd>, etc. Craft 3 <kbd>config/</kbd> files:

```

<?php
/**
 * Database Configuration
 *
 * All of your system's database connection settings go in here. You can see a
 * list of the available settings in vendor/craftcms/cms/src/config/DbConfig.php.
 */

return [
    'driver' => getenv('DB_DRIVER'),
    'server' => getenv('DB_SERVER'),
    'user' => getenv('DB_USER'),
    'password' => getenv('DB_PASSWORD'),
    'database' => getenv('DB_DATABASE'),
    'schema' => getenv('DB_SCHEMA'),
    'tablePrefix' => getenv('DB_TABLE_PREFIX'),
    'port' => getenv('DB_PORT')
];

```

While <kbd>.env</kbd> files are great for devel­op­ment, for live pro­duc­tion I’d rec­om­mend mov­ing the envi­ron­men­tal vari­ables [to your web­serv­er con­fig](https://github.com/vlucas/phpdotenv#usage-notes), or using some­thing like [Craft 3 Mul­ti-Envi­ron­ment](https://github.com/nystudio107/craft3-multi-environment) as described in the [Mul­ti-Envi­ron­ment Con­fig for Craft CMS](https://dev.to/gaijinity/multi-environment-config-for-craft-cms-3952-temp-slug-5514305) article.

## The Craft 3 Direc­to­ry Structure

Alrighty, now that we have a fresh Craft 3 project installed & set up, let’s take a lit­tle sur­vey of what we actu­al­ly have installed.

![Craft 3 Cms Directory Structure](https://nystudio107-ems2qegf7x6qiqq.netdna-ssl.com/img/blog/_1200x675_crop_center-center_82_line/craft-3-cms-directory-structure.jpg)

Here’s what our fresh­ly installed project direc­to­ry looks like:

```

vagrant@homestead ~/sites/crafttest $ tree -L 2 -a .
.
├── composer.json
├── composer.lock
├── config
│ ├── app.php
│ ├── db.php
│ ├── general.php
│ ├── redactor
│ └── routes.php
├── craft
├── craft.bat
├── .DS_Store
├── .env
├── .env.example
├── .gitignore
├── LICENSE.md
├── modules
│ └── Module.php
├── README.md
├── storage
│ ├── .gitignore
│ ├── logs
│ └── runtime
├── templates
│ └── .gitkeep
├── vendor
│ ├── autoload.php
│ ├── bin
│ ├── cebe
│ ├── composer
│ ├── craftcms
│ ├── creocoder
│ ├── danielstjules
│ ├── .DS_Store
│ ├── enshrined
│ ├── ezyang
│ ├── guzzlehttp
│ ├── justinrainbow
│ ├── league
│ ├── mikehaertl
│ ├── paragonie
│ ├── pixelandtonic
│ ├── psr
│ ├── seld
│ ├── swiftmailer
│ ├── symfony
│ ├── twig
│ ├── vlucas
│ ├── yiisoft
│ └── zendframework
└── web
    ├── cpresources
    ├── .htaccess
    ├── index.php
    └── web.config

33 directories, 22 files

```

The first thing you’ll notice is that there is no <kbd>craft/</kbd> direc­to­ry here at all any­more, which is some­thing we were used to see­ing in Craft 2.x. Every direc­to­ry that was inside of the <kbd>craft/</kbd> direc­to­ry in Craft 2.x is now in our root project directory.

This makes sense if you think about it, since Craft itself is now just installed as anoth­er Com­pos­er depen­den­cy in the <kbd>vendor/craftcms</kbd> directory.

So let’s take a look at some notable files/​directories that we have in our projects now:

- <kbd>composer.json</kbd> has all of the infor­ma­tion for our project, includ­ing the PHP pack­age depen­den­cies and their min­i­mum [semver ver­sions](https://semver.npmjs.com/)
- <kbd>composer.lock</kbd> has infor­ma­tion on what PHP pack­ages & their ver­sions are _actu­al­ly installed_ (they may be new­er than our min­i­mum versions)
- <kbd>config/</kbd> is what used to be <kbd>craft/config/</kbd>, and has all of the famil­iar Craft CMS con­fig files
- <kbd>craft</kbd> is a com­mand line tool that is exact­ly anal­o­gous to the web-fac­ing <kbd>index.php</kbd>. It’s what you use to run Craft 3 via the com­mand line (more on this below)
- <kbd>.env</kbd> is our [php­dotenv](https://github.com/vlucas/phpdotenv) <kbd>.env</kbd> file that has our envi­ron­ment-spe­cif­ic things like data­base pass­words, etc. stored
- <kbd>.gitignore</kbd> tells git what file pat­terns to ignore com­plete­ly, and nev­er check into git
- <kbd>storage/</kbd> is what used to be <kbd>craft/storage/</kbd> and is where tem­po­rary run­time files, logs, etc. are kept, just like in Craft 2.x
- <kbd>templates/</kbd> is what used to be <kbd>craft/templates/</kbd> and is where your Twig tem­plates are stored
- <kbd>vendor/</kbd> is where all of the PHP pack­age depen­den­cies that your project uses (includ­ing Craft itself) are stored
- <kbd>web/</kbd> is what used to be the <kbd>public/</kbd>, which con­tains our index.php, .htac­cess, etc. files, and is where the web serv­er root should be pointed

It’s impor­tant to note that Craft does­n’t real­ly care what you use as a direc­to­ry struc­ture, this is just what Pix­el & Ton­ic is pro­vid­ing you as a base set­up. If you don’t like the change from <kbd>public/</kbd> to <kbd>web/</kbd>, that’s fine. Just rename it!

The <kbd>craft</kbd> com­mand line tool is actu­al­ly what we used ear­li­er to set up the <kbd>.env</kbd> file, and option­al­ly install Craft. Just think of it as a way to run Craft from the com­mand line. It inher­its a num­ber of tools from [Yii2 Con­sole Com­mands](http://www.yiiframework.com/doc-2.0/guide-tutorial-console.html), and Pix­el & Ton­ic has added a num­ber of Craft-spe­cif­ic things to it as well.

For instance, you can use <kbd>./craft install/plugin my-plugin-handle</kbd> to install plu­g­ins from the com­mand line. Cool!

## Deploy­ing Craft CMS

The change in how Com­pos­er is used for Craft 3 dis­cussed ear­li­er leads direct­ly to how we should be updat­ing, test­ing, and deploy­ing Craft 3.

For Craft 2.x, we just checked all of <kbd>craft/</kbd> (includ­ing the <kbd>vendor/</kbd> sub-direc­to­ry) into git, updat­ed & test­ed it in <kbd>local</kbd> dev, and then deployed it to <kbd>staging</kbd>/<kbd>live</kbd> pro­duc­tion via our deploy­ment tool of choice, such as [Lar­avel Forge](https://forge.laravel.com/), [Buddy.works](https://buddy.works/), [Lar­avel Envoy­er](https://envoyer.io/), [Deploy­Bot](https://deploybot.com/), etc.

![Deploying Craft 3 Cms](https://nystudio107-ems2qegf7x6qiqq.netdna-ssl.com/img/blog/_1200x675_crop_center-center_82_line/deploying-craft-3-cms.jpg)

There are a few impor­tant bits from Com­pos­er that we need to under­stand first, to see how this needs to change for Craft 3:

- <kbd>composer.json</kbd> has all of the infor­ma­tion about our project, and what PHP pack­age depen­den­cies it requires as min­i­mum [semver ver­sions](https://semver.npmjs.com/)
- <kbd>composer.lock</kbd> has infor­ma­tion on what PHP pack­age depen­den­cies are _actu­al­ly installed_ (we might have new­er ver­sions than what our min­i­mum ver­sions require)
- <kbd>vendor/</kbd> is a direc­to­ry that has all of the actu­al PHP pack­ages installed (includ­ing Craft CMS itself!)
- <kbd>.gitignore</kbd> tells git what file pat­terns to ignore when track­ing changes in git

Here’s the default <kbd>.gitignore</kbd> file pro­vid­ed by the craftcms/​craft package:

```

/.env
/.idea
/vendor
.DS_Store

```

The impli­ca­tions are that we’re nev­er check­ing our <kbd>.env</kbd> files into git (because putting sen­si­tive things like pass­words into ver­sion con­trol is a bad idea), but we’re also ignor­ing the entire <kbd>/vendor</kbd> directory.

So if we’re not check­ing any of our PHP pack­ages in the <kbd>/vendor</kbd> direc­to­ry into git (this includes Craft CMS itself, remem­ber!), how do we update and deploy things?

<aside>
                                By embrac­ing Com­pos­er, that’s how!
                            </aside>

We’ll take advan­tage of how Com­pos­er works:

- In local dev, we’ll update every­thing via <kbd>composer update</kbd> (or we can update just spe­cif­ic pack­ages via <kbd>composer update packagevendor/package</kbd>)
- The above step can also be done via the AdminCP UI by click­ing on Update, either for Craft CMS itself, or any of its plu­g­ins. Under the hood, it ends up run­ning Com­pos­er just as described above
- This caus­es Com­pos­er to down­load & install the updat­ed package(s), and then it writes out what’s installed to the <kbd>composer.lock</kbd> file
- Then we test every­thing in <kbd>local</kbd> dev just as we used to, to make sure it’s ready for prime time
- Since we ignore all of the <kbd>/vendor</kbd> direc­to­ry, the only thing that will be changed as far as git is con­cerned is the <kbd>composer.lock</kbd> file that lists what ver­sions of what pack­ages are actu­al­ly installed

Then on the serv­er-side deploy­ment of things, we’ll run the fol­low­ing from our project direc­to­ry on the server:

```

composer install --no-interaction --prefer-dist --optimize-autoloader

```

What <kbd>composer install</kbd> does is look at what­ev­er is in the <kbd>composer.lock</kbd> file, and if it’s new­er than what it sees installed local­ly, it updates & installs it! You can see the full options avail­able to [com­pos­er install here](https://getcomposer.org/doc/03-cli.md#install).

The neat thing about doing it this way is we have less cruft checked into our git repos, and we can also dis­crete­ly update only spe­cif­ic things.

Maybe we only want to update a spe­cif­ic plu­g­in, we can do that by updat­ing only that plu­g­in via <kbd>composer update pluginvendor/plugin</kbd> from local dev. Since that’s the only change that gets writ­ten out to the <kbd>composer.lock</kbd> file, that’s the only thing that gets updat­ed when our serv­er runs <kbd>composer install</kbd>

Nice.

The only down­side to this is that <kbd>composer install</kbd> can take a bit longer than a sim­ple <kbd>git pull</kbd> to exe­cute, so look­ing into atom­ic deploy­ments via [Buddy.works](https://buddy.works/), [Lar­avel Envoy­er](https://envoyer.io/), [Deploy­Bot](https://deploybot.com/), etc. might not be a bad idea.

## Craft 3 Plugins

The bad news about plu­g­ins is that plu­g­in devel­op­ers will need to rewrite their plu­g­ins for Craft 3.

![Craft 3 Cms Plugins](https://nystudio107-ems2qegf7x6qiqq.netdna-ssl.com/img/blog/_1200x675_crop_center-center_82_line/craft-3-cms-plugins.jpg)

The good news is that Pix­el & Ton­ic has made a nice guide on [Craft 3 Plu­g­in Devel­op­ment](https://github.com/craftcms/docs#plugin-development), and many plu­g­ins have already been port­ed. Check out the [Craft 3 Plu­g­ins page](https://plugins.craftcms.com/) to see what’s avail­able already.

Also, tools like [plug​in​fac​to​ry​.io](https://pluginfactory.io/) and arti­cles like [So You Wan­na Make a Craft 3 Plu­g­in?](https://dev.to/gaijinity/so-you-wanna-make-a-craft-3-plugin-76m-temp-slug-4321262) are avail­able to help developers.

The best thing you can do is check with your plu­g­in ven­dor to see how far along they are on port­ing their plu­g­ins to Craft 3.

Pix­el & Ton­ic has stat­ed that a beta ver­sion of the Plu­g­in Store (which is inte­grat­ed into the Craft 3 AdminCP) will ship with Craft 3 CMS RC 1, but that only free plu­g­ins will be avail­able ini­tial­ly. Devel­op­ers can make plu­g­ins that will be paid plu­g­ins avail­able for free now as well, but they will require pur­chase once Craft CMS 3 is in GA release.

The full roll­out of the plu­g­in store with paid plu­g­ins, Com­merce 2, and the Gen­er­al Avail­abil­i­ty release of Craft 3 will hap­pen on April 4<sup>th</sup>, 2018. Check out the [What We Announced at Dot All 2017](https://craftcms.com/news/dot-all-2017-announcements) arti­cle for details.

Speak­ing of plu­g­ins, Craft 3 comes with **no Rich Text field** by default. You’ll need to install the [Redac­tor plu­g­in](https://github.com/craftcms/redactor) first (don’t wor­ry, your exist­ing con­tent is still there). This is because P&T will be offer­ing a [CKEd­i­tor](https://ckeditor.com/) Rich Text plu­g­in as well, in the near future.

## Tem­plate Changes

The good news is that in terms of actu­al changes to your Twig tem­plates, there aren’t that many. Pix­el & Ton­ic has done a great job out­lin­ing the changes in [Twig 2](https://github.com/craftcms/docs/blob/master/en/changes-in-craft-3.md#twig-2) as well as the changes in [Craft Tem­plate Tags](https://github.com/craftcms/docs/blob/master/en/changes-in-craft-3.md#template-tags) that you’ll need to be aware of.

The vast major­i­ty of the changes are mere­ly _dep­re­ca­tion errors_. That means that Pix­el & Ton­ic plans to phase them out when Craft 4 comes along, but they’ll still work for now.

You can check on any dep­re­ca­tion errors inside of Craft 3 by going to **Util­i­ties** → **Dep­re­ca­tion Errors**.

![Craft 3 Cms Deprecation Errors](https://nystudio107-ems2qegf7x6qiqq.netdna-ssl.com/img/blog/_1200x472_crop_center-center_100_line/craft-3-cms-deprecation-errors.png)

The oth­er real­ly inter­est­ing thing is that in Craft 3, the entire <kbd>craft.app</kbd> appli­ca­tion instance is avail­able to your Twig templates. 

What that means in real terms is that you can do any­thing with the Craft 3 APIs via Twig that you can via PHP. So many small plu­g­ins that were need­ed to expose some need­ed func­tion­al­i­ty may no longer be nec­es­sary at all.

![Phpstorm Craft Auto Completion](https://nystudio107-ems2qegf7x6qiqq.netdna-ssl.com/img/blog/_576x305_crop_center-center_100_line/phpstorm-craft-auto-completion.png)

One absolute­ly _amaz­ing_ thing you can do if you’re using [Php­Storm](https://www.jetbrains.com/phpstorm/) is get full auto-com­ple­tion of the entire <kbd>craft.</kbd> APIs in your Twig tem­plates, too! To do make the mag­ic hap­pen, install the [Sym­fony plu­g­in](https://plugins.jetbrains.com/plugin/7219-symfony-plugin), then Go to **Pref­er­ences** → **Lan­guages & Frame­works** → **PHP** → **Sym­fony** and check **Enable Plu­g­in for this Project**.

Then all you need to do is put this inspec­tion hint at the top of your Twig templates:

```

{# @var craft \craft\web\twig\variables\CraftVariable #}

```

…and just like that, you get the same mag­ic auto-com­ple­tion of in your Twig tem­plates that you have in your PHP code. And since the entire Craft appli­ca­tion is avail­able in our Twig tem­plates now, this makes writ­ing Twig code that uses the Craft app APIs so much nicer.

## Wrap­ping Up!

This is undoubtably the first of sev­er­al arti­cles I’ll be writ­ing on Craft 3. But hope­ful­ly it has giv­en you an idea of the lay of the land for Craft 3 development.

Go forth and make cool stuff!

## Further Reading

_If you want to be notified about new articles, follow [nystudio107](https://twitter.com/nystudio107) on Twitter._

<small>Copyright ©2020 nystudio107. Designed by nystudio107</small>