0

My goal is to configure php profiling for local development website in Kubuntu 16.04.

Installed tideways according to docs and checked it's installed correctly with:

php --ri tideways_xhprof

Created header.php with following contents

<?php 

tideways_xhprof_enable();

Added reference to it to php.ini

auto_prepend_file = "/home/user/pathto/header.php"

Restarted apache2

And getting the below errors in apache error log:

[Sat Jan 27 17:54:24.233604 2018] [:error] [pid 15976] [client 127.0.0.1:42054] PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 [Sat Jan 27 17:54:24.233653 2018] [:error] [pid 15976] [client 127.0.0.1:42054] PHP Fatal error: Unknown: Failed opening required '/home/user/pathto/header.php' (include_path='.:/usr/share/php') in Unknown on line 0

Tried adding directive

php_value auto_prepend_file /home/user/pathto/header.php 

to Directory block of the website in apache2.conf, but the same error pops.

What's wrong? What permissions are wrong? Regards.

4

1 回答 1

2

Linux 使用一种权限模型,该模型包含可以属于组的用户,以及可以分配给这些用户和组的文件和目录。默认情况下,当您在 Ubuntu 上安装 Apache 和 PHP 时,您最终会得到一个名为“www-data”的 Apache 新用户。每当 Apache 运行并需要访问文件系统时,它与任何其他用户没有什么不同,并且操作系统需要与任何其他用户相同的权限。

所以从技术上讲,如果你想在用户的主目录中使用 PHP 脚本,你必须以某种方式授予 Apache 的 www-data 用户访问那里文件的权限。

当我设置一个新服务器时,我通常会将自己添加到 www-data 组:

# add user brian to the www-data group
sudo usermod -a -G www-data brian

这使我更容易管理文件(一旦我完成了接下来的步骤),因为我不需要使用 sudo 来更改文件。

我会让 www-data 拥有 /var/www 下的所有内容

# Change all files at /var/www recursively to be owned by www-data
sudo chown -R www-data:www-data /var/www

让它在 /var/www 下创建的新文件最终归 www-data 所有:

#set the gid on any new dir inside /var/www
sudo chmod 2755 /var/www/html

然后将自己设置为所有者,而不是 www-data:

# Be the owner of all www
sudo chown -R brian:www-data /var/www

请注意,我从来没有授予/var/www 之外的权限,但这使得管理/var/www 中的文件和目录更容易,因此您不需要将PHP 文件放在您的主目录中。

于 2018-01-27T17:56:35.580 回答