I would like to publish the file manifest.webmanifest on Laravel Vapor. I've tried to serve it on the root domain (docs):
# vapor.php
...
'serve_assets' => ['manifest.webmanifest'],
...
Vapor handles that route, but throws an exception:
Client error: `GET https://xxxx.cloudfront.net/xxx/manifest.webmanifest` resulted in a `404 Not Found` response:
After further inspection this is logical, because the file is never send to the S3 bucket. It appears that Laravel/VaporCli/AssetFiles filters files like *.webmanifest, manifest.json and mix-manifest.json.
No clue why it does that. Does anyone have a trick to get the job done?
A developer working on Vapor replied and said changing it isn't possible right now because it will be a breaking change. He suggests adding a route that returns the content of the manifest.
I've added this route to my project:
Route::middleware('cache.headers:public;max_age=7200')->get(
'/manifest.webmanifest',
function (): string {
return file_get_contents(public_path('manifest.webmanifest'));
}
)
Related
First of all, sorry if this question is answered anywhere else, but I could not find the answer I needed so I'll ask again.
I am using laravel to create a REST API which I serve through Docker. Therefore I can reach the API through http://localhost:8888. For example, I have an endpoint /content/fetch/{env_type} which works fine through http://localhost:8888/api/content/fetch/test.
My problem is that I have some images in the (from Laravel root dir) directive /public/images/content/test. I was under the assumption that I would be able to reach these images in my frontend app using <img src="http://localhost:8888/images/content/test/myimage.jpg" /> but this does not work.
I have tried adding public/ before images/... but that did not work either. I also tried the URL to the image in the browser directly, and got 500 Internal Server Error:
Request URL: http://localhost:8888/images/content/test/myimage.jpg
Request Method: GET
Status Code: 500 Internal Server Error
Remote Address: 127.0.0.1:8888
Referrer Policy: no-referrer-when-downgrade
Looking in the laravel log I get this: production.ERROR: Uncaught ErrorException: file_put_contents(/var/www/storage/framework/views/ba2564046cc89e436fb993df6f661f314e4d2efb.php): failed to open stream: Permission denied in /var/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122
I know what it means but it feels strange that I should have to change the permissions for basically the entire vendor folder.
So my guess is that I am approaching this wrong. Does anyone have an idea how I should do this instead?
I'm attempting to use Google's Natural Language API for PHP, and having followed the instructions, I'm getting an error in the application I've written:
Fatal error: Uncaught Google\Cloud\Core\Exception\ServiceException: {
"error": { "code": 403, "message": "The request is missing a valid API
key.", "status": "PERMISSION_DENIED" } }
I've downloaded the account key file, run the export, but I get the 403 error.
I've created a symbolic link to the file in the project folder, run the export, but I get the 403 error.
I placed the export in the ".bash_profile" file, exited the terminal session, but I get the 403 error.
Provide authentication credentials to your application code by setting
the environment variable GOOGLE_APPLICATION_CREDENTIALS. Replace
[PATH] with the file path of the JSON file that contains your service
account key, and [FILE_NAME] with the filename. This variable only
applies to your current shell session, so if you open a new session,
set the variable again.
When I ran: echo $GOOGLE_APPLICATION_CREDENTIALS the export isn't there, so I ran it again, but I get the 403 error.
I followed the documentation to the letter, and I've gone through it three times, and each time I get the same 403 error.
I see no instructions asking me to store a string value for the API key in the application, but I've found a number of people recommending that, but not provide an example of how or where.
So, some advice would be welcome!
simply do not use an export; while your ~/.bashrc is not apache's .bashrc.
but add the path to the file directly into the PHP code; eg. into a config.php.
or use putenv('GOOGLE_APPLICATION_CREDENTIALS=/var/www/[FILE_NAME].json');
while preventing HTTP access to that file with .htaccess.
or one can even setup with .htaccess, alike
SetEnv GOOGLE_APPLICATION_CREDENTIALS "/var/www/[FILE_NAME].json"
I have a public S3 bucket called latheesan-public-bucket (for example) in AWS in the eu-west-1 region.
If I were to visit the following url in the browser (for example):
https://latheesan-public-bucket.s3-eu-west-1.amazonaws.com/
I get the following XML showing that I have one file in the bucket:
<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Name>latheesan-public-bucket</Name>
<Prefix />
<Marker />
<MaxKeys>1000</MaxKeys>
<IsTruncated>false</IsTruncated>
<Contents>
<Key>test.json</Key>
<LastModified>2017-07-11T16:39:50.000Z</LastModified>
<ETag>"056f32ee5cf49404607e368bd8d3f2af"</ETag>
<Size>17658</Size>
<StorageClass>STANDARD</StorageClass>
</Contents>
</ListBucketResult>
If I were to then visit https://latheesan-public-bucket.s3-eu-west-1.amazonaws.com/test.json I can download my file from my public bucket.
In order to achieve the same in my Laravel application; I first added this package via composer:
league/flysystem-aws-s3-v3
Then on my .env I've added the following lines:
AWS_REGION=eu-west-1
AWS_BUCKET=latheesan-public-bucket
Lastly, I then tried to use the laravel filesystem to access the public s3 bucket file like this:
$json = Storage::disk('s3')->get('test.json');
When I did this; I got the following error:
Error retrieving credentials from the instance profile metadata
server. (cURL error 28: Connection timed out after 1000 milliseconds
(see http://curl.haxx.se/libcurl/c/libcurl-errors.html))
So, I updated my .env with some fake credentials:
AWS_KEY=123
AWS_SECRET=123
AWS_REGION=eu-west-1
AWS_BUCKET=latheesan-public-bucket
Now I get this error:
Illuminate \ Contracts \ Filesystem \ FileNotFoundException
test.json
So my question is; firstly what am I doing wrong here? Is there no way to access a public s3 bucket in laravel without actually providing a valid S3 Key/secret? what if I don't know them? I only have the url to the public s3 bucket.
P.S. the latheesan-public-bucket does not exist (it was a dummy bucket name to explain my problem, I do have a real public bucket I am trying to work with and it works fine in browser as explained above).
When you try to access it via the HTTPS URL, it works because it is public, and you're
When you try to access it via the SDK, it is trying to use the API to access it.
So either give your instance profile the correct permissions to access the bucket (which would no longer need to be public) or simply use an http client to retrieve the file.
If you use the S3 API to access your bucket, AWS credentials are required. The reasons is that the API needs to sign the S3 request.
So I'm creating a route that requires posting. The route is as follows:
my_route:
path: /myroute/login
defaults: { _controller: "MyBundle:Default:login"}
methods: [POST]
So I use postman to hit app_dev.php/myroute/login and I get the correct response that I am looking for, currently the page just returns "hello world". Now when I change postman to just hit app.php/myroute/login I get an error saying:
The server returned a "405 Method Not Allowed".
I'm really confused as to why it says method not allowed so I tailed the prod.log file and got the following:
Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: "No route found for "GET /myroute/login": Method Not Allowed (Allow: POST)"
I'm sending the requests in postman as POST requests but somehow symfony is only seeing them as GET requests. Again I can change the url to app_dev.php/myroute/login and hit send and it works. I thought it was a caching issue so I tried the following to clear the caches:
$ php app/console cache:clear --env=prod --no-debug
This still doesn't clear my problem so I even removed all the files from app/cache/prod as well. I can't find anyone having issues that are similar to this so I'm hoping someone can point me in the right direction. I also thought it might be
After some more digging I discovered what the issue was. So I thought that maybe it was postman that was sending the incorrect method so I googled around for that which lead to this
Postman sending POST as GET
which lead to a question about htaccess files:
Redirect POST htaccess
So first off I set postman to hit app.php/myroute/login and xdebug showed the request method as GET. I moved the .htaccess file and hit the same url and the request method showed up as POST. Instead of hitting that url I moved my .htaccess file back and pointed at just /myroute/login and everything lit up. This was an extremely annoying exercise so I hope that this will save someone else in the future looking for the same problem.
for me the case was my mistake, i.e. i was sending to http instead of https
I am doing Push Notification Service for Apple iphone/ipad. i got the server side code from http://code.google.com/p/apns-php/. it is working well.. but i have to implement it in Yii framework.
i have googled it. and got this
https://github.com/shiki/yii-apns
Here i need to set server_certificates_bundle_sandbox.pem, and device token dynamically at run time.I am new to yii..please help me how to use this component..
i have extracted all the files in components folder,and tried the below code.
$obj=new SAPNS();
$obj->providerCertificateFilePath="provider certificate file path";
$obj->rootCertificationAuthorityFilePath="root certificate path";
$obj1=$obj->getPushProvider();
but while calling getPushProvider method,i got the following error.
include(ApnsPHP_Push.php): failed to open stream: No such file or directory
There is no such a file ApnsPHP_Push.php in ApnsPHP folder in my components folder.dont know in which part i did mistake..
the guys has already wrapped up everything in a component, so you just need to put all the things in components directory and call the desired functions.
if you look at SAPNS.php its got a public property
$providerCertificateFilePath
and that will be the file path to your PEM file and other
$rootCertificationAuthorityFilePath
for secure certificate (if any).
After giving these values you have to call getPushProvider method that will give you an object for ApnsPHP_Push from here you can call this class normally as you do without framework.