How can I run Firefox on CentOS with no display?
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.
Eric
Updated on September 18, 2022Comments
-
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 over 8 yearsI find it very strange that a question that has been starred 13 times is closed as "too localized".
-
Marek Rost almost 8 yearsExactly, 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 over 12 yearsWow! 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 over 12 yearsBy the way-- how can I "shut down" the Xvfb display when I'm done with everything?
-
cjc over 12 yearsYou 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 over 12 yearsGot 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 over 5 yearsThis 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