1

I'm working with the KnpSnappyBundle and on trying to create a PDF I get the 500 error Warning: mkdir(): Permission denied

I've looked around and found answers for this questions but they don't seem to specifically relate to the built-in server. I do think that this is a file permissions error but I do not know how to resolve it.

For context, below is the code that is triggering the error:

/**
 * @Route("/", name="home")
 */
function mainOverview() {



    return new Response(

        $this->get('knp_snappy.pdf')
             ->generate(
                'http://www.google.fr',
                '/pdf/test.pdf' // **500 error triggers here**
             ),
        200,
        array(
            'Content-Type'          => 'application/pdf',
            'Content-Disposition'   => 'attachment; filename="file.pdf"'
        )
    );

}

EDIT 1:

Clarified that this is probably a file permissions error, rather than a coding error.

DevLime
  • 937
  • 2
  • 9
  • 19
  • 1
    not sure what generate function does but it has something to do with directory permission. Can you check and change the directory permission for the user to be able to create directory under it ? Try running chmod +755 . – Aarish Ramesh May 21 '18 at 14:28
  • Hey @Aarish. That is the problem I am having. My current knowledge of permissions and servers, I don't know how to do that in the symfony built-in server. If you could answer the question (which is probably a much simpler problem than I think it is) with how to do that I will certainly accept it as the solution. – DevLime May 21 '18 at 14:31
  • I have answered it. Please accept it if it helps – Aarish Ramesh May 22 '18 at 06:12

1 Answers1

1

The permission error is due to the fact that the owner of the process , the symfony server, does not have the permission to create folder under the root directory /

$this->get('knp_snappy.pdf') ->generate( 'http://www.google.fr', '/pdf/test.pdf' // 500 error triggers here )

So please change the directory where you generate pdf from '/pdf/test.pdf' to your home directory (~/define/your/path) or where you have permission to create destination directory solve this issue

Aarish Ramesh
  • 6,745
  • 15
  • 60
  • 105
  • Hi @Aarish. Yeah. Thought it was ridiculously simple. New framework was making me second guess myself. That has resolved the 500 error. Thanks. I think I got this far before but the new error had me thinking it was not valid. New error now but it seems to be a related to [this configuration problem](https://stackoverflow.com/questions/1763156/127-return-code-from#1763178) – DevLime May 22 '18 at 06:29