Apache running as www-data - All permission on virtual host is permission denied. Please Help

Hi

I have a virtual host which has some php files that when run generate a PDF document. As of this morning I keep getting a 500 Error. I check the apache logs and get the following error (truncated for security reasons on this public forum):

[Wed Nov 30 13:30:09.008585 2016] [:error] [pid 3480] [client 197.245.99.231:62538] PHP Warning: file_put_contents(/00000_0000000_0000000000_0000000000000_FORMAL_LETTER_30112016_133008.PDF): failed to open stream: Permission denied

I doubled checked the directory permission and the ownership and all is ok. I then noticed that the apache instance is running as used www-data and not as the virtualhost user. Is this correct?

If I change the directory owner to www-data then everything works fine, but thats not the ideal or safe solution in this instance.

Can you please help urgently...

Thanks

Status: 
Closed (fixed)

Comments

Howdy -- when using the FCGID or CGI PHP Execution Modes, that should cause your web apps to run as the Virtual Server owner.

When using mod_php, that would indeed run as the www-data user.

If you look in Server Configuration -> Website Options, what is the PHP Execution Mode set to?

its currently set to: FCGId (run as virtual server owner)

Just a note - everything was working fine till yesterday... and this morning BAM - no longer working as it used to. Could it perhaps be any updates?

If you go into System Settings -> Re-Check Config, does that detect any problems?

Also, what is the output of the command "php -v"?

hi,

no problems detected... see below:

The status of your system is being checked to ensure that all enabled features are available, that the mail server is properly configured, and that quotas are active .. Your system has 15.55 GB of memory, which is at or above the Virtualmin recommended minimum of 256 MB. BIND DNS server is installed, and the system is configured to use it. Mail server Postfix is installed and configured. Postfix can support per-domain outgoing IP addresses, but is not currently configured to do so. This can be setup in the Postfix Mailserver module. Apache is installed. The following PHP versions are available : 5.5.9 (/usr/bin/php5-cgi) Webalizer is installed. Apache is configured to host SSL websites. MySQL is installed and running. ProFTPD is installed. Logrotate is installed. The System and Server Status module is installed and checking on schedule. Plugin AWstats reporting is installed OK. Plugin Protected web directories is installed OK. Using network interface p1p1 for virtual IPs. Default IPv4 address for virtual servers is 192.168.20.9. Both user and group quotas are enabled for home and email directories. All commands needed to create and restore backups are installed. Resource limits are supported and configured correctly. The selected package management and update systems are installed OK. .. your system is ready for use by Virtualmin.

And the "php -v" is:

PHP 5.5.9-1ubuntu4.20 (cli) (built: Oct 3 2016 13:00:37) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies

Yup, that all looks good.

How about the output of this command:

grep -i sethandler /etc/apache2/mods-enabled/*.conf

/etc/apache2/mods-enabled/php5.conf:# SetHandler application/x-httpd-php /etc/apache2/mods-enabled/php5.conf:# SetHandler application/x-httpd-php-source /etc/apache2/mods-enabled/proxy_balancer.conf: # SetHandler balancer-manager /etc/apache2/mods-enabled/status.conf: SetHandler server-status

Yup, that part looks good!

One thing you may want to try is to change your PHP Execution Mode to something else, and then to change it back. That will rewrite that section of the Apache config and make sure it's correct.

If that doesn't help, it might be good to see what your phpinfo output looks like.

To do that, make a file named test.php, and give it the following contents:

<?php phpinfo(); ?>

Then, could you share the resulting URL with us?

hi

tried what you said above and got this error when setting it back to FGId: Failed to save website options : Missing or invalid website documents sub-directory...

sorry- this is the error i get:

Failed to save website options : No section found for mod_fcgid directives

Is it just this one domain that's experiencing this problem, so far as you know?

If you look in /etc/apache2/sites-enabled, you should see a "DOMAIN_NAME.conf" file with the config for this particular domain.

Can you paste in it's contents?

Assigned: Unassigned »
Status: Active » Closed (fixed)

It sounds like you were able to correct this issue? If so, that's great!

Please feel free to let us know if you have any additional questions.

I had this issue on one virtual server, getting the Drupal 7 message "Updating modules and themes requires FTP access to your server". After a lot of hunting, switching Server Config->Website options Run cgi scripts NO and to Apache mod_php, save, then switch them back again to YES and FCGid does clear the issue. Hooray!