Running PHP as username instead of www-data

I have setup a Virtualmin server, I have chosen FCGId (run as virtual server owner). But when I execute PHP it runs as www-data instead of username, which leads to permission problems. It should run as username (same as the fileowner). How can I get it running as username?

I tried this: http://www.virtualmin.com/node/16841 (Uncommenting the handler in PHP) But then it says 'No input file specified.'

What could there be wrong?

Status: 
Active

Comments

Howdy -- when was it that you performed your Virtualmin installation?

Earlier this week (Tuesday perhaps?), a new virtualmin-base package was rolled out that should automatically comment out the SetHandler lines. If you did the install yesterday or today, that means something there didn't work right :-)

However, as far as the "No input file specified" error... what application is it that you're trying to run? Although most should work fine, some web apps may have problems running under FCGID or CGI.

One thing you might try just as a test, is to create a "test.php" in your public_html folder, and give it the following contents:

<?php phpinfo(); ?>

When you point your browser to that test.php, do you see the phpinfo output? Or do you get the "No input file specified" error?

Hi, I installed the server tonight. Following this procedure:
Added extra sources to apt-get.
()apt-get update
()apt-get upgrade

Then I downloaded the install.sh file.
()chmod +x install.sh
()./install.sh

Ran the installer.
Logged in in Webmin. Did first checks.
First check in webmin failed, I was missing suexec. So I installed suexec packages.
()apt-get install apache2-suexec-custom

I changed the first line in '/etc/apache2/suexec/www-data' to '/home' so the directory was set correctly.
I added one virtual server.
I tried to install Wordpress: uploaded files to puclic_html folder. Database was automatically created. Edited the WP-config file with correct settings.

Visited the site but I got error "“Your PHP installation appears to be missing the MySQL”, so I installed PHP5 MySQL modules
()apt-get install php5-mysql
()/etc/init.d/apache2 restart

(note: very strange that I had to install these last steps manually?)

Almost everything worked, but the permissions/user problem was there. So I searched for the solution. I found information about uncommenting and did it. After uncommenting and restarting apache I got the "No input file specified" error.
I get it while opening the normal site. Also while opening a whoami.php file (to see user) and also while opening your 'test.php'. Uncommenting fixes, but then there is the user/owner problem.

In uncommented mode test.php says this:
[code]
PHP Version 5.3.2-1ubuntu4.7

System Linux MYHOSTNAME 2.6.36 #4 SMP Sat Nov 6 13:22:47 UTC 2010 i686
Build Date Jan 12 2011 18:24:23
Server API Apache 2.0 Handler
Virtual Directory Support disabled
Configuration File (php.ini) Path /etc/php5/apache2
Loaded Configuration File /etc/php5/apache2/php.ini
Scan this dir for additional .ini files /etc/php5/apache2/conf.d
Additional .ini files parsed /etc/php5/apache2/conf.d/mysql.ini, /etc/php5/apache2/conf.d/mysqli.ini, /etc/php5/apache2/conf.d/pdo.ini, /etc/php5/apache2/conf.d/pdo_mysql.ini
PHP API 20090626
PHP Extension 20090626
Zend Extension 220090626
Zend Extension Build API220090626,NTS
PHP Extension Build API20090626,NTS
Debug Build no
Thread Safety disabled
Zend Memory Manager enabled
Zend Multibyte Support disabled
IPv6 Support enabled
Registered PHP Streams https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar, zip
Registered Stream Socket Transports tcp, udp, unix, udg, ssl, sslv3, sslv2, tls
Registered Stream Filters zlib.*, bzip2.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk
[/code]

Hrm, is there any chance I could log into your system to take a look?

It sounds like there's a couple of issues going on there, and logging into your server to take a look would be a big help in determining what those are.

If that's okay, you can email your root login details and hostname to eric@virtualmin.com.

Thanks!

Actually, I think I may see the issue.

In /etc/apache2/suexec/www-data, the first line should read:

/home

By default, it's listed as "/var/www".

There's a couple of bugs in the virtualmin-base package that are causing those issues on a new installation, we're working to get them fixed up :-)

Let us know if making that change gets things fixed for you. Thanks!

Thanks, the first line in www-data already was '/home'. I already corrected that problem, because indeed that would result in (other) problems too.

I have mailed the root login details to you. Thank you!

Okay, it looks like the issue is that the public_html folder, and all the files in it, are owned by "www-data", and not the owner of the Virtual Server, "lo1.nl.eu.org".

When FCGID/CGI mode is used, that means the web server executes the files as the user "lo1.nl.eu.org". If the files aren't owned by that user, the web server won't be able to see them.

After commenting out the SetHandler lines, I changed public_html and test.php to both be owned as the user "lo1.nl.eu.org".

However, you'd want to do the same for the other files in that directory.

You can see though that once those ownerships are updated, it does work as expected:

http://lo1.nl.eu.org/test.php

Thank you very much. I see. I indeed changed the ownerships to find out why I had the permission problem. But changing to www-data was only temporary and a 'bad' fix. Therefore I created this topic, to get everything running as 'username', so changing to www-data is not needed anymore. Only after uncommenting out SetHandler lines I forgot to change the ownership back to 'username'. A small mistake which resulted into the 'No input file specified' problem.

Changed everything back to original owners. Works perfect now. Thanks for your help. Great support!

I've got a problem here, too: To the best to my knowledge my virtualhosts run in FCGI mode and suexec is configured correctly.

phpinfo() says: GATEWAY_INTERFACE CGI/1.1

But when I let PHP create a new file it is still owned by www-data:www-data. In my view this should be someuser:someuser, shouldn't it?

I also have problems with a user wanting to use the automatic upgrade of her Wordpress installation: It doesn't work by default, but it works when I chown all her files in public_html to www-data:www-data.

So my impression is that PHP is running in CGI-Mode, but suexec has no effect, the script is still running as www-data. I also did the change of reply #4, but it didn't help.

Does anyone have an idea what to check or what to change to make it work?

Oh, apparently I've got it. I had to remove php5.load and php5.conf from /etc/apache2/mods-enabled.

It probably might have helped to comment (disable) the SetHandler directives in the php5.conf file. :)