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

I was loading ACF with the keyed download link in a special composer package, but it sometimes required deleting the plugin to get it to update (which disrupted our nice reliable trellis deploys). acf-pro-installer works great, thanks @philippbaschke

Glad that you like it. :blush:

Hey guys,

Previously I was able to deploy without any issues but now I am getting the MissingKeyException error. I am able to use ACF Pro without any issues in the dev environment, the error only appears when I deploy to staging or production.

The acf_pro_key variable exists in each vault.yml file and successfully gets deployed to each remote environment in the .env file. I have re-provisioned the server but continue to get the error when I try to deploy.

Any help would be great :slight_smile:

Unfortunately I never used Trellis so I canā€™t really help in that matter. I suspect that the problem occurs in the loadDotEnv method. Maybe the .env file is not in the current working directory (getcwd())?

Try to find out if the .env file is loaded. If it is loaded you have to check the environment after it is loaded. getKeyFromEnv should be the right place to do it :slight_smile:

Hope that helps. Please let us know if you find out what the problem is (because you donā€™t seem to be the first one to have it) :blush:

I started getting this issue out of nowhere also, it does not let me deploy to remote servers. Did you happen to solve this?

EDIT: Fixed by removing ACF, running composer update, pushing to remote, then adding it back in.

Wouldnā€™t that mean that you would have to do this everytime you redeploy the site?

I just added the ACF Pro key to the site config in vault yml and I had to do this only once.

1 Like

Iā€™m trying to get composer to manage ACF Pro.
Hereā€™s what I have:

Plus I have my key listed in my encrypted vault files.

When I run composer update all appears to complete successfully but Iā€™m not able to spot where ACF Pro was installed and it doesnā€™t show up in wp-admin plugins.

Perhaps Iā€™m missing somethingā€¦

You have "type": "library". That should be "type": "wordpress-plugin" or "type": "wordpress-muplugin"

I had tried both types and none of them were working.
Turns out composer clear-cache solved the problem.

2 Likes

Anyone had issues with acf-pro-installer on a Trellis box with multiple websites? Far as I can tell Iā€™ve done everything right (like Iā€™ve done on a dozen other sites) but it errors out trying to install.

If I run composer install on the server it comes up ā€˜authentication requiredā€™ and asks for a username/password. The key is definitely there in the .env file so no idea whatā€™s wrongā€¦

It installs fine on development, just not on production.

Edit: Actually this might just be itā€¦

Hi,

I had originally just added ACF in as a plugin through the dashboard so Iā€™ve set up all my custom fields etc. and have the custom fields in a JSON file stored in resources/acf-json. However I want to have it as a proper dependency in composer so that I donā€™t have to remember to copy it across when I deploy the site. When I copy all the ACF files across to the plugins folder then my custom fields are all there.

Iā€™ve followed all of the above and have ACF installed in the vendor folder. Is this right? ACF isnā€™t showing in the list of plugins in the dashboard and nothing works until I manually copy the ACF files across to the plugins folder again.

My composer.json is:

  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org"
    },
    {
      "type": "package",
      "package": {
        "name": "advanced-custom-fields/advanced-custom-fields-pro",
        "version": "5.6.10",
        "type": "wordpress-plugin",
        "dist": {
          "type": "zip",
          "url": "https://connect.advancedcustomfields.com/index.php?p=pro&a=download"
        },
        "require": {
          "philippbaschke/acf-pro-installer": "^1.0",
          "composer/installers": "^1.0"
        }
      }
    }
  ],
  "require": {
    "php": ">=5.6",
    "composer/installers": "^1.4",
    "vlucas/phpdotenv": "^2.0.1",
    "johnpbloch/wordpress": "4.9.7",
    "oscarotero/env": "^1.1.0",
    "roots/wp-password-bcrypt": "1.0.0",
    "johnbillion/extended-cpts": "^4.2",
    "advanced-custom-fields/advanced-custom-fields-pro": "*",
  },

I think Iā€™ve twiddled and fiddled with everything so much that Iā€™m not sure where everythingā€™s being set any more.

Any help much appreciated.

Did you run composer update after this? If so, did it say it was installing? Did it give an error?

Hi,

Yes I did and everything seemed fine.

Itā€™s put all the files in the site/vendor folder and not in the web/app/themes/theme-name/vendor folder. Is that right? I know it will have done this because I edited the composer.json file in the site folder and not the theme folder. Everything seems to indicate the site composer file is the right place.

Sorry, canā€™t think straight!

Are you also using hirak/prestissimo (global composer package) by chance?
There is a still open issue with hirak/prestissimo and PhilippBaschke/acf-pro-installer:

No, I donā€™t think so. How would I check this to be sure?

You can try to uninstall it:

$ composer global remove hirak/prestissimo

It is also possible to re-install it (but then the ACF installer wouldnā€™t work):

$ composer global require hirak/prestissimo

I tried to uninstall it but I donā€™t think it was installed. I get a runtime exception:
[RuntimeException]
Could not read ./composer.json

  file_get_contents(./composer.json): failed to open stream: No such file or   
  directory

BTW I highly recommend adding fields by PHP includes in your theme. Much more reliable than JSON files. Iā€™ve had instances where fields on development have been overwritten on deploy by outdated JSON files.

As an added benefit the fields canā€™t be edited in the Dashboard either.

Hi Simeon,

I agree. The main problem is that it doesnā€™t copy the ACF plugin files across at all so the site shows nothing until I copy those files across manually. Iā€™d just love to be able to get it all working properly so that I know that I can always recreate the site no matter what happens and I wonā€™t have to remember various steps in the process.

Iā€™ll look further into use PHP instead of JSON.

Thanks.