title: KnpSnappyBundle - stderr: "wkhtmltopdf: cannot connect to X server " stdout: ""
body: <p>I'm trying to use the <a href="https://github.com/KnpLabs/KnpSnappyBundle" rel="nofollow noreferrer">KnpSnappyBundle</a> to create PDF files from twig templates.</p>
  
  <p>I've followed this <a href="https://stackoverflow.com/questions/9604625/wkhtmltopdf-cannot-connect-to-x-server">post</a> to install <code>wkhtmltopdf</code> and it works when I do:</p>
  
  <pre><code>wkhtmltopdf http://www.google.com test.pdf
  </code></pre>
  
  <p>but when I try to create a PDF file from a controller:</p>
  
  <pre><code>$this-&gt;get('knp_snappy.pdf')-&gt;generateFromHtml(
  $this-&gt;renderView('AcmePDFBundle:Default:template.html.twig'),
  '../app/var/PDFfiles/PDF.pdf'
  ); 
  </code></pre>
  
  <p>I'm getting this error:</p>
  
  <pre><code>request.CRITICAL: RuntimeException: The exit status code '1' says something went wrong:
  stderr: "wkhtmltopdf: cannot connect to X server
  "
  stdout: ""
  command: /usr/bin/wkhtmltopdf --lowquality '/tmp/knp_snappy532ca2272fba44.73835084.html' '../app/var/files/PDF.pdf'. (uncaught exception) at /home/me/MyServer/project/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php line 304 [] []
  </code></pre>
  
  <p>Any idea of how to solve it?</p>
  
  <p>This is my configuration for KnpSnappyBundle:</p>
  
  <pre><code>knp_snappy:
      pdf:
          enabled:    true
          binary:     /usr/bin/wkhtmltopdf
          options:    []
      image:
          enabled:    false
          binary:     /usr/bin/wkhtmltoimage
          options:    []
  </code></pre>