1

我正在尝试在 UBuntu 上运行一个 php 项目。它有一个创建 mysql 数据库的安装脚本。当我尝试运行脚本时,出现以下错误:

Warning: fopen(dbinfo.php): failed to open stream: Permission denied in /opt/lampp/htdocs/project/install.php on line 12

Warning: fwrite() expects parameter 1 to be resource, boolean given in /opt/lampp/htdocs/project/install.php on line 19

Warning: fclose() expects parameter 1 to be resource, boolean given in /opt/lampp/htdocs/project/install.php on line 20

Warning: include(dbinfo.php): failed to open stream: No such file or directory in /opt/lampp/htdocs/project/install.php on line 21

Warning: include(): Failed opening 'dbinfo.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/project/install.php on line 21

Notice: Undefined variable: host in /opt/lampp/htdocs/project/install.php on line 23

Notice: Undefined variable: user in /opt/lampp/htdocs/project/install.php on line 23

Notice: Undefined variable: password in /opt/lampp/htdocs/project/install.php on line 23

Notice: Undefined variable: database in /opt/lampp/htdocs/project/install.php on line 25

Notice: Undefined variable: database in /opt/lampp/htdocs/project/install.php on line 26
Error connecting to database.

我知道这些错误是由于权限被拒绝造成的。但我不知道如何解决这个问题。似乎该脚本没有编辑或创建数据库的权限。我是 Ubuntu 新手,无法解决这个问题。抱歉英语不好。

4

1 回答 1

8

我假设您的用户可能拥有权限/opt/lampp,因此您可以编辑文件。但是,如果不是这种情况,您可以授予对您的用户和 apache 组的访问权限。下一个显示首先是用户,然后是组:

sudo chown -R youruser:www-data /opt/lampp

In that way you're setting the ownership to the user and then the group. After that you must grant the access for the three groups: User, group and others:

sudo chmod -R xxx /opt/lampp

Note: The rightmost refer to permissions for the file owner, then the group and other users.

Now, what does the xxx mean?

No - Permission - rwx

7 - full - 111

6 - read and write - 110

5 - read and execute - 101

4 - read only - 100

3 - write and execute - 011

2 - write only - 010

1 - execute only - 001

0 - none - 000

Or you can use:

chmod [reference][operator][mode] fileOrFolder

Where the reference is: u(ser), g(roup), o(thers) and a(ll).

The operator is: + (adds the specified modes to the specified references), - (removes) and = (the modes specified must be made the exact modes for the specified references)

Finally the modes are: r(ead), w(rite), x(execute), [X(special execute), s and t (that are not so common)].

Hope this is what you're looking for.

于 2013-04-05T02:57:29.053 回答