Setup Statamic via DDEV
Tags: statamic, ddev, cms, laravel
Published: 2022-07-02 16:01:59


**🚧 Update february 2023: Some installation commands in this tutorial seem to be broken. See [DDEV discord](https://discord.com/channels/664580571770388500/1072827039415021628) for an updated version. Thx to tyler36! 🚧 **

In this little series I try to setup a nice and clean deployment workflow for the PHP CMS Statamic. [Statamic](https://statamic.dev/) is based on Laravel and has strong support for git-centric workflows. Every config change is stored in `.yaml`-files and can be version-tracked in git, no database by default (Although a database can be added later). 

🚧 This article is work in progress. 🚧

![Screenshot Statamic Website](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pcsc5s41jfj37cqa7yg2.png)

Beware: My goal is to separate content from config as much as possible, therefore **I won't** rely on Statamics [Git Automation](https://statamic.dev/git-automation). I'll keep the `content/`-directory out of git. Let's see how far I can push this as a Statamic newbie.

## 1. Create a repository

We start by creating a (private) GitHub repository. Add a dummy file like `README.md` to begin.

![Screenshot of creating a Github repository](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r8gqfscdzhlv1ywkf9zn.png)

## 2. Setup Statamic with DDEV and Composer

For the following steps I assume you already installed [DDEV](http://ddev.com/) on your computer. (Make sure to join the [DDEV Discord](https://discord.gg/hCZFfAMc5k) to meet the wonderful community, there is also a Laravel channel!). 

Clone the Github project to your local hard drive, open the project folder in Visual Studio Code. Use the built-in terminal for the following commands below. 

![Screenshot of Visual Studio Code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aa3lqydlpev98mokkcik.png)

So here we go, let's set it up:

```bash

# Create configuration for DDEV project
ddev config --project-type=laravel --docroot=public --create-docroot

# Install latest statamic via composer
ddev composer create statamic/statamic

# Generate config, set APP_URL & generate key
ddev exec "cp .env.example .env"
ddev exec 'sed -i "/APP_URL=/c APP_URL=$DDEV_PRIMARY_URL" .env'
ddev artisan key:generate

# Add support for CLI please command via DDEV-addon:
# (https://github.com/mandrasch/ddev-statamic-please)
ddev get mandrasch/ddev-statamic-please

# Compile JS/SCSS
# TODO: Add browsersync as well https://github.com/tyler36/ddev-browsersync#laravel-mix-example
ddev exec npm install
ddev exec npm run dev

ddev launch
```

This will open your site:

![Screenshot of default start site of statamic](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tejewi4hx2sw7tjmhtse.png) 

Afterwards you can create your admin user with `ddev please make user`:

<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jc5daso4nnpk7z9hzvdw.png" style="width:150px;" alt="Dialog of creating the user" />

We can open the control panel via `ddev launch /cp`:

![Screenshot of Statamic Control Panel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a896euruta4zzr1iucmk.png)

Great, that's a functional local setup! 🥳 

Commit and push this back to GitHub. If you don't want to store your users in git, add `/users` to `.gitignore` beforehand. 

One last cool thing: DDEV enables to usage of [Gitpod](https://gitpod.io/) as well, check the "Open in Gitpod"-button on [mandrasch/ddev-statamic-blank](https://github.com/mandrasch/ddev-statamic-blank) for example to try it out.