Search code examples
laravelnamespacesphp-deployer

Deployer v4.2.1 fatal error "undefined function" with officially endorsed 3rd party recipes out of the box


After a basic install of PHP deployer v4.2.1 I find that it does not work (see below) with the officially endorsed 3rd party recipes out of the box. I am fairly new to Deployer. Here is what I did.

I installed PHP deployer v4.2.1 with:

composer require --dev deployer/deployer
composer require --dev deployer/recipes

And of course I ran dep init to get set up with a basic deploy.php file.

In my deploy.php I added the following at the top:

namespace Deployer;

require 'recipe/laravel.php';
require 'vendor/deployer/recipes/local.php';
require 'vendor/deployer/recipes/rsync.php';
require 'vendor/deployer/recipes/npm.php';
require 'vendor/deployer/recipes/cachetool.php';

Then I set my git repository, server info, etc. My final deploy task runs the local:prepare command and this is where it chokes with an odd error:

PHP Fatal error:  Uncaught Error: Call to undefined function Deployer\desc() in /home/vagrant/Code/MyProject/vendor/deployer/recipes/local.php:76

Obviously there is some namespacing issue going on.

Somehow I figured out that I can get around the issue if I make a local copy (outside vendor dir) of the 3rd party recipe files, and then modify them so the calls to desc(...) follow task(...) like task(...)->desc(...). This works, but now I am running into other issues and I feel like I'm headed down the wrong path. I feel like this is an unacceptable work around for what is basically a fresh installation. The laravel.php recipe that comes bundled with Deployer calls desc(...) all by itself and not after task(...)->desc(...), so it seems to me that the 3rd party recipes should be able to handle it, but they throw an error. (Even with namespace Deployer; declared at the top, or perhaps because of it.)

Anybody else encounter this issue? Is there something simple I forgot to add to deploy.php so I don't have to modify vendor files?


Solution

  • (Going to answer my own question here...)

    I had a globally installed dep that was version 3.3.0 (installed manually without composer), and this was the file that was running everytime I typed dep instead of the newer, locally installed project version of dep. So it was trying to run 4.2.1 recipes with 3.3.0 deployer.

    Solution:

    Run this from the command line:

    php vendor/bin/dep deploy [server]
    

    instead of:

    dep deploy [server]