shopware5 / SwagMediaSftp

MIT License
12 stars 6 forks source link

Adapter Class 'FlySystem' anyway i did composer install... #6

Closed Hotte512 closed 5 years ago

Hotte512 commented 6 years ago

I did install the Plugin and composer install / update on SwagMediaSftp but i get the following Error:

`me@cgn /var/www/vhosts/DOMAIN.TLD.de/httpdocs/_dev/bin # ./console sw:media:migrate --from=local --to=sftp

PHP Fatal error: Uncaught Error: Class 'League\Flysystem\Sftp\SftpAdapter' not found in /var/www/vhosts/DOMAIN.TLD.de/httpdocs/_dev/custom/plugins/SwagMediaSftp/Subscriber/AdapterCollectionSubscriber.php:48 Stack trace:

0 /var/www/vhosts/DOMAIN.TLD.de/httpdocs/_dev/engine/Library/Enlight/Event/Handler/Default.php(91): SwagMediaSftp\Subscriber\AdapterCollectionSubscriber->createSftpAdapter(Object(Enlight_Event_EventArgs))

1 /var/www/vhosts/DOMAIN.TLD.de/httpdocs/_dev/engine/Library/Enlight/Event/EventManager.php(336): Enlight_Event_Handler_Default->execute(Object(Enlight_Event_EventArgs))

2 /var/www/vhosts/DOMAIN.TLD.de/httpdocs/_dev/engine/Shopware/Bundle/MediaBundle/MediaServiceFactory.php(106): Enlight_Event_EventManager->collect('Shopware_Collec...', Object(Doctrine\Common\Collections\ArrayCollection), Object(Enlight_Event_EventArgs))

3 /var/www/vhosts/DOMAIN.TLD.de/httpdocs/_dev/engine/Shopware/Bundle/MediaBundle/MediaServiceFactory.php(130): Shopware\Bundle\MediaBundle\MediaServiceFactory->getAdapterBy in /var/www/vhosts/DOMAIN.TLD.de/httpdocs/_dev/custom/plugins/SwagMediaSftp/Subscriber/AdapterCollectionSubscriber.php on line 48

`

Adapter added to the config: `'cdn' => [

    'backend' => 'sftp',
    'adapters' => [
        'sftp' => [
            'type' => 'sftp',
            'mediaUrl' => 'https://media.DOMAN.TLDe/',
            'path' => realpath(__DIR__ . '/'),
    'host' => 'DOMAIN.TLD',
            'port' => 22,
            'username' => 'SFTPUSER',
            'password' => 'PASSWORD',
            'root' => '/var/www/vhosts/DOMAIN.TLD/httpdocs/',
    'timeout' => 10
        ]
    ]
],`

Composer: `_dev/custom/plugins/SwagMediaSftp # composer update

Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files `

Community: https://forum.shopware.com/discussion/comment/221358/#Comment_221358

Hotte512 commented 6 years ago

This ISSUE seems to happen just with Version 1.0.1!! 1.0 looks good so far (after composer install).

Also while I use 1.0 now there is an chmod issue.. what will be the best practices? Adapter-Setting and wich? I didn’t find any documentation about adapter settings in the configuration... :(

I did try stuff like that... `added it in config.php:

    'permissions' => [
        'file' => [
        'public' => 0755 & ~umask(),
        'private' => 0700 & ~umask(),
        ],
        'dir' => [
                'public' => 0777 & ~umask(),
                'private' => 0700 & ~umask(),
        ]
    ],`

but it is not working... :(

Does anyone have a hint for me? Someone use it already?

@mitelg is there any suggestion or documentation ?

teiling88 commented 6 years ago

It works with ssh keys for me. https://github.com/shopware-blog/shopware-deployment-installation/blob/master/app/config/config.php#L44

Is your SFTP Server in your known_hosts?

Hotte512 commented 6 years ago

Migration / uploading files to the sftp-server works fine. (I don‘t use ssh-key)

But after that i keep getting 403 Forbidden until i change permissions (by hand - chaos -R..) and this will again not work for new Media-files uploaded through the Backend.

teiling88 commented 6 years ago

I didn't have this kind of issue. I can upload images etc. It seems for me to be a hosting setting which causes this problem.

Hotte512 commented 6 years ago

But why should „Hosting“ (sftp-server) set chmod to rw/r/r (644 instead of 755 rwx/rx/rx) ?

teiling88 commented 6 years ago

Why does it work in my ubuntu installation environment on aws?

Maybe some default permission setting?

Hotte512 commented 6 years ago

Thx, I‘ll have a look, may be it is a user-id issue?

teiling88 commented 6 years ago

Maybe but I'm not an expert in linux permissions :-\

bcremer commented 6 years ago

Hey @Hotte512, may be this blog post of mine can help you: https://developers.shopware.com/blog/2016/02/26/file-permissions-and-umask-in-php-and-shopware/

When using the sftp-adapter the current systems umask should not be applied as a mask so you can set the permissions in absoute terms of the target system.

    'permissions' => [
        'file' => [
        'public' => 0644,
        'private' => 0600,
        ],
        'dir' => [
                'public' => 0755,
                'private' => 0700,
        ]
    ],
Hotte512 commented 6 years ago

Hey @bcremer thanks, but sadly this seems not to work out permission problem... i also tryed 777, no change:/

'permissions' => [ 'file' => [ 'public' => 0777, 'private' => 0777, ], 'dir' => [ 'public' => 0777, 'private' => 0777, ] ],

I keep getting 403 Forbidden, which disapperas if i do an chmod -R .... on the media folder.

On the hosting site @teiling88 (also thx for that idear) I assume it not to be an issue with User-ID or ownership on the server and the user privileges might be set while putting the file there via sftp or not? chmod is helping, not chown.... so may be the group needs r-x on my setup? as my apache user is "www-data" and my sftp user is "mrmedia"? But this might be a common configuration? @teiling88 How is your setup / config for that? What are your permissions on the files and folders ?

THX for the help! :-)

...May be i should move over to azure blob...

teiling88 commented 6 years ago

This is my permission setting for the media directory:

drwxrwxr-x 3 ubuntu ubuntu 4096 May  4 09:23 .
drwxrwxr-x 5 ubuntu ubuntu 4096 May  4 05:31 ..
drwxr--r-- 3 ubuntu ubuntu 4096 May  4 09:23 media

file permission

drwxr--r-- 3 ubuntu ubuntu  4096 May  4 09:23 ..
-rwxr--r-- 1 ubuntu ubuntu 26280 May  4 09:23 Traubenbatterie-CloseUp-Top_600x600@2x.jpg
Hotte512 commented 6 years ago

And Files / Folder get 644 / 755?

For me sftp-adapter leaves both (file&folder) at 744 atm, even with 777 in config. :/ If I change file (the.jpg) to 644 rw-r--r-- and folder to 755 rwxr-xr-x by hand it works...

Some more Suggestions?

Hotte512 commented 6 years ago

I did trie again and agin, but some how it won't work => Still keep getting 403 for some reason...

On my Shopware Serer the permission of media folders is rwx r-x r-x (755) and file rw- r-- r-- (644) so why isn't it the same on sftp host?

Any idea how to give www-data permission on that file or change the given chmod from/in/with sftp-Adapter? "I stand on the hose" Only workaround idea so far is CRON a chmod.... :-/

@teiling88 is ubuntu also your sftp user-account? And Apache is running as www-data? And what kind of user is ubuntu?

teiling88 commented 6 years ago

SFTP and Apache are running under the user ubuntu and group ubuntu.

Hotte512 commented 6 years ago

But should it not be possible to set same permission as on the master System ?

'permissions' => [

Seems not to work with sftp, is that ight ?

And by the way, little OT: How are you dealing with testenvirement and S3 / SFTP -Adapters ??

THX

herweck commented 5 years ago

The require_once statement in

Subscriber/AdapterCollectionSubscriber.php

misses '../' in the path directive to find the autoload.php. Changed to the following and the error from the issue is gone (at least by us).

if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}