How do I tell the Laravel filesystem layer to use the s3 metadata on an EC2 instance? I don't want to provide hardcoded keys and secrets for my s3 buckets. I'm unclear on what the configuration should look like. When I exclude the key and secret from the filesystem configuration I get the following error
ErrorException
Undefined index: key
The fix is to leave empty placeholder values in place for key and secret. eg, in config/filesystems.php
return [
'cloud' => 's3',
'disks' => [
's3' => [
'driver' => 's3',
'key' => '',
'secret' => '',
'region' => env('S3_REGION'),
'bucket' => env('S3_BUCKET'),
],
],
];
The correct way to provide your credentials is by using the .env file.
In your .env file, add something like that:
EC2_SECRET=your_ec2_secret
EC3_KEY=your_ec2_key
and in the `` config file, use something like that:
'ec2' => [
...
'key' => env('EC2_SECRET'),
'secret' => env('EC3_KEY'),
],
You should now be able to use the service without having the credentials stored in the repository.
Related
I have a website built with Laravel. I need to fetch files from my nextcloud storage and display in the website. I have successfully installed sabre/dav to create a webdav.
$settings = array(
'baseUri' => 'https://cloud.example.com',
'userName' => 'admin',
'password' => 'password'
);
$client = new \Sabre\DAV\Server($settings);
dd($client);
First I am getting 500 internal server error in dd($client) response. Second I don't know what is next. I am stuck here your help will be much appreciated
achieved laravel + nextcloud working with this config:
installed https://github.com/protonemedia/laravel-webdav
config/filesystems.php
'disks' => [
...
'webdav' => [
'driver' => 'webdav',
'baseUri' => env('NEXTCLOUD_URL'),
'userName' => env('NEXTCLOUD_USER'),
'password' => env('NEXTCLOUD_PASSWORD'),
'pathPrefix' => 'remote.php/dav/files/USERNAME_HERE/', // pay attention on closing slash
],
],
.env
NEXTCLOUD_URL=https://nextcloud_base_url/ #https://nextcloud.example.com/
NEXTCLOUD_USER=username
NEXTCLOUD_PASSWORD=password
now you can use laravel Storage fasade like Storage::disk('webdav')->files('folder'). One thing to mention - this package can't Storage::disk('webdav')->url('path') (error This driver does not support retrieving URLs)
I want to define some of my configuration in one file.
I want to put in config/app.php define("PATH", "path/to/uploaded/files");
and use it in config/filesystems
'local' => [
'driver' => 'local',
'root' => PATH,
],
It's a bad idea to put this data into app.php and then use it in filesystems.php. You should add PATH to the .env file, because PATH will be different for each machine:
PATH=path/to/uploaded/files
And then use this variable in the filesystems.php:
'local' => [
'driver' => 'local',
'root' => env('PATH'),
],
Certainly you can , in your config/filesystems just include /config/app.php, then you can use variables defied in config/app.php like they are in config/filesystems.
I've install Yii2 framework using composer but get this error in my browser (on localhost):
Invalid Configuration – yii\base\InvalidConfigException
yii\web\Request::cookieValidationKey must be configured with a secret key.
How can I solve this problem?
There is this problem with basic app now https://github.com/yiisoft/yii2-app-basic/issues/69 where composer install doesn't generate this key.
You need to add this key manually.
Go to /config/web.php.
Edit the line 'cookieValidationKey' => '', to include random string (you can use anything like 'cookieValidationKey' => 'jfsbkjsbfdskjgfdskjbgfsdhjgfajds',
You need to set cookieValidationKey in the config file to a random string. The config file is located under yii/your-projectfolder/config/main-local.php if you are using Yii 2.0 Advanced Template
You need to set cookieValidationKey value in project/config/web.php at line 12.
change at:
'cookieValidationKey' => '',
replace with:
'cookieValidationKey' => 'setyourkey',
That should address the issue.
Try this
open Frontend/ config / main.php
'components' => [
'request' => [
'enableCookieValidation' => true,
'enableCsrfValidation' => true,
// 'cookieValidationKey' => 'xxxxxxx', // if u dont hv key just comment it
],
],
if you have a web.php
'components' => [
'request' => [
'enableCookieValidation' => true,
'cookieValidationKey' => 'your-validation-key',
],
I am uisn glravel 5.1 and setting up mail service with Mailgun. I've just found that my services file contains lines like the following:
'mailgun' => [
'domain' => env('<domain>'),
'secret' => env('<key>'),
],
Now for some reason, these values get ignored as-is. However, if I remove the env() method from the above, it works. So now I have this:
'mailgun' => [
'domain' => '<domain>',
'secret' => '<key>',
],
Can anyone explain why this is?
Because by
env('foo');
You are asking for the content of the "foo" constant defined in the .env file. Do you have a constant in your .env file named 'foo'?
I am using the Storage provider to upload files to rackspace like so...
$logo = $request->file('logo');
$content = fopen($logo->getRealPath(), 'r+');
\Storage::disk('cdn')->put('logo.png', $content);
Now, how can I get the url of the file above? I has been looking for a method in the API and it seems so impossible.
http://laravel.com/api/5.0/Illuminate/Filesystem/FilesystemAdapter.html
http://laravel.com/api/5.0/Illuminate/Filesystem/Filesystem.html
I usually store the disk public URL in the config/filesystems.php file. For example:
'google' => [
'driver' => 's3',
'key' => env('STORAGE_GOOGLE_KEY'),
'secret' => env('STORAGE_GOOGLE_SECRET'),
'bucket' => env('STORAGE_GOOGLE_BUCKET'),
'base_url' => 'https://storage.googleapis.com',
'public_url' => env('STORAGE_GOOGLE_PUBLIC_URL'),
],
Then in my model, I define a mutator for the field containing the file name:
public function getAvatarAttribute($value)
{
// If avatar isn't a URL, generate it
if (filter_var($value, FILTER_VALIDATE_URL) !== FALSE) {
return $value;
} else {
$disk = config('filesystems.default');
return config('filesystems.disks.'.$disk.'.public_url').'/avatars/'.$value;
}
}
This allows me:
To change the default disk at any time and immediately point all the references to my new disk.
To store actual URLs in the database if required. In my case, avatars may come from OAuth or actual file uploads, so I need to cater for both.
The issue here is the way the FlySystem adapter works.
For most operations it will just return a boolean indicating if an operation was successful or not.
Even Laravel's FlySystem wrapper also doesn't keep track of paths, so a workaround would be to build the path yourself after a successful upload.
By using the filesystem configuration, we can come up with something like this:
$cdn_url = config('filesystems.disks.cdn.container').'/logo.png';
You get the picture.
In recent Laravel releases you can customise your storage URL
https://laravel.com/docs/8.x/filesystem#url-host-customization
URL Host Customization
If you would like to pre-define the host for file URLs generated using
the Storage facade, you may add a url option to the disk's
configuration array:
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
example 'url' => 'https://cdn.example.com', or just add it to .env file ( by default for s3 it is AWS_URL)