2

I'm facing a problem with my Laravel application. It is deployed on the server and uses nginx as the main web server.

I am unable to read two files from the path I set in the deployment server, but on the local environment, it is working fine. These two files are confidential, one is .crt file and second is .pem file. I placed both of these files in laravel-app/app/Certificates directory.

laravel-app/app/Certificates/test2-2023_cert.pem

laravel-app/app/Certificates/curl-bundle.crt

The file path in .env is set like this:

PEM=/Certificates/test2-2023_cert.pem
CRT=/Certificates/curl-bundle.crt

My config/services file:

<?php

return [

    'pay' => [
        'pem' => app_path() . env('PEM', ''),
        'crt' => app_path() . env('CRT', '')
    ]

];

My Controller construct function:

public function __construct()
    {
      
        $this->pem = config('services.pay.pem');
        $this->crt = config('services.pay.crt');
    }

It is returning the following path on server:

/var/www/laravel-app/app/Certificates/test2-2023_cert.pem
/var/www/laravel-app/app/Certificates/curl-bundle.crt

but the server is not loading the file and gives me an error response in the API call. What I'm doing wrong?

Ven Nilson
  • 969
  • 4
  • 16
  • 42
  • you want just to load the path or read the file ? – Abdulla Nilam Jan 02 '23 at 05:38
  • 1
    Most likely its an issue with apache/linux and having the word "Certificates" being capital, try renaming it to lower case and see if that resolves your issue. – RG Servers Jan 02 '23 at 05:40
  • 1
    @KGG no issues if you define it correctly. As per the question, it is correct – Abdulla Nilam Jan 02 '23 at 05:41
  • @AbdullaNilam I have to read the files from the defined path. In my local Laravel app it is working fine but not on the server. – Ven Nilson Jan 02 '23 at 05:50
  • 2
    @KGG I try it but the same issue. – Ven Nilson Jan 02 '23 at 05:51
  • @VenNilson, you need API to return` app/Certificates/test2-2023_cert.pem` or contents of his file. did you try `File::get(app_path('Certificates/test2-2023_cert.pem'))` in **services.php** – Abdulla Nilam Jan 02 '23 at 05:58
  • @AbdullaNilam I called this: `InvalidArgumentException: Malformed UTF-8 characters, possibly incorrectly encoded in file` – Ven Nilson Jan 02 '23 at 06:04
  • 1
    That means that @AbdullaNilam code is working, you just have parsing of data issues, we have no idea what content is in the file or what you will do with it, are you downloading it? rendering it? how is *.pem encoded*? you can try a different approach to download: https://stackoverflow.com/questions/2236668/file-get-contents-breaks-up-utf-8-characters you can also pass a header to handle downloads examples (Content-type / Content-Transfer-Encoding) – RG Servers Jan 02 '23 at 06:13

0 Answers0