craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.29k stars 638 forks source link

Can't use DB Backup (MAMP localhost) #1369

Closed marjorg closed 7 years ago

marjorg commented 7 years ago

Description

When I click "Start" on the DB Backup page I get a 500 (Internal Server Error) in the console and no backup is done. The error is traced to jquery.js:9175.

index.php/admin/actions/utilities/db-backup-perform-action 500 (Internal Server Error)

Additional info

angrybrad commented 7 years ago

Craft 3 doesn't do PHP based backups anymore and relies on mysqldump to be available to PHP for backup/restore operations. Can you verify the underlying error by using the database backup tool with your browser's console open, then checking the response of the request in the network tab?

fmolina24 commented 7 years ago

@marjorg So you got to add mysqldump in the path for MAMP you will need to add it here /Applications/MAMP/Library/bin/envvars if the file does not exist create it and add the following export PATH=/usr/local/bin:$PATH also make sure mysqldump is in your /usr/local/bin folder.

MAMP comes with mysqldump so if mysqldump is not in your /usr/local/bin you can create a symbolic link sudo ln -s /Applications/MAMP/Library/bin/mysqldump /usr/local/bin/mysqldump

marjorg commented 7 years ago

@takobell The solution @fmolina24 suggested worked out. Thanks! Do you still want the error from the network tab?

angrybrad commented 7 years ago

@marjorg Nope... not necessary because it's easily reproducible. Going to go ahead and close this, but made a new issue in https://github.com/craftcms/cms/issues/1372 to keep track of the behavior you saw because I'd consider that a bug.

marjorg commented 7 years ago

@fmolina24 I'm having a similar issue with "Asset Indexes". Do you know if I have to follow any similar steps to make it work?

At the moment I can't select files through the Assets entry field and I think it might be tied to the "Assets Indexes". When I press "Start" under "Utilities" > "Asset Indexes" I get a 400 (Bad request) error.

Console error: http://i.imgur.com/vn1PSYN.png

angrybrad commented 7 years ago

@marjorg I just tested and the Update Asset Indexes utility does successfully complete for me, even through a 400 Bad Request is generated at the end of it. I've created an issue for that here: https://github.com/craftcms/cms/issues/1373

bertoost commented 6 years ago

Too bad! When using Docker, mysql is no longer inside the same container as the PHP is. Therefor it's not possible to execute mysqldump. Now I have to implement it myself :-(

narration-sd commented 6 years ago

@bertoost Don't think you should have to do that.

Look into links and ports commands for docker-compose. And configure your database to use port for access, rather than a named pipe....

bertoost commented 6 years ago

I don't know exactly what you mean @narration-sd but of course is my mysql container accessible via a host and port inside my docker-network and from the host (by localhost:3306) otherwise my projects couldn't connect to the database either. So I don't know how links and ports could help for that. The mysqldump command is just not available on the localhost from the php-container.

narration-sd commented 6 years ago

Well, it's late here, and more than a year since building up a containerized Craft site, but it seems the answer is still straightforward. Let me explain what I'm thinking, anyway, and maybe it can be useful.

The 'userland', the application program set we are used to on Linux is very limited on each bare Docker container, until we specifically install the programs we want there -- it's only the kernel that's shared from the platform the containers run on. This is particularly so if you may be using Alpine for example, as I did, which is very slimmed indeed. So then you need to add any additional features you want, through the Dockerfile of each container where you want them.

You may be already getting the Maria/MySql tools automatically with the install of the database itself, into your presumed separate database container, but if so could only be using them there.

Since you want mysqldump to be available to Craft, though, the package for it needs to be installed separately on the php-fpm container.

For Alpine even, the package you want is directly supported, and you'd add a call apk add mysql-client to the php-fpm Dockerfile, quite possibly as part of a larger RUN command for your other packages.

For a container base of a Linux variety that supports apt, the call should be apt install mysql-client, unless it's apt-get for a particularly slimmed or older version.

The package mysql-client includes mysqldump, along with the other normal utilities.

I looked, and this is what I've done on that operating Dockerized Craft. I haven't exercised it with recent versions, but the result should be the same, and I believe should work for you.

Apologies that I misunderstood at first your brief comment about what was missing -- yes, if you've separated container abilities in the way I have and I think you have, you've already handled the inter-container networking, so that Craft would be able to see the database itself.

bertoost commented 6 years ago

Thanks @narration-sd for the excellent explanation! Therefor, that's not (as far I am used to) the idea of running containers. They should do one thing, one task. So a PHP container should only contain PHP stuff. So in my/our PHP containers only PHP tools are installed (and php extensions we need). Nevertheless; I/we have other tools installed in our PHP container to run things, like Git for example (since we use the Git version tag in our projects). Since database backups are of course very important, I will check out what the impact will be to install the mysql-client in our PHP containers. Apart from that I still think this should not work like that.

[edit] Just to let you know... Installing mysql-client in the PHP container solves it.

narration-sd commented 6 years ago

hallo again @bertoost -- good, that should get you on your way.

And I wouldn't be too intense about conceptual purity for things like this. Functionally, you are still pure -- the php-fpm container still provides just what that execution environment needs.

To enable the functionality, you include the necessary tools. It's the way containers are designed to be implemented; the reflection of the basis slim-down which gets you size efficiency, rather than including all the possible functionality, much of which you will not need.

I feel that partitioning thinking this way works... :) And, good fortune your direction.

rayhatfield commented 6 years ago

Hoping this will save someone the time and trouble I went through trying to get this to work under MAMP Pro (4.5).

Look at /Applications/MAMP/Library/bin/apachectl for the following block:

# pick up any necessary environment variables
if test -f /Applications/MAMP/Library/bin/envvars; then
  . /Applications/MAMP/Library/bin/envvars
fi

That tells you where it's looking for envvars. The envvars filename seems to have changed with different versions of MAMP (leading underscore, trailing underscore, no underscore).

I duplicated and renamed /Applications/MAMP/Library/bin/envvars_ to /Applications/MAMP/Library/bin/envvars (removed trailing underscore).

I added a line before the DYLD_LIBRARY_PATH stuff. If i put this at the end it did not work for reasons that aren't clear to me and frankly I don't care about.

export PATH="/Applications/MAMP/Library/bin:$PATH"

Once I did that, saved, and restarted MAMP, the updated PATH showed up and I was able to back up the database from within Craft.

kmgdevelopment commented 6 years ago

@rayhatfield Worked for me, thanks!

benface commented 6 years ago

Thanks @rayhatfield, your solution as-is didn't work for me in the latest MAMP 5.0.4 (Apache wouldn't start), but you got me on the right track. I created a /Applications/MAMP/Library/bin/envvars file with only this line:

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin";

Then I created a symlink for MAMP's mysqldump in /usr/local/bin as mentioned earlier in this thread with:

sudo ln -s /Applications/MAMP/Library/bin/mysqldump /usr/local/bin/mysqldump

After these two things, mysqldump works both in the Terminal and in PHP.

mateostabio commented 6 years ago

Anyone have a Windows solution?? I got all this to work at home on my macbook, but here at my new job, they use Windows 10 and can get craft to export database...

angrybrad commented 6 years ago

@mateostabio System Properties->Advanced->Environment Variables->System Variables->PATH is the one you'd edit to add the path to.

mateostabio commented 6 years ago

@marjorg So you got to add mysqldump in the path for MAMP you will need to add it here /Applications/MAMP/Library/bin/envvars if the file does not exist create it and add the following export PATH=/usr/local/bin:$PATH also make sure mysqldump is in your /usr/local/bin folder.

MAMP comes with mysqldump so if mysqldump is not in your /usr/local/bin you can create a symbolic link sudo ln -s /Applications/MAMP/Library/bin/mysqldump /usr/local/bin/mysqldump

@angrybrad What I had done on my mac was this ^ But now I don't know how to run this on PC. Don't see envvars file nor do I see the mysqldump.

angrybrad commented 6 years ago

@marjorg The path to the file will depend on how/where MySQL is installed on your box. For example, it might be C:\Program Files\MySQL\MySQL Server 5.7\bin.

Then hit the Windows key and type "edit system environment variables". Open it, click Environment Variables, find "System variables" in the bottom half of the modal, find "PATH" and edit it, then add the path above that you found.