This tutorial explains how to run Selenium test cases with Selenium Server and PHPUnit on a Linux server that has no GUI (headless).

Make sure you have pear installed. Then upgrade to at least version 1.9.2

pear upgrade pear

Install firefox

apt-get install firefox

In order to run firefox on a headless server (means without a GUI), Xvfb (X virtual frame buffer) must be used. To install it:

apt-get install xvfb

Install Java:

apt-get install openjdk-6-jre-headless

Download Selenium Server and put it on your server, for example: /opt/selenium-server.jar. or direct link

Install PHPUnit –

pear channel-discover
pear channel-discover
pear channel-discover
pear install phpunit/PHPUnit

Now everything is installed successfully.

Let’s start things up

Xvfb :99 -ac -screen 0 1024x768x8 > /tmp/xvfb.log 2>&1 &
export DISPLAY=localhost:99.0 && java -jar /opt/selenium-server-standalone-2.0rc2.jar > /tmp/selenium_server.log 2>&1 &

Now you can execute your Selenium PHPUnit testcase.

phpunit selenium_phpunit_testcase.php