Apache2 server run script as specific user
<p>I am using Ubuntu server 12.04 to run Apache2 web server.</p>

<p>I am hosting several webpages, and most are working fine.</p>

<p>One page is running a cgi script which mostly works (I have the python code working outside Apache building the html code nicely.)</p>

<p>However, I am calling a home automation program (heyu) and it is returning different answers then when I run it in my user account.</p>

<p>Is there a way I can...</p>

<p>1 call the heyu program from my python script as a specific user, (me) and leave the rest of the python code and cgi code alone?</p>

<p>2, configure apache2 to run the cgi code, as a whole, as me? I would like to leave all the other pages unchanged. Maybe using the sites_available part.</p>

<p>3, at least determine which user is running the cgi code so maybe I can get heyu to be OK with that user.</p>

<p>Thanks, Mark.</p>

<p>Seeing as you are using python, you can use the following to extract the user that the python script as running as;</p>

<pre><code>from getpass import getuser
print getuser()
</code></pre>

<p>When you hit the page, you'll get the username that the script ran as - and you can from there adjust the permissions of that specific user accordingly.</p>

php python apache