0

After moving the project from a local machine to a production machine, I get the following error:

<b>Warning</b>:  mkdir(): Permission denied in
<b>/var/www/html/findmynumber/api/v1/apache-log4php-2.3.0/src/main/php/appenders/LoggerAppenderFile.php</b> on line
<b>93</b>
<br/>
<b>Warning</b>:  log4php: [LoggerAppenderFile:myAppender]: Failed creating target directory [/var/wwww/html/findmynumber/api/v1/logs]. Closing appender. in
<b>/var/www/html/findmynumber/api/v1/apache-log4php-2.3.0/src/main/php/LoggerAppender.php</b> on line
<b>283</b>

The owner is www-data. Also the group is www-data. I even tried give full permissions(777) for the project folder but with no success.

The calls for log4php are:

include dirname(__FILE__) . "/apache-log4php-2.3.0/src/main/php/Logger.php"; 
Logger::configure(dirname(__FILE__) . '/apache-log4php-2.3.0/src/config.xml'); 
$log = Logger::getLogger('myLogger');

The config.xml looks like this:

<configuration>
  <appender name="myAppender" class="LoggerAppenderFile">
    <param name="file" value="/var/wwww/html/findmynumber/api/v1/logs/myLog.log"/>
  </appender>
  <appender name="console" class="LoggerAppenderConsole"/>
  <root>
    <appender_ref ref="console"/>
  </root>
  <logger name="myLogger">
    <level value="DEBUG"/>
    <appender_ref ref="myAppender"/>
  </logger>
</configuration>

What am I missing here?

Edit

Bellow is the function were the error appears. It is taken from the log4php files, from LoggerAppenderFile.php:

protected function openFile() { 
    $file = $this->getTargetFile(); 
    echo $file . "\n"; 
    $curr = !is_file($file); 
    echo "curr is: " . $curr . "\n"; 
    echo is_file($file) . "\n" ; 
    echo dirname($file) . "\n"; 
    // Create the target folder if needed 
    if(!is_file($file)) { 
        $dir = dirname($file); 

        if(!is_dir($dir)) { 
            $success = mkdir($dir, 0777, true); 
            if ($success === false) { 
                $this->warn("Failed creating target directory [$dir]. Closing appender."); 
                $this->closed = true; 
                return false; 
            } 
        } 
    }

As you see, I added some debug prints myself. The 93 line is the one with mkdir statement.

florin
  • 719
  • 12
  • 31
  • 1
    use recursive command for set permissions "chmod 777 -R your-proj-folder". if you use -R it will set permissions for your project folder and sub folders too. – Naisa purushotham Jun 09 '16 at 05:21
  • @TheBigbyteNumber I already did that but the error remains – florin Jun 09 '16 at 05:25
  • we have to see the line 93 – vitr Jun 09 '16 at 05:49
  • @vitr I've edited the question with the line 93. Also, I added the full error message – florin Jun 09 '16 at 06:26
  • 1
    Wtf is the point of mkdir when the source path is the directory of a file you just verified the existence of? And I'd have to check the actual usage, but you certainly failed to make a directory... it already existed. – John Green Jun 09 '16 at 06:29
  • @JohnGreen I'm not the owner of that code. It's is taken from log4php. – florin Jun 09 '16 at 06:35
  • output the `$dir` first, why do you think it's the same as you changed permissions of? – vitr Jun 09 '16 at 06:39
  • @vitr the output of $dir is: /var/wwww/html/findmynumber/api/v1/logs. I'm afraid that I don't understand your question – florin Jun 09 '16 at 06:50
  • if `/var/wwww/html/findmynumber/api/v1/logs` exists (you wrote you changed its permissions) you should never hit the line 93, right? I guess, we're missing something here. check the permissions of the parent dir `/var/wwww/html/findmynumber/api/v1/`, also did you change the permissions recursively? – vitr Jun 09 '16 at 08:03
  • @vitr What I've tried is to give permissions recursively for user www-data for folder /findmynumber/. I didn't give permissions also for /var/www/html. My concern is that maybe I have write access for sub-folder /findmynumber/api.... but not for the full parent directory /var/www/html – florin Jun 09 '16 at 17:12

1 Answers1

0

@florin problem is typo mistake in config.xml

 <appender name="myAppender" class="LoggerAppenderFile">
    <param name="file" value="/var/wwww/html/findmynumber/api/v1/logs/myLog.log"/>
  </appender>

it should be like this

/var/www/html/findmynumber/api/v1/logs/myLog.log. instead of www you kept wwww 

this one you can check in this warning

<b>Warning</b>:  log4php: [LoggerAppenderFile:myAppender]: Failed creating target directory [/var/wwww/html/findmynumber/api/v1/logs]. Closing appender. in
Naisa purushotham
  • 905
  • 10
  • 18