Warning: mkdir() [function.mkdir]: No such file or directory in
/var/www/humspm/data/www/humspm.com/gettext.php on line 17 CMD:EXIT
can you please help me to resolve this issue
Thanks in adavence
You can turn off notifications in PHP:
<?php error_reporting(0); ?>
More:
http://php.net/manual/de/function.error-reporting.php
http://www.w3schools.com/php/php_error.asp
I recommend to solve the issue with correct coding instead of just turning off errors and warnings!
For your issue, just check if the file or directory exists before you try to work with the filesystem. (check the PHP manual for file_exists() and is_dir())
From the CAKEphp manual:
Error configuration is done inside your application’s
app/Config/core.php file. You can define a callback to be fired each
time your application triggers any PHP error - exceptions are handled
Exceptions separately. The callback can be any PHP callable, including
an anonymous function. The default error handling configuration looks
like:
Configure::write('Error', array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true ));
You have 5 built-in options when configuring error handlers:
handler - callback - The callback to handle errors. You can set this
to any callable type, including anonymous functions.
level - int - The
level of errors you are interested in capturing. Use the built-in PHP
error constants, and bitmasks to select the level of error you are
interested in.
trace - boolean - Include stack traces for errors in
log files. Stack traces will be included in the log after each error.
This is helpful for finding where/when errors are being raised.
consoleHandler - callback - The callback used to handle errors when
running in the console.
If undefined, CakePHP’s default handlers will
be used. ErrorHandler by default, displays errors when debug > 0, and
logs errors when debug = 0. The type of errors captured in both cases
is controlled by Error.level. The fatal error handler will be called
independent of debug level or Error.level configuration, but the
result will be different based on debug level.
Link to manual
First of all check what causes this issue,
Check folder permission
Check whether you have privileges to create a directory inside the specific location.
Still if you want to silence the error
You can add # in front of mkdir
You can disable error reporting.
Please see your directory structor carefully.According to url something is repeating into your url.
/var/www/humspm/data/www/humspm.com/gettext.php
Also see mkdir is only working with the directory path, not the URL or domain.
You should have to point to your subdomain's absolute path, not the URL.
I ran into the same error on a client's WordPress site:
(Warning: mkdir() [function.mkdir]: No such file or directory in /var/www/humspm/data/www/humspm.com/gettext.php on line 17 CMD:EXIT)
I found that their index.php file was calling a file named cache.php on line 1.
cache.php contained obfuscated code that appears to have been attempting to use the invalid absolute path. The use of obfuscated code probably explains why you couldn't find any reference to that directory path in your code.
The actual file name may differ in your site, I'd recommend looking out for any unfamiliar php files in the same directory as your index.
Commenting out the line in index.php that called to this cache.php fixed the issue with the warning message.
However, the file itself appears to be malicious so I'm recommending that my client harden their security and scan for additional malware. You might want to do the same.
Related
I am having an issue when I have a php application that is returning an internal server error (500) however nothing is showing up in the error log.
Now I know there are error with what I am trying to run, I know I have missing some files and what not but something should show in the apache error log (otherwise how are I supposed to know exactly what I am missing).
I created a test script is errors it in under the same vhost configuration and those error show up fine so everything seems configured right as far as php/apache. Are there certain php errors that does show up in the error log (php is configure to display any type of notice, warning, , error, fatal error, etc...)?
This is running on ubunut 10.04 with the standard apache and php from the ubuntu repo with apt-get.
Scan your source files to find #.
From php documentation site
Currently the "#" error-control operator prefix will even disable
error reporting for critical errors that will terminate script
execution. Among other things, this means that if you use "#" to
suppress errors from a certain function and either it isn't available
or has been mistyped, the script will die right there with no
indication as to why.
Copy and paste the following into a new .htaccess file and place it on your website's root folder :
php_flag display_errors on
php_flag display_startup_errors on
Errors will be shown directly in your page.
That's the best way to debug quickly but don't use it for long time because it could be a security breach.
If you still have 500 error and no logs you can try to execute from command line:
php -f file.php
it will not work exactly like in a browser (from server) but if there is syntax error in your code, you will see error message in console.
Maybe something turns off error output. (I understand that you are trying to say that other scripts properly output their errors to the errorlog?)
You could start debugging the script by determining where it exits the script (start by adding a echo 1; exit; to the first line of the script and checking whether the browser outputs 1 and then move that line down).
In the past, I had no error logs in two cases:
The user under which Apache was running had no permissions to modify php_error_log file.
Error 500 occurred because of bad configuration of .htaccess, for example wrong rewrite module settings. In this situation errors are logged to Apache error_log file.
For Symfony projects, be sure to check files in the project'es app/logs
More details available on this post :
How to debug 500 Error in Symfony 2
Btw, other frameworks or CMS share this kind of behaviour.
Here is another reason why errors might not be visible:
I had the same issue. In my case, I had copied the source from a production environment. Hence the ENVIRONMENT variable defined in index.php was set to 'production'. This caused error_reporting to be set to 0 (no logging). Just set it to 'development' and you should start seeing error messages in apache log.
Turned out the 500 was due to a semi colon missing in database config :-)
Another case which happened to me, is I did a CURL to some of my pages, and got internal server error and nothing was in the apache logs, even when I enabled all error reporting.
My problem was that in the CURL I set
curl_setopt($CR, CURLOPT_FAILONERROR, true);
Which then didn't show me my error, though there was one, this happened because the error was on a framework level and not a PHP one, so it didn't appear in the logs.
You need to enable the PHP error log.
This is due to some random glitch in the web server when you have a php error, it throws a 500 internal error (i have the same issue).
If you look in the PHP error log, you should find your solution.
see here in the doc of how to enable it in the php.ini
Be sure your file permissions are correct. If apache doesn't have permission to read the file then it can't write to the log.
What happened for me when this was an issue, was that the site had used too much memory, so I'm guessing that it couldn't write to an error log or displayed the error. For clarity, it was a Wordpress site that did this. Upping the memory limit on the server showed the site again.
SOLVED
I struggled with this and later on, I realized that I was working on PHP 5.6, so I upgraded to PHP 7.0, then I released there were comments placed by git for conflicting codes. I found something like this in my code <<<<<<<< But solved it.
Is it just me or is do others have trouble understanding how logging works in PHP?
I come from a Java/Python logging world where you usually have access to an inbuilt utility for logging that allows you to either specify a log level or call a log level function (like logger.info('foo');). The core library would then organise from configuration values how the log appears and in what file it ends up in.
However out of the many documents I've read and google searches done on the subject, I seem to be missing some sort of fundamental understanding of the way PHP logging works.
what I've found so far is that PHP has:
the log_errors=[0|1] ini config directive, which enables logging of errors (if you would believe it),
the error_log=/path/to/file, not to be confused with the error_log() function, which defines the file which errors are logged to
an additional note on the error_log value, I have found that in apache2, when you set this value as an absolute path, Apache will honor the value, however any other relative path will default to the ErrorLog value of the Apache server (usually /var/log/[httpd|apache2|apache]/error.log)
a syslog() and error_log() function which defers messages to either the PHP system logger (/var/log/syslog) or the SAPI logger respectively (see this post and notice on error_log).
I have no control from the method signature what level message I have logged. (I know there are different levels as I can see when I receive an Illegal string offset Warning or Undefined variable notice).
# php internal log examples
[10-Mar-2017 02:45:17 UTC] PHP Warning: Illegal string offset 'username' in /var/www/html/foobar.php on line 123
[10-Mar-2017 02:45:17 UTC] PHP Notice: Undefined variable: col_info in /var/www/html/barfoo.php on line 89
[10-Mar-2017 02:45:17 UTC] my message using error_log() function without any level indication.
Now I realise that I may output the level myself, but am I to believe I cannot integrate with PHP's own level system for the sake of easy config? I choose to believe otherwise.
All my searches thus far have only informed me how to disable or enable these levels and not how to output a message with a given level.
I am hoping to be directed to some fundamental documentation on the reasoning behind logging in PHP... Or I may eat my shoe out of frustration from this simple endeavour.
P.S. I am using Apache2 as my web server.
Update:
I can see that you may log to syslog with syslog($ERRNO, $ERRMSG) and this sets the log_level (LOG_DEBUG, LOG_INFO, etc...). It would be nice to hijack the log_level configuration without using the implicit syslog file. i.e. my_error.log as opposed to syslog. I'm beginning to believe that log levels are internal ideas in the PHP core.
I'm currently working on a project and to give a helping hand, I've changed my php.ini file to log errors to "php_errors.log" inside the directory of where a PHP file has returned an error.
I was wondering, after searching online (maybe I'm not wording this correctly), is there any way to set a unique file name in the php.ini file for the different errors.
For example, if an error occurred on let's say account.php, is there any way to log an error file "account_php_errors.log" through the ini file?
From the ini file you can set a global error file, if you want to override that you can add the following lines to the "account.php"
ini_set("log_errors", 1);
ini_set("error_log", "/path/to/logfile.log");
error_log( "one error" );
Or if you use a framework you could check the documentation to see how you can customize errors. Frameworks will have advanced logging mechanisms.
There is no way for you to use php.ini to log to multiple files based on the php file that generated the fatal error.
You could try and use register_shutdown_function to catch fatal errors then log to individual files using the ['file'] you get in the array response to a get_last_error.
If you were practicing Object Oriented Programming with try/catch Exceptions you could use some logging method to separate out error into individual files.
Options inside the php.ini file itself are not this flexible (which is actually a good thing so that other programs such as logrotate can be applied in an effective manner). You can look at accomplishing what you need via your application (whether that is a framework or purely custom code). You could just grep out what you need if you're on a linux system or search in the Event Viewer on Windows. It really depends on what your specific needs really are.
You can create a custom error handler within the application. You should be able to get all the needed details from here
// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline) {
// file_put_contents
}
set_error_handler("myErrorHandler");
More info:
http://php.net/manual/en/function.set-error-handler.php
I would rethink the purpose for keeping errors logs in different directories, because it will make Your app messy. Greping logs from different folders alone is not so convienient and if You ever want to add log monitoring tools like Logstash with elasticsearch, you will be forced to do a more complex setup
Bit of a strange one here. I'm looking through my PHP Error log and on a number of occasions I'm seeing the following line
File does not exist: /var/www/vhosts/mywebsite.org.uk/httpdocs/users/assignmnets
The reason the file doesn't exist is that the folder is spelt wrong - it should read assignments, not assignmnets.
The thing is, I've gone through all of the code on the site and this spelling mistake doesn't appear anywhere at all, so why am I getting this error? Furthermore, there are no links to the above folder - any links point directly to the php file contained within the folder - assignments/assignments.php
I can't make head nor tail of it. Is this a common issue with PHP or is there something I am getting wrong?
Thanks!
What kind of PHP error log is it? some custom logger function? Try using Tracy https://github.com/nette/tracy - enabling this debugger in your project with
Debugger::enable(Debugger::DETECT, __DIR__ . '/mylog');
will result in that all PHP errors will be logged as an HTML file with very verbose description of the error, including full stack trace (in production environment; on localhost, when development environment is detected, you will see the stack trace immediatelly in browser). From this you will be able to determine which part of code caused this problem next time it happens.
Don't forget to disable your custom error handler if any is in use, as it may be colliding with Tracy.
I am having an issue when I have a php application that is returning an internal server error (500) however nothing is showing up in the error log.
Now I know there are error with what I am trying to run, I know I have missing some files and what not but something should show in the apache error log (otherwise how are I supposed to know exactly what I am missing).
I created a test script is errors it in under the same vhost configuration and those error show up fine so everything seems configured right as far as php/apache. Are there certain php errors that does show up in the error log (php is configure to display any type of notice, warning, , error, fatal error, etc...)?
This is running on ubunut 10.04 with the standard apache and php from the ubuntu repo with apt-get.
Scan your source files to find #.
From php documentation site
Currently the "#" error-control operator prefix will even disable
error reporting for critical errors that will terminate script
execution. Among other things, this means that if you use "#" to
suppress errors from a certain function and either it isn't available
or has been mistyped, the script will die right there with no
indication as to why.
Copy and paste the following into a new .htaccess file and place it on your website's root folder :
php_flag display_errors on
php_flag display_startup_errors on
Errors will be shown directly in your page.
That's the best way to debug quickly but don't use it for long time because it could be a security breach.
If you still have 500 error and no logs you can try to execute from command line:
php -f file.php
it will not work exactly like in a browser (from server) but if there is syntax error in your code, you will see error message in console.
Maybe something turns off error output. (I understand that you are trying to say that other scripts properly output their errors to the errorlog?)
You could start debugging the script by determining where it exits the script (start by adding a echo 1; exit; to the first line of the script and checking whether the browser outputs 1 and then move that line down).
In the past, I had no error logs in two cases:
The user under which Apache was running had no permissions to modify php_error_log file.
Error 500 occurred because of bad configuration of .htaccess, for example wrong rewrite module settings. In this situation errors are logged to Apache error_log file.
For Symfony projects, be sure to check files in the project'es app/logs
More details available on this post :
How to debug 500 Error in Symfony 2
Btw, other frameworks or CMS share this kind of behaviour.
Here is another reason why errors might not be visible:
I had the same issue. In my case, I had copied the source from a production environment. Hence the ENVIRONMENT variable defined in index.php was set to 'production'. This caused error_reporting to be set to 0 (no logging). Just set it to 'development' and you should start seeing error messages in apache log.
Turned out the 500 was due to a semi colon missing in database config :-)
Another case which happened to me, is I did a CURL to some of my pages, and got internal server error and nothing was in the apache logs, even when I enabled all error reporting.
My problem was that in the CURL I set
curl_setopt($CR, CURLOPT_FAILONERROR, true);
Which then didn't show me my error, though there was one, this happened because the error was on a framework level and not a PHP one, so it didn't appear in the logs.
You need to enable the PHP error log.
This is due to some random glitch in the web server when you have a php error, it throws a 500 internal error (i have the same issue).
If you look in the PHP error log, you should find your solution.
see here in the doc of how to enable it in the php.ini
Be sure your file permissions are correct. If apache doesn't have permission to read the file then it can't write to the log.
What happened for me when this was an issue, was that the site had used too much memory, so I'm guessing that it couldn't write to an error log or displayed the error. For clarity, it was a Wordpress site that did this. Upping the memory limit on the server showed the site again.
SOLVED
I struggled with this and later on, I realized that I was working on PHP 5.6, so I upgraded to PHP 7.0, then I released there were comments placed by git for conflicting codes. I found something like this in my code <<<<<<<< But solved it.