
{
"name": "Internal Server Error",
"message": "服务器内部错误。",
"code": 0,
"status": 500
}

{
"name": "Exception",
"message": "Failed to change permissions for directory \"/webtv/wangjie/pcs-api/tmp/2019/12/05\": chmod(): Operation not permitted",
"code": 2,
"type": "yii\\base\\Exception",
"file": "/mcloud/www/pcs-api/vendor/yiisoft/yii2/helpers/BaseFileHelper.php",
"line": 635,
"stack-trace": [
"#0 /mcloud/www/pcs-api/common/services/AssetService.php(77): yii\\helpers\\BaseFileHelper::createDirectory('/webtv/wangjie/...')",
"#1 /mcloud/www/pcs-api/api/rests/asset/UploadAction.php(93): common\\services\\AssetService::uploadTempAssets(Array)",
"#2 [internal function]: api\\rests\\asset\\UploadAction->run()",
"#3 /mcloud/www/pcs-api/vendor/yiisoft/yii2/base/Action.php(94): call_user_func_array(Array, Array)",
"#4 /mcloud/www/pcs-api/vendor/yiisoft/yii2/base/Controller.php(157): yii\\base\\Action->runWithParams(Array)",
"#5 /mcloud/www/pcs-api/vendor/yiisoft/yii2/base/Module.php(528): yii\\base\\Controller->runAction('upload', Array)",
"#6 /mcloud/www/pcs-api/vendor/yiisoft/yii2/web/Application.php(103): yii\\base\\Module->runAction('v1/asset/upload', Array)",
"#7 /mcloud/www/pcs-api/vendor/yiisoft/yii2/base/Application.php(386): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))",
"#8 /mcloud/www/pcs-api/api/web/index.php(17): yii\\base\\Application->run()",
"#9 {main}"
],
"previous": {
"name": "PHP Warning",
"message": "chmod(): Operation not permitted",
"code": 2,
"type": "yii\\base\\ErrorException",
"file": "/mcloud/www/pcs-api/vendor/yiisoft/yii2/helpers/BaseFileHelper.php",
"line": 633,
"stack-trace": [
"#0 [internal function]: yii\\base\\ErrorHandler->handleError(2, 'chmod(): Operat...', '/mcloud/www/pcs...', 633, Array)",
"#1 /mcloud/www/pcs-api/vendor/yiisoft/yii2/helpers/BaseFileHelper.php(633): chmod('/webtv/wangjie/...', 509)",
"#2 /mcloud/www/pcs-api/common/services/AssetService.php(77): yii\\helpers\\BaseFileHelper::createDirectory('/webtv/wangjie/...')",
"#3 /mcloud/www/pcs-api/api/rests/asset/UploadAction.php(93): common\\services\\AssetService::uploadTempAssets(Array)",
"#4 [internal function]: api\\rests\\asset\\UploadAction->run()",
"#5 /mcloud/www/pcs-api/vendor/yiisoft/yii2/base/Action.php(94): call_user_func_array(Array, Array)",
"#6 /mcloud/www/pcs-api/vendor/yiisoft/yii2/base/Controller.php(157): yii\\base\\Action->runWithParams(Array)",
"#7 /mcloud/www/pcs-api/vendor/yiisoft/yii2/base/Module.php(528): yii\\base\\Controller->runAction('upload', Array)",
"#8 /mcloud/www/pcs-api/vendor/yiisoft/yii2/web/Application.php(103): yii\\base\\Module->runAction('v1/asset/upload', Array)",
"#9 /mcloud/www/pcs-api/vendor/yiisoft/yii2/base/Application.php(386): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))",
"#10 /mcloud/www/pcs-api/api/web/index.php(17): yii\\base\\Application->run()",
"#11 {main}"
]
}
}

[root@d48dedd9fceb pcs-api]# ls
2019 tmp
[root@d48dedd9fceb pcs-api]# cd tmp
[root@d48dedd9fceb tmp]# ls
2019
[root@d48dedd9fceb tmp]# cd 2019
[root@d48dedd9fceb 2019]# ls
10 11 12
[root@d48dedd9fceb 2019]# cd 12
[root@d48dedd9fceb 12]# ls
05
[root@d48dedd9fceb 12]# cd 05
[root@d48dedd9fceb 05]# ls
[root@d48dedd9fceb 05]# pwd
/webtv/wangjie/pcs-api/tmp/2019/12/05
[root@d48dedd9fceb 05]# ls -l
total 0
[root@d48dedd9fceb 05]# cd ..
[root@d48dedd9fceb 12]# ls -l
total 0
drwxrwxrwx 2 root root 0 Dec 5 15:28 05
[root@d48dedd9fceb 12]#

[root@685b4b7fd197 /]# cd /webtv/wangjiedev/pcs-api/
[root@685b4b7fd197 pcs-api]# ls
2019 php-fpm1.conf php-fpm.conf tmp
[root@685b4b7fd197 pcs-api]# cd tmp
[root@685b4b7fd197 tmp]# ls -l
total 0
drwxrwxr-x 9 nginx nginx 101 Dec 2 16:26 2019
<pre class="wp-block-syntaxhighlighter-code">
<?php
/**
* Created by PhpStorm.
* User: Qiang Wang
* Date: 2019/12/05
* Time: 16:45
*/
namespace common\helpers;
/**
* File system helper.
*
* @author Qiang Wang <shuijingwanwq@163.com>
* @since 1.0
*/
class FileHelper extends \yii\helpers\FileHelper
{
/**
* Creates a new directory.
*
* This method is similar to the PHP `mkdir()` function except that
* it uses `chmod()` to set the permission of the created directory
* in order to avoid the impact of the `umask` setting.
*
* @param string $path path of the directory to be created.
* @param int $mode the permission to be set for the created directory.
* @param bool $recursive whether to create parent directories if they do not exist.
* @return bool whether the directory is created successfully
* @throws \yii\base\Exception if the directory could not be created (i.e. php error due to parallel changes)
*/
public static function createDirectory($path, $mode = 0775, $recursive = true)
{
if (is_dir($path)) {
return true;
}
$parentDir = dirname($path);
// recurse if parent dir does not exist and we are not at the root of the file system.
if ($recursive && !is_dir($parentDir) && $parentDir !== $path) {
static::createDirectory($parentDir, $mode, true);
}
try {
if (!mkdir($path, $mode)) {
return false;
}
} catch (\Exception $e) {
if (!is_dir($path)) {// https://github.com/yiisoft/yii2/issues/9288
throw new \yii\base\Exception("Failed to create directory \"$path\": " . $e->getMessage(), $e->getCode(), $e);
}
}
try {
return @chmod($path, $mode);
} catch (\Exception $e) {
throw new \yii\base\Exception("Failed to change permissions for directory \"$path\": " . $e->getMessage(), $e->getCode(), $e);
}
}
}
</pre>


{
"name": "Internal Server Error",
"message": "创建目录:/webtv/wangjie/pcs-api/tmp/2019/12/05,失败",
"code": 202002,
"status": 500,
"type": "yii\\web\\ServerErrorHttpException"
}

<pre class="wp-block-syntaxhighlighter-code">
<?php
/**
* Created by PhpStorm.
* User: Qiang Wang
* Date: 2019/12/05
* Time: 16:45
*/
namespace common\helpers;
/**
* File system helper.
*
* @author Qiang Wang <shuijingwanwq@163.com>
* @since 1.0
*/
class FileHelper extends \yii\helpers\FileHelper
{
/**
* Creates a new directory.
*
* This method is similar to the PHP `mkdir()` function except that
* it uses `chmod()` to set the permission of the created directory
* in order to avoid the impact of the `umask` setting.
*
* @param string $path path of the directory to be created.
* @param int $mode the permission to be set for the created directory.
* @param bool $recursive whether to create parent directories if they do not exist.
* @return bool whether the directory is created successfully
* @throws \yii\base\Exception if the directory could not be created (i.e. php error due to parallel changes)
*/
public static function createDirectory($path, $mode = 0775, $recursive = true)
{
if (is_dir($path)) {
return true;
}
$parentDir = dirname($path);
// recurse if parent dir does not exist and we are not at the root of the file system.
if ($recursive && !is_dir($parentDir) && $parentDir !== $path) {
static::createDirectory($parentDir, $mode, true);
}
try {
if (!mkdir($path, $mode)) {
return false;
}
} catch (\Exception $e) {
if (!is_dir($path)) {// https://github.com/yiisoft/yii2/issues/9288
throw new \yii\base\Exception("Failed to create directory \"$path\": " . $e->getMessage(), $e->getCode(), $e);
}
}
try {
// return chmod($path, $mode);
@chmod($path, $mode);
return true;
} catch (\Exception $e) {
throw new \yii\base\Exception("Failed to change permissions for directory \"$path\": " . $e->getMessage(), $e->getCode(), $e);
}
}
}
</pre>


PHP / Laravel / Yii2 老项目维护与长期技术支持
如果你的 PHP / Laravel / Yii2 项目已经上线,但遇到原开发离职、Bug 长期无人修复、接口不稳定、性能下降、代码难以接手等问题,可以联系我做一次远程技术排查。
适合以下情况:
✅ 老旧 PHP 系统无人维护
✅ Laravel / Yii2 项目 Bug 修复
✅ 后台管理系统小功能迭代
✅ RESTful API 接口排查
✅ MySQL / Redis / Nginx 性能问题
✅ 长期远程兼职维护
可先从一次小问题开始:
✅ 线上报错排查
✅ 接口异常分析
✅ 慢查询与性能瓶颈定位
✅ 代码结构初步评估
✅ 部署环境与日志检查
如需咨询,请联系我,并注明:PHP 维护咨询。
联系方式:
Telegram:@shuijingwan
微信:13980074657
邮箱:shuijingwanwq@gmail.com

发表回复