質問編集履歴

3

追記

2017/10/10 05:21

投稿

mugen
mugen

スコア13

test CHANGED
File without changes
test CHANGED
@@ -129,3 +129,59 @@
129
129
  なぜexecが動かないのか見当もつかないので解決の糸口でもつかめたらと思っています。
130
130
 
131
131
  よろしくお願い致します。
132
+
133
+
134
+
135
+
136
+
137
+ ###追記
138
+
139
+ ①同じ条件でロリポップのサーバーで試してみたところ、問題なく動きました。
140
+
141
+
142
+
143
+ なのでそもそもexecが使えないのか?と思い
144
+
145
+ ```
146
+
147
+ echo exec('ls -l /virtual/exectest/');
148
+
149
+ ```
150
+
151
+ を試すも問題なく表示されました。
152
+
153
+
154
+
155
+ ②試したことで出たStatus: 404が気になり、require_onceで
156
+
157
+ execで呼び出すphpと同じパスを入れてみました。
158
+
159
+ ```
160
+
161
+ require_once ('/virtual/exectest/exectest.php');
162
+
163
+ exec('nohup php /virtual/exectest/exectest.php > /dev/null &');
164
+
165
+
166
+
167
+ ```
168
+
169
+
170
+
171
+ exectest.phpはメールを送るものだけにしました。
172
+
173
+ ```
174
+
175
+ mail($to, $subject, $message, $headers);
176
+
177
+ ```
178
+
179
+ するとなぜかメールが2通届くようになりました。
180
+
181
+ これは、require_onceとexecで2回呼び出されているからなのでしょうか?
182
+
183
+ require_onceを消すとメールは1通も届きません。
184
+
185
+
186
+
187
+ なにか気が付いた点があれば教えてください。

2

加筆修正

2017/10/10 05:21

投稿

mugen
mugen

スコア13

test CHANGED
File without changes
test CHANGED
@@ -8,73 +8,7 @@
8
8
 
9
9
 
10
10
 
11
- ところが移行先のサーバーではexecが動いておらず、サーバー側に確認すると
11
+ ところが移行先のサーバーではexecが動いていませんでした。
12
-
13
-
14
-
15
- shtml以外の拡張子でSSIを実行させる場合は、「.htaccess」ファイルを使用して設定を変更する必要があります。
16
-
17
-
18
-
19
- との回答でした。
20
-
21
-
22
-
23
- execが動かなかったのはphpファイルのみでSSIを実行させようとしてたからなのでしょうか?
24
-
25
-
26
-
27
-
28
-
29
- また、「.htaccess」で以下の記述をしたのですが、phpのコードが出てきてしまいました。
30
-
31
- ```
32
-
33
- <Files "itemsEditor.php">
34
-
35
- Options +Includes
36
-
37
- Addtype "text/html; charset=utf-8" .html .shtml .php .inc
38
-
39
- AddOutputFilter INCLUDES .html .shtml .php .inc
40
-
41
- AddHandler server-parsed .html .shtml .php .inc
42
-
43
- </Files>
44
-
45
- ```
46
-
47
-
48
-
49
- 記述順でphpのコードが出てきてしまうことがあるという記事を見つけたので以下のように変更したところphpファイルが実行されず、ダウンロードされてしまうようになりました。
50
-
51
- ```
52
-
53
- <Files "itemsEditor.php">
54
-
55
- Options +Includes
56
-
57
- Addtype "text/html; charset=utf-8" .html .shtml .php .inc
58
-
59
- AddOutputFilter INCLUDES .html .shtml .php .inc
60
-
61
- AddHandler server-parsed .html .shtml .php .inc
62
-
63
-
64
-
65
- AddType "application/x-httpd-php; charset=utf-8" .php .inc
66
-
67
- AddType "application/x-httpd-php-source; charset=utf-8" .phps
68
-
69
- </Files>
70
-
71
- ```
72
-
73
- 変更後の現象はMIMEタイプが違っているからダウンロードされてしまうと思うのですが、
74
-
75
- phpのMIMEタイプが間違っているのでしょうか?
76
-
77
-
78
12
 
79
13
 
80
14
 
@@ -82,6 +16,116 @@
82
16
 
83
17
  ```
84
18
 
85
- exec('php /virtual/IPアドレス/home/html_test/admin/exectest.php > /dev/null &');
19
+ exec('php /virtual/exectest/exectest.php > /dev/null &');
86
20
 
87
21
  ```
22
+
23
+
24
+
25
+ これが動かなかったので以下で試してみました。
26
+
27
+ ```
28
+
29
+ chmod("/virtual/exectest/log", 0755);
30
+
31
+ exec('php /virtual/exectest/exectest.php > /dev/null &', $output, $return_var);
32
+
33
+ var_dump($output,$return_var);
34
+
35
+ ```
36
+
37
+
38
+
39
+ array(0) { } int(0)と帰ってきましたがexectest.phpは実行されていなさそうです。
40
+
41
+ chmodの返り値はtrueだったので成功していると思います。
42
+
43
+
44
+
45
+ 実行するexectest.phpの方にはログファイルを作る処理をしています。
46
+
47
+ ```
48
+
49
+ error_log('message', 3, '/virtual/exectest/test.log');
50
+
51
+ ```
52
+
53
+ 直接exectest.phpにアクセスするとログファイルが作成されるのですが、
54
+
55
+ execの方では作成されませんでした。
56
+
57
+
58
+
59
+
60
+
61
+ ###試したこと
62
+
63
+ 上記コードでダメだったので以下のコードを試してみました。
64
+
65
+ ```
66
+
67
+ exec('nohup php /virtual/exectest/exectest.php 2>&1', $output, $return_var);
68
+
69
+ var_dump($output);
70
+
71
+ var_dump($return_var);
72
+
73
+ ```
74
+
75
+ 返り値は以下の通りです。
76
+
77
+ ```
78
+
79
+ array(13) {
80
+
81
+ [0]=> string(23) "Content-type: text/html"
82
+
83
+ [1]=> string(0) ""
84
+
85
+ [2]=> string(10) "array(4) {"
86
+
87
+ [3]=> string(7) "
88
+
89
+ [0]=>"
90
+
91
+ [4]=> string(26) " string(11) "Status: 404""
92
+
93
+ [5]=> string(7) "
94
+
95
+ [1]=>"
96
+
97
+ [6]=> string(38) " string(23) "Content-type: text/html""
98
+
99
+ [7]=> string(7) "
100
+
101
+ [2]=>"
102
+
103
+ [8]=> string(14) " string(0) """
104
+
105
+ [9]=> string(7) "
106
+
107
+ [3]=>"
108
+
109
+ [10]=> string(39) " string(24) "No input file specified.""
110
+
111
+ [11]=> string(1) "}"
112
+
113
+ [12]=> string(8) "int(255)" }
114
+
115
+ int(0)
116
+
117
+ ```
118
+
119
+
120
+
121
+ ファイルが見つからないエラーだと思うのですが
122
+
123
+ 同階層に入れていて見つからないというのも謎で、
124
+
125
+ $return_varの返り値は0なので正常終了しているということではないのでしょうか?
126
+
127
+
128
+
129
+ なぜexecが動かないのか見当もつかないので解決の糸口でもつかめたらと思っています。
130
+
131
+ よろしくお願い致します。

1

追記

2017/10/02 10:05

投稿

mugen
mugen

スコア13

test CHANGED
File without changes
test CHANGED
@@ -73,3 +73,15 @@
73
73
  変更後の現象はMIMEタイプが違っているからダウンロードされてしまうと思うのですが、
74
74
 
75
75
  phpのMIMEタイプが間違っているのでしょうか?
76
+
77
+
78
+
79
+
80
+
81
+ execで外部スクリプトを実行する部分はphpファイルの中に以下の記述があります。
82
+
83
+ ```
84
+
85
+ exec('php /virtual/IPアドレス/home/html_test/admin/exectest.php > /dev/null &');
86
+
87
+ ```