Jump to content

PHP CLI unable to execute in subdir


FieldingBlue

Recommended Posts

Hiho,
This one has me stumped. I've been coding for a while and never seen this sort of problem before. This issue has occured on an openSuse box.

PHP from the command line reports that it is unable to find php files in a particular sub-directory. But everywhere else things work fine. There are no differences that I can identify between permissions. There is no .htaccess file. I've checked the php.ini file and there are no prescriptive settings that prohibit the offending sub-directory. The problem exists even as Super User.
Below is the output from a session that highlights my issue. The same test.php file is included in the current directory, a 'test' sub-directory and the offending 'projects' sub-directory.
The script permissions are the same in each directory. Also the permissions for the directories are identical.
The script is simple.
The script contents are the same in each directory.
The output is different for the script in the 'projects' sub-directory. Apparently PHP cannot find the file.

If anyone has any hints I'd love to hear them.
Thanks

user@machine:~> ls -l test.php
-rw-r--r-- 1 user users 37 May 11 07:40 test.php                                                                                                             
user@machine:~> ls -l test/test.php
-rw-r--r-- 1 user users 37 May 11 07:41 test/test.php                                                                                                        
user@machine:~> ls -l projects/test.php
-rw-r--r-- 1 user users 37 May 11 07:41 projects/test.php

user@machine:~> cat test.php
<?php
echo "is this thing on?\n";
?>

user@machine:~> diff test.php test/test.php
user@machine:~> diff test.php projects/test.php        
                                                                                                       
user@machine:~> php test.php                                                                                                                                  
is this thing on?                                                                                                                                            
user@machine:~> php test/test.php                                                                                                                             
is this thing on?                                                                                                                                            
user@machine:~> php projects/test.php                                                                                                                         
PHP Fatal error:  Unknown: Failed opening required 'projects/test.php' (include_path='.:/usr/share/php5:/usr/share/php5/PEAR') in Unknown on line 0
user@machine:~>

Link to comment
Share on other sites

relative is no leading slash

absolute will have a leading slash

You don't want to use a relative path, an absolute path of the current directory is what you need

 

If this script isn't running from the same directory it wouldn't be able to find it, so try adding the directory path

 

You can use set_include_path()

 

Some OS are slightly different.

 

In php scripts I add this to locate the directory name and it's separator

$full_path = dirname(__FILE__) . DIRECTORY_SEPARATOR."/projects/test.php";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.