问题
I am trying to run a php project on UBuntu . It has an install script which creates the mysql database. When i try to run the script i am getting the following errors:
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.
I know these errors are due to Permission denial.But i don't know how to resolve this.It seems the script does not have permission to edit or create a databse.I am new to Ubuntu and cannot get a stand of the problem.Sorry for the bad english.
回答1:
I assume that maybe your user has rights over /opt/lampp
and because of that you can edit the files. However, if that's not the case you can grant access to both, your user and the apache group. The next shows firs the user, then the group:
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.
来源:https://stackoverflow.com/questions/15721012/fopendbinfo-php-failed-to-open-stream-permission-denied-ubuntu-12-04-lts