0
-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
http://<ip>/html/DB-Monitoring/mysql-connectivity-status.php.

In mysql-connectivity-status.php I have called the file dbm-config.ini. While am accessing via URL am getting the following Warning.

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?

Havelock
  • 6,913
  • 4
  • 34
  • 42
sibimani
  • 95
  • 1
  • 11
  • Do you happen to know if you're running SuPHP or PHPExec on your server? You should be able to find out via phpinfo(). I might just change the permissions of the file to 644 and then block direct access to the file via htaccess so PHP can still access it. [This might help](http://stackoverflow.com/questions/1340001/deny-direct-access-to-all-php-files-except-index-php) – djthoms Feb 05 '13 at 07:56

2 Answers2

2

-rw-r----- 1 root root 1344 Feb 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--

If you access the php file using curl, this is executed most likely with your webservers user and group which is not root:root

That's why php can't read the ini file. 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

determine the username php is executed with

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

chown user:group dbm-config.ini
Michel Feldheim
  • 17,625
  • 5
  • 60
  • 77
1

The problem is that your webserver cannot access that file. If you cannot fix that you cannot access it remotely through that webserver. :)

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. IF your webserver is apache and that is the correct group that it is using this might help.

Sarien
  • 6,647
  • 6
  • 35
  • 55