title: selenium.common.exceptions.WebDriverException with Selenium Firefox Webdriver script from PHP/Apache
body: <p>We are calling a python/selenium script which utilizes the firefox webdriver.</p>
  
  <p>The script works fine when run from the command line, but when called using a system/exec call from PHP via Apache, we are seeing the following error(s) in the apache logs:</p>
  
  <pre><code>selenium.common.exceptions.WebDriverException: Message: 'The browser appears to have 
  exited before we could connect. 
  The output was: \n(firefox-bin:16178): libgnomevfs-WARNING **: 
  Unable to create ~/.gnome2 directory: Permission denied\nSegmentation fault\n' 
  </code></pre>
  
  <p>The point of failure is directly after the web driver tries to spawn the virtual browser using:</p>
  
  <pre><code>display = Display(visible=0, size=(1000, 800))
  display.start()
  browser = webdriver.Firefox()
  </code></pre>
  
  <p>Has anyone come across this before? After a lot of trying, I have been unable to find a clear-cut solution. I'm presuming it is something to do with permission differences between running via cli compared to running through apache.</p>
  
  <hr>
  
  <p>The root cause was permissions: I found that executing the script via the command line as the apache user gave a more informative error:</p>
  
  <pre><code>sudo -u www-data python &lt;script&gt;
  </code></pre>
  
  <p>I needed to add a .gnome and .gnome_private directory to the web server root (/var/www/), then chown it to be owned by www-data.</p>