Debug School

rakesh kumar
rakesh kumar

Posted on

Larvel Error:file_put_contents(oldkey.pem): Failed to open stream: Permission denied

My code is

    public function storeWebToken(Request $request)
    {
        $key_pair = openssl_pkey_new(array(
            'private_key_bits' => 1024,
            'private_key_type' => OPENSSL_KEYTYPE_RSA,
        ));
        // Get the private key string
        openssl_pkey_export($key_pair, $private_key);
        // Get the public key string
        $public_key = openssl_pkey_get_details($key_pair);
        $public_key = $public_key["key"];
        // Use the private key to sign some data
        $encoded_public_key = base64_encode($public_key);
        $email = $request->input('email_address');
        $admin_id = $request->input('admin_id');
        $currentDate = Carbon::now()->toDateString();
        $key = Str::random(10);
        $admin_email = $request->input('admin_email');
        $u_org_slugname = $request->input('u_org_slugname');
        $u_org_organization_id = $request->input('u_org_organization_id');
        $u_org_role_id = $request->input('u_org_role_id');
        $input = $request->all();
        log::info("yanha daya axfs");
        log::info($input);
        $merge = $email . '.pem';
        $merge1 = $email . 'privatekey' . '.pem';
        $newkey = 'key' . $key;
        $mywebtoken = Mywebaccesstoken::where('u_org_organization_id', $u_org_organization_id)->where('token', $merge)->first();
        if (!$mywebtoken) {
            log::info("else yanha daya axfs");
            $myModel = new Mywebaccesstoken;
            $myModel->token = $merge;
            $myModel->admin_id = $admin_id;
            $myModel->keydate = $currentDate;
            $myModel->keyid = $newkey;
            $myModel->pubkey = $encoded_public_key;
            $myModel->keydate = $currentDate;
            $myModel->admin_email = $admin_email;
            $myModel->u_org_slugname = $u_org_slugname;
            $myModel->u_org_organization_id = $u_org_organization_id;
            $myModel->u_org_role_id = $u_org_role_id;

            $myModel->save();
            $data = "Hello, world!";
            openssl_sign($data, $signature, $private_key, OPENSSL_ALGO_SHA256);
            $validToken = sha1(time()) . rand();
            $privatekey = array(
                'admin_id' => $admin_id,
                'email' => $admin_email,
                'token' => $merge,
                'private_key' => $private_key,
            );
            $file = 'oldkey.pem';
}
Enter fullscreen mode Exit fullscreen mode

I got Errors

file_put_contents(oldkey.pem): Failed to open stream: Permission denied

Solution

Method1:

chmod 755 /path/to/your/directory

Enter fullscreen mode Exit fullscreen mode

Image description

Method2
step1

ls -l /path/to/your/directory
Enter fullscreen mode Exit fullscreen mode

step2
Image description

step3
Image description

Top comments (0)