Apache2服务器以特定用户身份运行脚本

I am using Ubuntu server 12.04 to run Apache2 web server.

I am hosting several webpages, and most are working fine.

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

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

Is there a way I can...

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?

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.

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

Thanks, Mark.

It looks like I could use suEXEC.

It is an Apache module that is not installed at default because they really don't want you to use it. It can be installed using the apt-get scheme.

That said, I found the real answer to my issue, heyu uses the serial ports to do it's work. I needed to add www-data to the dialout group then reboot.

This circumvented the need to run my code as me (as I had already add me to the dialout group a long time ago) in favor of properly changing the permissions.

Thanks.

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

from getpass import getuser
print getuser()

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.