简体   繁体   English

如何使用Curl从URL访问文件

[英]How to access a file from URL using Curl

-rw-r--r-- 1 root      root        514 Jan 15 04:03 curl.php
-rw-r----- 1 root      root       1344 Feb  5 02:09 dbm-config.ini
-rw-r--r-- 1 root      root       5149 Feb  5 02:19 mysql-connectivity-status.php

Here, Am accessing the file "mysql-connectivity-status.php" from url like 在这里,我从url这样访问文件“ mysql-connectivity-status.php”
http://<ip>/html/DB-Monitoring/mysql-connectivity-status.php . http://<ip>/html/DB-Monitoring/mysql-connectivity-status.php

In mysql-connectivity-status.php I have called the file dbm-config.ini . mysql-connectivity-status.php我将文件命名为dbm-config.ini While am accessing via URL am getting the following Warning. 通过URL访问时,出现以下警告。

Warning: parse_ini_file(/var/www/html/DB-Monitoring/dbm-config.ini): failed to open stream: Permission denied in /var/www/html/DB-Monitoring/mysql-connectivity-status.php on line 113

So, I don't want to change the permission for the dbm-config.ini But how to I access the file using URL? 因此,我不想更改dbm-config.ini的权限,但是如何使用URL访问文件?

-rw-r----- 1 root root 1344 Feb 5 02:09 dbm-config.ini -rw-r ----- 1个根root 1344 2月5日02:09 dbm-config.ini

The file can be read from and written to, by the user root rw- and read from by the members of the group root r-- 该文件可由用户root rw-读取和写入,以及由组root r--成员读取。

If you access the php file using curl, this is executed most likely with your webservers user and group which is not root:root 如果您使用curl来访问php文件,则很有可能是由非root:root用户的webservers用户和组执行的root:root

That's why php can't read the ini file. 这就是为什么php无法读取ini文件的原因。 I recommend to move the file out of your document root so it can't be accessed directly from the web, then change the owner to your webserver user and group 我建议将文件移出文档根目录,以使它不能直接从Web上访问,然后将所有者更改为Web服务器用户和组

determine the username php is executed with 确定用户名php与执行

ps aux | grep "httpd" # apache environment
ps aux | grep "php"   # php fastcgi environment 

chown user:group dbm-config.ini

The problem is that your webserver cannot access that file. 问题是您的Web服务器无法访问该文件。 If you cannot fix that you cannot access it remotely through that webserver. 如果无法修复,则无法通过该Web服务器进行远程访问。 :) :)

Wild guess, since I don't know what you're using: 大胆的猜测,因为我不知道您在使用什么:

chown root:apache dbm-config.ini
chmod g+r dbm-config.ini

might help. 可能有帮助。 That will set the owning group of the file to apache and give the group read access. 这样会将文件所属的组设置为apache并赋予该组读访问权限。 IF your webserver is apache and that is the correct group that it is using this might help. 如果您的Web服务器是apache,那是它正在使用的正确组,则可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM