1. copy(/webtv/wangjie/channel-pub-api/images/2020/08/26/1598426506.2121.2009434638.jpeg): failed to open stream: Permission denied. See Figure 1.

2020-08-26 16:05:11 [10.42.2.229][-][-][error][yii\base\ErrorException:2] yii\base\ErrorException: copy(/webtv/wangjie/channel-pub-api/images/2020/08/26/1598429111.0583.1328310233.jpeg): failed to open stream: Permission denied in /mcloud/www/channel-pub-api/common/services/AssetService.php:207
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError(2, 'copy(/webtv/wan...', '/mcloud/www/cha...', 207, Array)
#1 /mcloud/www/channel-pub-api/common/services/AssetService.php(207): copy('/webtv/wangjie/...', '/webtv/wangjie/...')
#2 /mcloud/www/channel-pub-api/wx/services/WxArticleMassService.php(80): common\services\AssetService::copyAssetsSync('spider', Array)
#3 /mcloud/www/channel-pub-api/wx/rests/wx_article/ArticleAction.php(118): wx\services\WxArticleMassService->publishNewsArticle(Array)
#4 [internal function]: wx\rests\wx_article\ArticleAction->standardArticle(Array, 'mass')
#5 /mcloud/www/channel-pub-api/wx/rests/wx_article/ArticleAction.php(76): call_user_func(Array, Array, 'mass')
#6 [internal function]: wx\rests\wx_article\ArticleAction->run()
#7 /mcloud/www/channel-pub-api/vendor/yiisoft/yii2/base/Action.php(94): call_user_func_array(Array, Array)
#8 /mcloud/www/channel-pub-api/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\Action->runWithParams(Array)
#9 /mcloud/www/channel-pub-api/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction('article', Array)
#10 /mcloud/www/channel-pub-api/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('v1/wx-article/a...', Array)
#11 /mcloud/www/channel-pub-api/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#12 /mcloud/www/channel-pub-api/wx/web/index.php(17): yii\base\Application->run()
#13 {main}
2020-08-26 16:05:11 [10.42.2.229][-][-][warning][yii\debug\Module::checkAccess] Access to debugger is denied due to IP address restriction. The requesting IP address is 10.42.2.229
2020-08-26 16:05:11 [10.42.2.229][-][-][info][application] $_GET = [
'group_id' => 'spider'
]
$_POST = [
'app_ids' => [
0 => 'af2dfa72e29111eaa8ec8471dcec4058'
]
'code' => 'standard'
'thumb' => 'https://mserver.chinamcloud.cn/cms/mrzd/upload/Image/MRLM/2020/08/26/1_12f10c372509417a904a96a1563d59ca.jpeg'
'author' => '大兵小将Big Or Small'
'source_article_id' => '265042'
'source_pub_user_id' => '11111'
'material_list' => '[{\"type\":\"video\",\"url\":\"https://mserver.chinamcloud.cn/vms/video/default/vod/2020/08/25/eea43bcdf8454dde8b7ef9b73ad7be4a/eea43bcdf8454dde8b7ef9b73ad7be4a_h264_1200k_mp4.mp4\",\"tag\":\"video\",\"title\":\"555555555555555555\",\"article_category_id\":226}]'
'description' => 'wjtest->default'
'source_uuid' => '8d44142324ed4ee69427804c5f1823e5'
'source' => 'spider'
'title' => '555555555555555555'
'content' => '
'
'url' => 'https://mserver.chinamcloud.cn/cms/mrzd/zmt/flal/dbdjsoldier/265042.shtml'
'wx_send_type' => 'mass'
'source_callback_url' => 'https://scms.wjtest.chinamcloud.cn/api/thirdPush/callBack'
'tag' => 'video'
]
$_FILES = []
$_COOKIE = []
$_SERVER = [
'USER' => 'nginx'
'HOME' => '/var/cache/nginx'
'HTTP_CONNECTION' => 'close'
'HTTP_X_FORWARDED_FOR' => '188.131.147.50'
'HTTP_X_FORWARDED_PORT' => '80'
'HTTP_CONTENT_LENGTH' => '2111'
'HTTP_HOST' => 'channelpubapi.wjtest.chinamcloud.cn'
'HTTP_USER_AGENT' => 'Jakarta Commons-HttpClient/3.1'
'HTTP_CONTENT_TYPE' => 'application/x-www-form-urlencoded'
'HTTP_ACCEPT_ENCODING' => 'gzip,deflate,br'
'HTTP_ACCEPT_LANGUAGE' => 'zh-CN'
'HTTP_ACCEPT' => 'application/json;version=0.0'
'SCRIPT_FILENAME' => '/mcloud/www/channel-pub-api/wx/web/index.php'
'REDIRECT_STATUS' => '200'
'SERVER_NAME' => 'channelpubapi.wjtest.chinamcloud.cn'
'SERVER_PORT' => '80'
'SERVER_ADDR' => '10.42.222.158'
'REMOTE_PORT' => '42812'
'REMOTE_ADDR' => '10.42.2.229'
'SERVER_SOFTWARE' => 'nginx/cnginx'
'GATEWAY_INTERFACE' => 'CGI/1.1'
'REQUEST_SCHEME' => 'http'
'SERVER_PROTOCOL' => 'HTTP/1.1'
'DOCUMENT_ROOT' => '/mcloud/www/channel-pub-api'
'DOCUMENT_URI' => '/wx/web/index.php'
'REQUEST_URI' => '/wx/v1/wx-articles/article?group_id=spider'
'SCRIPT_NAME' => '/wx/web/index.php'
'CONTENT_LENGTH' => '2111'
'CONTENT_TYPE' => 'application/x-www-form-urlencoded'
'REQUEST_METHOD' => 'POST'
'QUERY_STRING' => 'group_id=spider'
'FCGI_ROLE' => 'RESPONDER'
'PHP_SELF' => '/wx/web/index.php'
'REQUEST_TIME_FLOAT' => 1598429110.9021
'REQUEST_TIME' => 1598429110
]
2. I navigated to the directory /webtv/wangjie/channel-pub-api/images/2020/08 and checked its permissions. I found that the user and group for the 26 directory were root. Because the program was upgraded today, the user and group that generate the directory have changed. I decided to delete the 26 directory and regenerate it via the API. The error no longer occurred, as shown in Figure 2.

[root@04302a060834 logs]# cd /webtv/wangjie/channel-pub-api/images/2020/08
[root@04302a060834 08]# ls -l
total 24
drwxrwxr-x 2 nginx nginx 4096 Aug 1 17:17 01
drwxrwxr-x 2 nginx nginx 4096 Aug 2 10:06 02
drwxrwxr-x 2 nginx nginx 4096 Aug 3 21:11 03
drwxrwxr-x 2 nginx nginx 4096 Aug 5 15:45 05
drwxrwxr-x 2 nginx nginx 4096 Aug 7 11:33 07
drwxrwxr-x 2 nginx nginx 91 Aug 21 17:02 21
drwxrwxr-x 2 nginx nginx 102 Aug 25 14:59 25
drwxrwxr-x 2 root root 4096 Aug 26 13:33 26
[root@04302a060834 08]# rm -rf 26
[root@04302a060834 08]# ls -l
total 20
drwxrwxr-x 2 nginx nginx 4096 Aug 1 17:17 01
drwxrwxr-x 2 nginx nginx 4096 Aug 2 10:06 02
drwxrwxr-x 2 nginx nginx 4096 Aug 3 21:11 03
drwxrwxr-x 2 nginx nginx 4096 Aug 5 15:45 05
drwxrwxr-x 2 nginx nginx 4096 Aug 7 11:33 07
drwxrwxr-x 2 nginx nginx 91 Aug 21 17:02 21
drwxrwxr-x 2 nginx nginx 102 Aug 25 14:59 25
[root@04302a060834 08]# ls -l
total 20
drwxrwxr-x 2 nginx nginx 4096 Aug 1 17:17 01
drwxrwxr-x 2 nginx nginx 4096 Aug 2 10:06 02
drwxrwxr-x 2 nginx nginx 4096 Aug 3 21:11 03
drwxrwxr-x 2 nginx nginx 4096 Aug 5 15:45 05
drwxrwxr-x 2 nginx nginx 4096 Aug 7 11:33 07
drwxrwxr-x 2 nginx nginx 91 Aug 21 17:02 21
drwxrwxr-x 2 nginx nginx 102 Aug 25 14:59 25
drwxrwxr-x 2 nginx nginx 104 Aug 26 16:12 26
[root@04302a060834 08]#
3. Conclusion: If the 26 directory is created by the root user from the command line, an error will occur when the nginx user writes files to it via the API. If the 26 directory is created by the nginx user via the API, no error will occur when the nginx user writes files to it via the API. I recommend writing files using the root user from the command line. This ensures that both directory creation and file writing are performed by the root user.
