ACF Pro as a Composer dependency (without committing your license key unencrypted)

I am a bit confused as I assumed that adding env variables in #trellis to /group_vars/all/vault.yml such as

vault_wordpress_sites:
  example.com:
    env:
      ACF_PRO_KEY: A-UNIQUE-KEY-AJHDIUHDW/Z/(ADIHDSAJK

would add the key to the .env at provision as it does for the environment specific vault.yml.
Just tried it for a couple of times but the variables from /group_vars/all/vault.yml are not added to .env. Don’t you agree that this would be very useful, as you do not have to set the same variable three times for development, staging and production. Or do I someting wrong?

Cheers and best regards

You can use vault_wordpress_env_defaults (introduced by @TangRufus in https://github.com/roots/trellis/pull/1048)

2 Likes

Very useful hint! :slight_smile: Thanks!

I followed the guide > ACF Pro as a Composer dependency (without committing your license key unencrypted) - trellis - Roots Discourse on my staging environment ACF Pro is installed without problems when I deploy, but on my development environment I receive this error when I run composer update

[FFraenz\PrivateComposerInstaller\Exception\MissingEnvException]
  Can't resolve placeholder {%ACF_PRO_KEY}. Environment variable 'ACF_PRO_KEY' is not set.

I added the acf_pro_key: “xxxx” in the trellis/group_vars/development/vault.yml (as i did for the staging vault file) but on development environment it doesn’t work.

I suppose that the problem is this one:

how can i re-create my .env file in the development environment?

thanks

Run vagrant up --provision or just add it manually

thanks @Twansparant, it is ok now, I run vagrant reload --provision
I noted for the next time, thanks again :wink:

1 Like

Hello all,

I am excited to start working with Bedrock and came across this article. Very helpful but it assumes you are using Trellis. Is there an alternative approach for being able to use ACF Pro without Trellis? Thank you

It should be pretty much the same except you’ll just put the ACF key in your .env file manually rather than having Trellis create the .env on deployment. Does that make sense?

1 Like

Ah… great. Thank you!

Is it possible to update the documentation to reflect the update of private-composer-installer? The version currently included is conflicting with phpdotenv but the author recently published a new version (4.0) that fixes the bug.

1 Like

I use Bedrock/Trellis but only to deploy to kinsta. That means no local Vagrant deploy. I attempted the method to load ACF Pro with the license key in vault.yml.

When I run composer update on my local repo, it can’t resolve the ACF_PRO_KEY environment variable. This makes sense because there actually isn’t a local .env, it is on kinsta.

Running ansible deploy to kinsta does populate the .env file with the ACF key, However, the plugin doesn’t install because composer update failed and didn’t update composer.lock before deployment.

Seems a catch 22 here. There is no local deploy or local .env, but the remote deploy to kinsta needs there to be one.

Any thoughts for Kinsta/Trellis folks trying to use ACF Pro?

For local development, the key should be in the local .env file.
But for remote, the vault file and Trellis deploy should be already sufficient.
Be sure that the same variable name as in the composer.json is used among the local dev .env and Trellis vault files.

I don’t care much for how this tutorial requires the consumer to bump the plugin version manually anytime there’s a release.

Created this as a general-purpose alternative.

3 Likes

This is wonderful! Thank you for this contribution!

Update the link looks like this now: https://connect.advancedcustomfields.com/v2/plugins/download?p=pro&k={%ACF_PRO_KEY}&t={%version}

3 Likes

ACF have created their own way to do this now.

The news article:

The ACF guide:
https://www.advancedcustomfields.com/resources/installing-acf-pro-with-composer/

How we can use it:
https://roots.io/trellis/docs/composer-http-basic-authentication/

5 Likes

It would be nice to have an example for storing the ACF license information in Trellis vault,
when deploying the site.

1 Like

Yeah, i’m struggling with getting this to work.
I’ve added the key etc to the vault, but it’s still says that I must be using the interactive console to authenticate.

Which method are you struggling with? There are now a few described in this thread. If it’s the official ACF method, I recommend reaching out to their support for assistance.

I set up the new, official ACF PRO installation mechanism on a site and noticed some gotchas,
namely the password field must be non-empty and a full URL, not just the hostname – otherwise HTTP basic authentication will fail!

I documented the setup process in a little guide:

1 Like