# How to change WordPress DB prefix during provisioning

**URL:** https://discourse.roots.io/t/how-to-change-wordpress-db-prefix-during-provisioning/8247
**Category:** trellis
**Created:** 2016-12-02T19:41:25Z
**Posts:** 16

## Post 1 by @eshimischi — 2016-12-02T19:41:26Z

Hi. Any suggestions about changing DB\_PREFIX during the remote provisioning, would love to see database tables begin with {db\_prefix}?

Tried to change production/wordpress\_sites.yml and wordpress-setup/tasks/database.yml with no luck

---

## Post 2 by @ben — 2016-12-02T19:54:23Z

> [@eshimischi](#):
>
> Tried to change production/wordpress\_sites.yml and wordpress-setup/tasks/database.yml with no luck

Specifically what did you try? (Post code)

I haven’t tried it, but setting a `DB_PREFIX` env var before provisioning your site should work

---

## Post 3 by @RiFi2k — 2016-12-02T19:54:33Z

I’m confused about the use case for doing this honestly. Wouldn’t you just want to change your table prefix during development to whatever it was going to be, then this becomes a non issue.

---

## Post 4 by @eshimischi — 2016-12-02T20:04:11Z

As you know its a kind of security issue, there were a lot of articles about it, one more extra way to protect your wordpress blog and database against hackers.

---

## Post 5 by @eshimischi — 2016-12-02T20:16:30Z

So sorry for my english, but Bedrock has config/application.php with $table\_prefix = env(‘DB\_PREFIX’) ?: ‘wp\_’; as i do understand DB\_PREFIX may come from .env file that generated during the provisioning , but how to add this DB\_PREFIX to .env during the generation. I thought about adding a line to production/wordpress\_sites.yml, for example, db\_prefix: _dbprefix_ that will go to wordpress-install/tasks/main.yml -\> section ‘Create .env file’ and than to wordpress-setup/tasks/database.yml to create database with prefix for all the tables inside wordpress database. I’m not to vagrant at all to process all these steps. What do your think?

---

## Post 6 by @ben — 2016-12-02T20:28:15Z

See:

> [@Custom env variables trellis](https://discourse.roots.io/t/custom-env-variables-trellis/6330/2):
>
> If you want custom variables in the .env file created on deploy, each WP site will create env variables using the [wordpress\_env\_defaults](https://github.com/roots/trellis/blob/fc44e94d6f174792b00833d79a89dd92d4b1daf8/deploy.yml#L16-L23) from deploy.yml. To override or add to these env variables, you can edit group\_vars/\<environment\>/wordpress\_sites.yml. For example, if for example.com you wanted to override the default db\_name and add a new var new\_env\_var, you could add this for the site example.com: wordpress\_sites: example.com: ... env: db\_name: override\_name new\_env\_var: fo…

Also `env` in [https://roots.io/trellis/docs/wordpress-sites/](https://roots.io/trellis/docs/wordpress-sites/)

---

## Post 7 by @eshimischi — 2016-12-02T20:33:09Z

oh, missed it. thanks!

---

## Post 8 by @allurewebsolutions — 2018-01-25T06:00:04Z

If I want to rerun the server.yml playbook tag that generates the .env file, what tag would I run?

---

## Post 9 by @mZoo — 2018-03-27T20:54:53Z

just add a parameter to the `env` block in `group_vars/<environment>/vault.yml`:

```
db_prefix: "wpextended_"
```

In there with `db_password`, `auth_key`, etc.

That’s the source for the environment variables trellis inserts into the Bedrock installation, if I understand correctly.

---

## Post 10 by @allurewebsolutions — 2018-03-27T21:14:14Z

What I meant is that I don’t want to rerun all of the tasks in the playbook. So I was wondering which specific task controls the .env creation.

Also, it seems from my tests that once a .env is created, you can no longer change it through the playbook. Does anyone else experience this?

---

## Post 11 by @knowler — 2018-03-27T21:29:57Z

`.env` creation would be app specific so it would be a task in the `deploy.yml` playbook not `server.yml`. And as far as I know with deploys, you shouldn’t/can’t run specific tags (unless you want to [check the connection](https://github.com/roots/trellis/blob/master/deploy.yml#L12)). Each deploy is it’s own release, unlike the server which is being modified when it’s provisioned.

---

## Post 12 by @mZoo — 2018-03-27T21:58:11Z

As @knowler says it’s just the deployment plays which would be run again, so it should be something you can do fairly often without much hair-pulling. `./bin/deploy.sh staging example.com` from within Trellis (which you probably already know.)

---

## Post 13 by @allurewebsolutions — 2018-03-28T14:38:46Z

Do you have to commit the change to the repo in order for it to get deployed through the deploy playbook?

I’m thinking of a scenario where you want to add a temporary change to the `.env` and don’t want to commit it to the develop branch.

---

## Post 14 by @MWDelaney — 2018-03-28T14:45:45Z

I’d still do it in a branch, even if it’s not the `develop` branch. I’m always nervous of changing something without documenting it at least somewhere.

---

## Post 15 by @knowler — 2018-03-28T15:11:09Z

> [@allurewebsolutions](#):
>
> Do you have to commit the change to the repo in order for it to get deployed through the deploy playbook?

The change would take place within your `trellis` directory not the `site` directory,1 so technically no. While [you do have to version control the site’s folder](https://roots.io/trellis/docs/deploys/#configuration) for Trellis to deploy it, Trellis doesn’t do the same with itself. You could make a temporary change to the `group_vars`, deploy, then revert them. But like @MWDelaney said, it’s a good idea to document changes.

1 This assumes you are following [a standard Roots project structure](https://github.com/roots/roots-example-project.com).

---

## Post 16 by @allurewebsolutions — 2018-03-28T20:26:48Z

@knowler @MWDelaney @mZoo  
Thanks for all of your input!
