2017-03-01 6 views
0

Ich versuche einen Shell-Befehl auszuführen, damit gulp kompiliert wird.Run Schluck "Npm Start" von einem PHP-Dokument?

i in der Regel laufen:

cd 
cd /var/www/html/ 
npm uninstall gulp --save 
npm install gulp --save 

npm start 

und die schluck Datei kompiliert gut.

Ich muss wissen, ob eine Möglichkeit theres die schluck Datei zu kompilieren (im Wesentlichen die npm Startbefehl von einem PHP-Dokument ausgeführt

$output = shell_exec('./compileNpmStart.sh'); 

// display $output 
echo $output; 

Dies scheint aber zu kompilieren.

Nach dem Übersetzen i statt korrekte Zusammenstellung bekam eine Protokolldatei.

0 info it worked if it ends with ok 
1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'start' ] 
2 info using [email protected] 
3 info using [email protected] 
4 verbose run-script [ 'prestart', 'start', 'poststart' ] 
5 info lifecycle [email protected]~prestart: [email protected] 
6 warn lifecycle npm is using /usr/bin/nodejs but there is no node binary in the current PATH. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with. 
7 silly lifecycle [email protected]~prestart: no script for prestart, continuing 
8 info lifecycle [email protected]~start: [email protected] 
9 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true 
10 verbose lifecycle [email protected]~start: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/var/www/html/node_modules/.bin 
11 verbose lifecycle [email protected]~start: CWD: /var/www/html 
12 silly lifecycle [email protected]~start: Args: [ '-c', 'gulp serve' ] 
13 info lifecycle [email protected]~start: Failed to exec start script 
14 verbose stack Error: [email protected] start: `gulp serve` 
14 verbose stack spawn sh ENOENT 
14 verbose stack  at exports._errnoException (util.js:1023:11) 
14 verbose stack  at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32) 
14 verbose stack  at onErrorNT (internal/child_process.js:359:16) 
14 verbose stack  at _combinedTickCallback (internal/process/next_tick.js:74:11) 
14 verbose stack  at process._tickCallback (internal/process/next_tick.js:98:9) 
15 verbose pkgid [email protected] 
16 verbose cwd /var/www/html 
17 error Linux 4.8.6-x86_64-linode78 
18 error argv "/usr/bin/nodejs" "/usr/bin/npm" "start" 
19 error node v7.5.0 
20 error npm v4.1.2 
21 error file sh 
22 error path sh 
23 error code ELIFECYCLE 
24 error errno ENOENT 
25 error syscall spawn sh 
26 error [email protected] start: `gulp serve` 
26 error spawn sh ENOENT 
27 error Failed at the [email protected] start script 'gulp serve'. 
27 error Make sure you have the latest version of node.js and npm installed. 
27 error If you do, this is most likely a problem with the base-prep package, 
27 error not with npm itself. 
27 error Tell the author that this fails on your system: 
27 error  gulp serve 
27 error You can get information on how to open an issue for this project with: 
27 error  npm bugs base-prep 
27 error Or if that isn't available, you can get their info via: 
27 error  npm owner ls base-prep 
27 error There is likely additional logging output above. 
28 verbose exit [ 1, true ] 
+0

lookup shell_exec – Dimi

+0

Ich habe shell_exec, System(), exec() und ein paar mehr versucht. Keiner von ihnen scheint zu arbeiten. Ich denke, dass es eine Art Erlaubnisfehler geben kann. habe versucht, webconsole.php zu installieren und den Befehl von einem webbasierten http://web-console.org/ Terminal auszuführen. habe Erlaubnisfehler bekommen. –

+0

haben Sie versucht, ein Shell-Skript mit SUID zu erstellen und auszuführen? – Dimi

Antwort

1

starten durch das Skript Speichern Sie in einer Datei ausgeführt werden soll, zB compile.sh. geben Sie das Skript th Die korrekten Laufberechtigungen, z.B. chmod 755 compile.sh.

Dann in Ihrem PHP-Skript, fügen Sie die folgenden Schritte aus:

<?php 
// allow script to run for up to 10 minutes 
set_time_limit(600); // seconds 

// output of script will be saved in $output 
$output = shell_exec('./compile.sh'); 

// display $output 
echo $output; 

Dies sollte genug für Sie das Skript mit PHP laufen.

Möglicherweise müssen Sie auf npm und alle Verzeichnisse, die absoluten Pfad verwenden, verweisen. Führen Sie über die Befehlszeile which npm aus, um den vollständigen Pfad zu ermitteln. Führen Sie das Skript über die Befehlszeile aus, um sicherzustellen, dass es funktioniert.

+0

Versucht, dass. Es scheint das Skript auszuführen, aber keinen tatsächlichen Effekt auf die Serverdateien. –

+0

Dateiberechtigungen sind 777 für die Datei compile.sh, die das SH-Skript hat –

+0

Führen Sie './Compile.sh' manuell über die Befehlszeile aus und stellen Sie sicher, dass das Skript selbst keine Fehler enthält. Möglicherweise müssen Sie auch 'npm' als absoluten Pfad angeben. –