title: PHP/Ubuntu - QxcbConnection: Could not connect to display aborted
body: <p>I am using a php script on my apache/ubuntu server to call a bash script that triggers an application taking a python script as an argument (IDAPro).</p>
  
  <p>PHP Code</p>
  
  <pre><code>chdir('/var/www/dashboard/team/static/sql');
  $output = exec('sudo -u rohan ./start.sh');
  </code></pre>
  
  <p>Now, the above code works fine if I run the PHP file from the terminal - but only if I run it as the root user. Needless to say, if I execute the bash file directly it runs too. </p>
  
  <p>But when I run the PHP file on the browser, it doesn't work and I get the following error in the apache error log:</p>
  
  <pre><code>QXcbConnection: Could not connect to display
  Aborted
  </code></pre>
  
  <p>I understand that Apache/php runs as 'www-data' user (used the 'whoami' to verify), and that is why I have the sudo in my exec. I have tweaked and tinkered the permissions for both users to no avail. When I run the php file from the terminal as the 'www-data' user, it throws no error but does not do anything except display the random echo tags I at the start and end of the script to debug it.</p>
  
  <p>I am a linux novice, so any help is greatly appreciated.</p>