edwardspec / mediawiki-aws-s3

Extension:AWS allows MediaWiki to use Amazon S3 (instead of the local directory) to store images.
https://www.mediawiki.org/wiki/Extension:AWS
GNU General Public License v2.0
42 stars 32 forks source link

Use the extension for Cloudflare R2 #79

Closed songnguxyz closed 5 months ago

songnguxyz commented 5 months ago

Cloudflare R2 is believed to have almost the same compatibility, so I can technically use it, but I can't get it working.

So here is what I use to setup with R2:

// THIS IS NOT NEEDED if your EC2 instance has an IAM instance profile.
$wgAWSCredentials = [
    'key' => 'MY_KEY',
    'secret' => 'MY_SECRET_TOKEN',
    'token' => false
];

$wgAWSRegion = 'apac'; # Northern Virginia

// Replace <something> with the name of your S3 bucket, e.g. wonderfulbali234.
$wgAWSBucketName = "MY_R2_BUCKET_NAME";

// If you anticipate using several hundred buckets, one per wiki, then it's probably better to use one bucket
// with the top level subdirectory as the wiki's name, and permissions properly configured of course.
// While there are no more performance losses by using such a scheme, it might make things messy. Hence, it's
// still a good idea to use one bucket per wiki unless you are approaching your 1,000 bucket per account limit.
$wgAWSBucketTopSubdirectory = "/$wgDBname"; # leading slash is required

//The url used for the API (PutObject, etc.)
$wgFileBackends['s3']['endpoint'] = "https://<CLOUDFLARE_ACC_ID>.r2.cloudflarestorage.com";
$wgAWSBucketDomain = 'MYTESTDOMAIN';
edwardspec commented 5 months ago

Check the debug log (for errors or anything suspicious):

$wgDebugLogGroups['FileOperation'] = '/path/to/some/writable/file.log';
songnguxyz commented 5 months ago

I tries to do it but finds no success, so instead I first inspect PHP log and: [22-May-2024 15:17:09 UTC] PHP Warning: require_once(/home/songngu-ww2/htdocs/ww2.songngu.xyz/extensions/AWS/s3/../vendor/autoload.php): Failed to open stream: No such file or directory in /home/songngu-ww2/htdocs/ww2.songngu.xyz/extensions/AWS/s3/AmazonS3FileBackend.php on line 25

songnguxyz commented 5 months ago

So I try the dangerous one (ShowExceptionDetails) and I got this:

Original exception: [90345e3dd249047c65443dbd] /index.php?title=%C4%90%E1%BA%B7c_bi%E1%BB%87t:T%E1%BA%A3i_l%C3%AAn Error: Failed opening required '/home/songngu-ww2/htdocs/ww2.songngu.xyz/extensions/AWS/s3/../vendor/autoload.php' (include_path='/home/songngu-ww2/htdocs/ww2.songngu.xyz/vendor/pear/console_getopt:/home/songngu-ww2/htdocs/ww2.songngu.xyz/vendor/pear/mail:/home/songngu-ww2/htdocs/ww2.songngu.xyz/vendor/pear/mail_mime:/home/songngu-ww2/htdocs/ww2.songngu.xyz/vendor/pear/net_smtp:/home/songngu-ww2/htdocs/ww2.songngu.xyz/vendor/pear/net_socket:/home/songngu-ww2/htdocs/ww2.songngu.xyz/vendor/pear/net_url2:/home/songngu-ww2/htdocs/ww2.songngu.xyz/vendor/pear/pear-core-minimal/src:/home/songngu-ww2/htdocs/ww2.songngu.xyz/vendor/pear/pear_exception:.:/usr/share/php')
Backtrace:
from /home/songngu-ww2/htdocs/ww2.songngu.xyz/extensions/AWS/s3/AmazonS3FileBackend.php(25)
#0 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/AutoLoader.php(221): require()
#1 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/filebackend/FileBackendGroup.php(203): AutoLoader::autoload()
#2 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/filerepo/FileRepo.php(189): FileBackendGroup->get()
#3 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/filerepo/LocalRepo.php(84): FileRepo->__construct()
#4 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/filerepo/RepoGroup.php(417): LocalRepo->__construct()
#5 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/filerepo/RepoGroup.php(389): RepoGroup->newRepo()
#6 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/filerepo/RepoGroup.php(311): RepoGroup->initialiseRepos()
#7 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/filerepo/RepoGroup.php(345): RepoGroup->getRepo()
#8 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/specials/SpecialUpload.php(85): RepoGroup->getLocalRepo()
#9 /home/songngu-ww2/htdocs/ww2.songngu.xyz/vendor/wikimedia/object-factory/src/ObjectFactory.php(240): MediaWiki\Specials\SpecialUpload->__construct()
#10 /home/songngu-ww2/htdocs/ww2.songngu.xyz/vendor/wikimedia/object-factory/src/ObjectFactory.php(149): Wikimedia\ObjectFactory\ObjectFactory::getObjectFromSpec()
#11 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/specialpage/SpecialPageFactory.php(1471): Wikimedia\ObjectFactory\ObjectFactory->createObject()
#12 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/MediaWiki.php(304): MediaWiki\SpecialPage\SpecialPageFactory->getPage()
#13 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/MediaWiki.php(960): MediaWiki->performRequest()
#14 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/MediaWiki.php(613): MediaWiki->main()
#15 /home/songngu-ww2/htdocs/ww2.songngu.xyz/index.php(50): MediaWiki->run()
#16 /home/songngu-ww2/htdocs/ww2.songngu.xyz/index.php(46): wfIndexMain()
#17 {main}

Exception caught inside exception handler: [90345e3dd249047c65443dbd] /index.php?title=%C4%90%E1%BA%B7c_bi%E1%BB%87t:T%E1%BA%A3i_l%C3%AAn TypeError: Cannot assign null to property MediaWiki\Specials\SpecialUpload::$localRepo of type LocalRepo
Backtrace:
from /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/specials/SpecialUpload.php(85)
#0 /home/songngu-ww2/htdocs/ww2.songngu.xyz/vendor/wikimedia/object-factory/src/ObjectFactory.php(240): MediaWiki\Specials\SpecialUpload->__construct()
#1 /home/songngu-ww2/htdocs/ww2.songngu.xyz/vendor/wikimedia/object-factory/src/ObjectFactory.php(149): Wikimedia\ObjectFactory\ObjectFactory::getObjectFromSpec()
#2 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/specialpage/SpecialPageFactory.php(1471): Wikimedia\ObjectFactory\ObjectFactory->createObject()
#3 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/skins/SkinTemplate.php(1408): MediaWiki\SpecialPage\SpecialPageFactory->getPage()
#4 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/skins/SkinTemplate.php(1345): SkinTemplate->getSpecialPageAssociatedNavigationLinks()
#5 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/skins/SkinTemplate.php(604): SkinTemplate->buildContentNavigationUrlsInternal()
#6 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/skins/SkinTemplate.php(181): SkinTemplate->getPortletsTemplateData()
#7 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/skins/SkinMustache.php(125): SkinTemplate->getTemplateData()
#8 /home/songngu-ww2/htdocs/ww2.songngu.xyz/skins/Vector/includes/SkinVectorLegacy.php(161): SkinMustache->getTemplateData()
#9 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/skins/SkinMustache.php(92): MediaWiki\Skins\Vector\SkinVectorLegacy->getTemplateData()
#10 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/skins/SkinTemplate.php(174): SkinMustache->generateHTML()
#11 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/Output/OutputPage.php(2947): SkinTemplate->outputPage()
#12 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/exception/MWExceptionRenderer.php(188): MediaWiki\Output\OutputPage->output()
#13 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/exception/MWExceptionRenderer.php(105): MWExceptionRenderer::reportHTML()
#14 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/exception/MWExceptionHandler.php(134): MWExceptionRenderer::output()
#15 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/exception/MWExceptionHandler.php(251): MWExceptionHandler::report()
#16 /home/songngu-ww2/htdocs/ww2.songngu.xyz/includes/MediaWiki.php(635): MWExceptionHandler::handleException()
#17 /home/songngu-ww2/htdocs/ww2.songngu.xyz/index.php(50): MediaWiki->run()
#18 /home/songngu-ww2/htdocs/ww2.songngu.xyz/index.php(46): wfIndexMain()
#19 {main}
edwardspec commented 5 months ago

Error: Failed opening required '[...]/extensions/AWS/s3/../vendor/autoload.php'

Please follow the installation instructions in README (you didn't run the Composer).

songnguxyz commented 5 months ago

It turns out that I use CloudPanel to manage my instance and while SSH-ing I don't have enough perms, which causes the composer update not to work as intended. I logged in as root, navigated myself to the folder, and ran, which worked as expected.

Anyways to create thumbnails from S3 storage?

edwardspec commented 5 months ago

MediaWiki creates thumbnails the same way with and without this extension.