Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6094683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:42:30+00:00 2026-05-23T12:42:30+00:00

While using PHP cli in ubuntu i got apache as web server i cant

  • 0

While using PHP cli in ubuntu i got apache as web server i cant read the file which i can while using it in the browser.
And about the error it just shows nothing and the next like i just used this code for my testing purposes :

<?
$handle = fopen("testFile.txt", "r");
if ($handle) {
    while (($buffer = fgets($handle, 4096)) !== false) {
    echo $buffer;
    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
    }
if(!is_readable($handle)
{
 die("Not readable");
}
fclose($handle);
}
?>

How do i fix that ?

EDIT :

After removing the ‘@’ before fopen i got the following error

fopen(testFile.txt): failed to open
stream: No such file or directory in
/var/www/log/ka.php on line 2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:42:30+00:00Added an answer on May 23, 2026 at 12:42 pm

    When you run your script through CLI, it uses your shell’s working directory, in opposition to the file’s directory (which Apache hands as the current directory). This is important for you, since your fopen call depends on a relative path; and relative paths are resolved relatively to the working directory, not to the script.

    To have your script behave like it does with Apache, you either need to cd /var/www/log prior to running the php command, or add this at the beginning of your PHP script:

    chdir(dirname(__FILE__));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using streaming sockets in PHP to read from a remote server. When
Is it possible to upload a file to the FTP server using PHP script
Been using PHP/MySQL for a little while now, and I'm wondering if there are
I'm getting error while using php function copy() Warning: copy() [function.copy]: Couldn't resolve host
I've been trying for a while to generate an RSA keypair using PHP's openssl
In a PHP environment, is it possible to have different/independent sessions while using http
While using Struts2, I am using several annotations to do my validations inside the
While using Vim (at home and at work), I often find myself doing similar
I am experiencing a crash while using the Boost.Spirit and Boost.Thread libraries in my
I've seen this quite a few times while using Office Interop classes this.CustomXMLParts.Add(MyResources.Data, new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.