How to install Xvfb (X11 Server) in Linux Server

Xvfb is a virtual frame buffer X11 server that can be installed on linux servers without a monitor and graphics card. It can be customized for multiple displays and screens as well. In this tutorial i will show how to install, setup and configure a display. I am installing the Xvfb (X11 server) on a Centos/ Redhat linux system.

Example:

If you want to capture a screen shot but you have only a linux server running and no graphics card or monitor. To get the output you have to dump the virtual display to a file and then convert to suitable jpg or png graphics with ImageMagick

To Install Xvfb

yum install Xvfb

To intialize the display

Xvfb :1 -screen 0 800x600x24&

This sets the display number 1 and screen 0 to 800×600 resolution with the color depth of 24.

If you get error like

Fatal server error:
Couldn't add screen 0

then most probably you have set the color depth to 32bit which never worked for me. You have to set to 16 bit or 24 bit color for the virtual buffer.

To export the display to X11

export DISPLAY=localhost:1.0

If you get errors like while running Xvfb then you install necessary fonts

Could not init font path element unix/:7100, removing from list!
FreeFontPath: FPE "built-ins" refcount is 2, should be 1; fixing.

yum install xorg-x11-fonts*

It should in most cases fix the problem!

To Run a program in the virtual display

DISPLAY=localhost:1.0 firefox

Similar Posts:

Tags:

Prabhu Balakrishnan

I am cool and friendly internet entreprenur blogging since 2005. My interests are wordpress, PHP, linux servers, SEO and travel. Besides computers, i am crazy for video games, travel and a cup of hot coffee! I am born in Coimbatore, India but i currently live in Budapest, Hungary. Feel free to contact me folks!

Leave a Reply

Your email address will not be published. Required fields are marked *


+ three = 8

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please wrap all source codes with [code][/code] tags. Powered by
  1. jason

    How do you set the depth to 32 bit to actually honor alpha transparency?
    I am working with a headless system and it is not honoring alpha.

    Reply
  2. BB

    I’m getting the following errors, any idea what I’m missing? I installed the fonts like you recommended…

    $ DISPLAY=localhost:1.0 /usr/local/bin/firefox/firefox
    FreeFontPath: FPE “built-ins” refcount is 2, should be 1; fixing.
    Couldn’t open RGB_DB ‘/usr/share/X11/rgb’
    error opening security policy file /usr/lib/xserver/SecurityPolicy
    Could not init font path element unix/:7100, removing from list!

    Reply
  3. Robus

    There is actually quite a difference between 24 and 32bit. Here’s the soultion I’ve found http://robus.info/devblog/2010/04/taking-website-screenshots/

    Reply
  4. web development

    have a vps. “yum install xvfb” is not working for me. any alternative?

    web development

    Reply
  5. shulato

    at first it is working without problem but right now it’s giving me an error

    Xlib: connection to “:99.0″ refused by server
    Xlib: Invalid MIT-MAGIC-COOKIE-1 key
    CutyCapt: cannot connect to X server :99
    /usr/bin/xvfb-run: line 173: kill: (12088) – No such process

    web development

    Reply
  6. yuli chika

    Hi Dave, do u know how to set CutyCapt in php code?

    I want more setting, like photo quality, width and height of the site witch is cut, and percent of the original size.
    For example, I want to get url from http://www.google.com, cut with 1024*768(x=1024px ,y=768px, out of this size are ignored, photo quality 70%, then shrunk to 20% of the 1024*768.
    The final size may be 205*154px, this size of the thumbnail will be stored into my hard driver. I think the picture size is 30-40kb.
    Do you have any idea? send a email and teach me. Thanks.
    regards,
    Yuli Chika

    Reply
  7. Angelltroa

    Hi guys,

    I am considering to use xvfb, but my questions is:

    – Though I have to install xorg-x11-server-Xorg, can I run xvfb in init 3?

    xvfb covers a necessity I have but for security reason I would like to avoid X-windows.

    Thanks for your help !

    Reply