Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8551353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:10:39+00:00 2026-06-11T14:10:39+00:00

exec(wkhtmltopdf test.html output.pdf); In the php command line it works but if I try

  • 0
exec("wkhtmltopdf test.html output.pdf");

In the php command line it works but if I try to call it from apache it doesn’t create the pdf file and the log show this:

$ tail -f  /var/log/apache2/error.log
wkhtmltopdf: cannot connect to X server
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:10:40+00:00Added an answer on June 11, 2026 at 2:10 pm

    You can use Xvfb to emulate a x-environment

    <?php exec("xvfb-run -a wkhtmltopdf test.html output.pdf");
    

    OR

    <?php exec("startx -- `which Xvfb` :1 -screen 0 800x600x24 && DISPLAY=:1 && wkhtmltopdf test.html output.pdf");
    

    I made this script for myself to get wkhtml running on centos 6+:

     yum install xorg-x11-server-Xvfb
        nano /etc/init.d/xvfbd
        #paste this:
        #!/bin/bash
    
    #
    # /etc/rc.d/init.d/xvfbd
    #
    # chkconfig: 345 95 28
    # description: Starts/Stops X Virtual Framebuffer server
    # processname: Xvfb
    #
    
    . /etc/init.d/functions
    
    [ "${NETWORKING}" = "no" ] && exit 0
    
    PROG="/usr/bin/Xvfb"
    PROG_OPTIONS=":1 -screen 1 1024x768x24 -nolisten tcp"
    PROG_OUTPUT="/tmp/Xvfb.out"
    
    case "$1" in
    start)
    echo -n "Starting : X Virtual Frame Buffer "
    $PROG $PROG_OPTIONS>>$PROG_OUTPUT 2>&1 &
    disown -ar
    /bin/usleep 500000
    status Xvfb & >/dev/null && echo_success || echo_failure
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
    /bin/touch /var/lock/subsys/Xvfb
    /sbin/pidof -o %PPID -x Xvfb > /var/run/Xvfb.pid
    fi
    echo
    ;;
    stop)
    echo -n "Shutting down : X Virtual Frame Buffer"
    killproc $PROG
    RETVAL=$?
    [ $RETVAL -eq 0 ] && /bin/rm -f /var/lock/subsys/Xvfb
    /var/run/Xvfb.pid
    echo
    ;;
    restart|reload)
    $0 stop
    $0 start
    RETVAL=$?
    ;;
    status)
    status Xvfb
    RETVAL=$?
    ;;
    *)
    echo $"Usage: $0 (start|stop|restart|reload|status)"
    exit 1
    esac
    
    exit $RETVAL
    
    
    #END
    chmod 550 /etc/init.d/xvfbd
    chkconfig xvfdb on
    service xvfdb start
    
    #Compile wkhtml compelety:
    http://code.google.com/p/wkhtmltopdf/wiki/compilation
    
    ./configure -nomake examples,demos,docs,translations -opensource -webkit -prefix "../wkqt"
    
    
    #Install fonts:
    yum install xorg-x11-fonts*
    

    After that run it in PHP:

    exec("DISPLAY=:1  timeout 60 wkhtmltoimage --height 1024 --width 1280 --quality 80 \"" . $site . "\" " . $filename);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this working fine from Linux command line: wkhtmltopdf entry.html output.pdf But the
I am using wkhtmltopdf(html to pdf converter) and am running it through a php
I'm using wkhtmltopdf to export html pages to pdf, but it seems it has
I have a working exec(java $file) command in php, but the problem is that
I'm using wkhtmltopdf on my server to transfer HTML document to PDF. It works
when I run exec('C:\execute\batfile.bat'); it works when my xampp is installed in C: but
I'm currently building a class in PHP that generates PDF documents using the WKHTMLTOPDF
Using system() or exec() , I can get any command to execute but they
I use exec function calling python script from PHP script. Python writes to standard
I want to exec my procedure from sql, but I don't know how. Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.