Find out why a program can't seem to access to a file

2010-05-05 278 words 2 mins read

$ strace php tias.php -e open,access 2>&1 | <a class="zem_slink freebase/en/grep" href="" title="Grep" rel="wikipedia">grep foo.txt Sometimes a program refuses to read a file and you&#8217;re not sure why. You may have display_errors turned off for <a class="zem_slink freebase/en/php" href="" title="PHP" rel="homepage">PHP or something. In this example, fopen(&#8217;/var/www/test/foo.txt&#8217;) was called but doesn&#8217;t have read access to foo.txt.

Strace can tell you what went wrong. E.g., if php doesn&#8217;t have read access to the file, strace will say &#8221;EACCESS (Permission denied)&#8221;. Or, if the <a class="zem_slink freebase/guid/9202a8c04000641f8000000000220ffa" href="" title="Path (computing)" rel="wikipedia">file path you gave doesn&#8217;t exist, strace will say &#8221;ENOENT (No such file or directory)&#8221;, etc.

This works for any program you can run from the <a class="zem_slink freebase/en/command_line_interface" href="" title="Command-line interface" rel="wikipedia">command-line, e.g., strace python -e open,access…

Note: the above command uses php-cli, not mod_php, which is a different <a class="zem_slink freebase/en/server_application_programming_interface" href="" title="Server Application Programming Interface" rel="wikipedia">SAPI with <a class="zem_slink freebase/en/diff" href="" title="Diff" rel="tracked">diff configs, etc.

  • <a href="">View this command to comment, vote or add to favourites
  • <a href="">View all commands by <a href="">rkulla

<a href=""><img align="bottom" src="" alt="" />

by David Winterbottom (<a href="">

<a href=""><img align="bottom" src="" alt="" />
<a href=""><img align="bottom" src="" alt="" />

<img align="bottom" width="1" height="1" src="" alt="" />

URL: <a href=""><h6 class="zemanta-related-title">Related articles by Zemanta <ul class="zemanta-article-ul"> <li class="zemanta-article-ul-li"><a href="">Visualizing system performance data ( <li class="zemanta-article-ul-li"><a href="">IO profiling of MPI apps ( <li class="zemanta-article-ul-li"><a href="">Symfony Components ( <li class="zemanta-article-ul-li"><a href="">What Every Developer Should Know About URLs ( <li class="zemanta-article-ul-li"><a href="">Creating MySQL Stored Routines for Non-DBAs – Part Three ( <div class="zemanta-pixie"><a class="zemanta-pixie-a" href="" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="" alt="Reblog this post [with Zemanta]" /><span class="zem-script more-related more-info pretty-attribution paragraph-reblog">


Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it