How can I run Firefox on CentOS with no display?

44,645

Use Xvfb. It gives you an X server that doesn't require connection to a physical display.

(So, on CentOS, you'd do something like "yum install xorg-x11-server-Xvfb".)

You can then start it up on display ":1" with the command "/path/on/which/installed/Xvfb :1 -screen 0 1024x768x24 &". This will create a screen with resolution 1027x768 and depth 24. Use of "&" will make the command execute in the background.

Before launching Firefox, you need to make the display accessible, which is done using the Export command - ie. "export DISPLAY=:1", pointing to whatever host is appropriate.

Share:
44,645
Eric
Author by

Eric

Updated on September 18, 2022

Comments

  • Eric
    Eric over 1 year

    I'm trying to run Firefox GUI browser on headless CentOS server in order to perform some web testing.

    I don't need to see the graphical output, because i use Selenium server API to control browser's input and inspect the output.

    The setup was successfully tested on desktop Mac computer. It, however, fails to run on my headless VPS CentOS server with following message "Error: no display specified." (Which makes sense, since it's just a server sitting on a rack someplace.)

    How can I get Firefox to run without a display, so Selenium will be able to interact with it? Or - more broadly - how do people run GUI-only applications on a Linux server when there is no display?

    I've noticed that Firefox has this command line option:

    X11 options
      --display=DISPLAY  X display to use
    

    Unfortunately I don't know anything about X11 or displays under CentOS so I don't know what to specify on the command line, or if this would help.

    • harshath.jr
      harshath.jr over 8 years
      I find it very strange that a question that has been starred 13 times is closed as "too localized".
    • Marek Rost
      Marek Rost almost 8 years
      Exactly, I'm having similar issue and both the question and the answer were beneficial to me. It definetly should be reopened in case someone finds another solution.
  • Eric
    Eric over 12 years
    Wow! Thanks! That works-- though I'm getting TONS of weird error messages from the display. I'll post a new question about those. Bottom line, despite the messages, it's working and returning the data I need. Thank you so much, this is just the help I needed.
  • Eric
    Eric over 12 years
    By the way-- how can I "shut down" the Xvfb display when I'm done with everything?
  • cjc
    cjc over 12 years
    You should be able to just kill the process. If you want to get more sophisticated, you can look into setting up start/stop scripts (if the package doesn't already provide it; it might: look in /etc/init.d for any xvfb script).
  • Eric
    Eric over 12 years
    Got it, thanks. I've posted a follow-up question regarding the info/error messages I'm seeing, in case you are looking for more reputation points :-) serverfault.com/questions/363914/…
  • TuyenNTA
    TuyenNTA over 5 years
    This answer is correct but you MUST keep in mind that the export command MUST be set on the same terminal session as the terminal you gonna run your firefox