Unable to back-up the database from the Craft admin locally on Laravel Valet.
I've read through many similar issues regarding this and I think I've found where the problem is (vaguely) but I'm not sure where to go from here.
Here's a few things I know:
./craft backup On that last one, here's what I see in the error logs:
Could not create backup: The shell command "mysqldump --defaults-extra-file="/Users/ryan/Git/Beanstalk/clientname/storage/runtime/temp/my.cnf" --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --single-transaction --no-data --result-file="/Users/ryan/Git/Beanstalk/clientname/storage/backups/step-change-in-safety_191205_201550_p87yyvfon1_v3.3.17.sql" clientname && mysqldump --defaults-extra-file="/Users/ryan/Git/Beanstalk/clientname/storage/runtime/temp/my.cnf" --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --no-create-info --ignore-table=clientname.assetindexdata --ignore-table=clientname.assettransformindex --ignore-table=clientname.sessions --ignore-table=clientname.templatecaches --ignore-table=clientname.templatecachequeries --ignore-table=clientname.templatecacheelements --ignore-table=clientname.cache --ignore-table=clientname.templatecachecriteria clientname >> "/Users/ryan/Git/Beanstalk/clientname/storage/backups/step-change-in-safety_191205_201550_p87yyvfon1_v3.3.17.sql"" failed with exit code 127: sh: mysqldump: command not found in /Users/ryan/Git/Beanstalk/clientname/vendor/craftcms/cms/src/controllers/UtilitiesController.php:343
The mysqldump command can be found so something else is wrong (maybe). I kept an eye on the "storage/runtime/temp/" directory while pressing the Backup button and noticed the "my.cnf" file is created then instantly deleted.
So I took the above failed command, manually created a "my.cnf" file, pointed the command to that and then ran it from the command line. i.e. this:
mysqldump --defaults-extra-file="./my.cnf" --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --single-transaction --no-data --result-file="/Users/ryan/Git/Beanstalk/clientname/storage/backups/step-change-in-safety_191205_201550_p87yyvfon1_v3.3.17.sql" clientname && mysqldump --defaults-extra-file="./my.cnf" --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --no-create-info --ignore-table=clientname.assetindexdata --ignore-table=clientname.assettransformindex --ignore-table=clientname.sessions --ignore-table=clientname.templatecaches --ignore-table=clientname.templatecachequeries --ignore-table=clientname.templatecacheelements --ignore-table=clientname.cache --ignore-table=clientname.templatecachecriteria clientname >> "/Users/ryan/Git/Beanstalk/clientname/storage/backups/step-change-in-safety_191205_201550_p87yyvfon1_v3.3.17.sql"
馃挜It works!
So this is where I am, there's something going on with the my.cnf file Craft creates in the temp storage directory that prevents the command from being run.
Any ideas out there?
TIA
Hrm... not super-familiar with Valet, unfortunately.
If you create a test.php file in your public HTML folder, then put this in it:
<?php passthru('echo $PATH')
Then load that in a browser, does the path that gets output include the path to where mysqldump is located?
That's interesting, I get /usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:. which is not the same as echo $PATH in the terminal.
The output from test.php doesn't have mysqldump's location (but the "normal" $PATH does).
That reminded me of an Issue I saw yesterday, adding putenv("PATH={$_SERVER["PATH"]}:/usr/local/opt/[email protected]/bin"); to the general.php config appears to solve the problem!
Now I just need to only have that locally and not get committed to staging and production 馃
[edit] sorted that out, everything now works 馃憤
Thanks for tip Brad.
Awesome... glad you're all sorted, @RyanRoberts!
@RyanRoberts Here is a way to keep things walled off per environment -- by keeping the full paths to mysql and mysqldump in the .env file: https://packagist.org/packages/samhernandez/craft-db-paths. Same issue affects MAMP users.
@RyanRoberts Here is a way to keep things walled off per environment -- by keeping the full paths to
mysqlandmysqldumpin the.envfile: https://packagist.org/packages/samhernandez/craft-db-paths. Same issue affects MAMP users.
Thanks! That looks great.
Most helpful comment
@RyanRoberts Here is a way to keep things walled off per environment -- by keeping the full paths to
mysqlandmysqldumpin the.envfile: https://packagist.org/packages/samhernandez/craft-db-paths. Same issue affects MAMP users.