Reputation: 33
I have a PHP script located at /var/www/html/index.php
and need to open /var/log/apache2/access.log
.
Through the console, the file exists and in the browser the other way around.
Here is my code :
$filename = '/var/log/apache2/error.log';
if (file_exists($filename)) {
exit("Файл $filename существует");
} else {
exit("Файл $filename не существует");
}
Upvotes: 0
Views: 313
Reputation: 493
You can add echo exec("whoami") . "\n";
to your script to know who is the role used by the HTTP server (usually www-data
with apache) and configure the permissions on your server.
You can also configure an other path for your logs using the CustomLog
and ErrorLog
directive in the configuration of your web-server or in the .htaccess file
example:
CustomLog /var/www/html/logs/access.log combined
ErrorLog /var/www/html/logs/error.log
Documentation:
Upvotes: 0
Reputation: 643
Perhaps set the path wrong, try
var_dump($_SERVER["DOCUMENT_ROOT"]."/myFolder/*");
google for $_SERVER path coms.
Or similar.
us error_reporting(E_ALL)
at the top of the code to see what path it throws back when it doesnt find it.
and like zane pointed it out, it most likely cannot reach root files, its usually restricted area.
Upvotes: 0
Reputation: 219
Warning: This function returns FALSE for files inaccessible due to safe mode restrictions. However these files still can be included if they are located in safe_mode_include_dir.
from php-manual.
Upvotes: 3