簡體   English   中英

使用 PHP 頁面在遠程 linux 服務器上執行安裝的軟件命令

[英]Execute an installed software command on a remote linux server using a PHP page

我正在開發一個 3D 打印 web 頁面。 為了計算材料和時間,我試圖讓 web 在文件上運行 cura-engine 軟件(控制台程序)。

我在 Google Cloud Platform 中創建了一個虛擬機,在 debian 10 下運行 LAMP 堆棧。我使用 apt 安裝了 cura'engine package,我可以從終端運行它(通過 ssh):

eduardoj_vieirav@instance-1-vm:/var/www/html$ CuraEngine

Cura_SteamEngine version 3.3.0
Copyright (C) 2018 Ultimaker

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
...

但是當嘗試使用 exec 或 shell_exec 使用 php 執行此命令時,我沒有 output。

<?php
echo exec('CuraEngine');
?>

我還嘗試對文件執行操作,我可以再次使用以下命令從 ssh 執行此操作:

eduardoj_vieirav@instance-1-vm:/var/www/html$ CuraEngine slice -v -j resources/definitions/creality_ender3.def.json -o gcode/output.gcode -l STL/cube.stl

但同樣不能從 php 運行

<?php
echo exec('CuraEngine slice -v -j resources/definitions/creality_ender3.def.json -o gcode/output.gcode -l STL/cube.stl');
?>

我發現我無法執行 CuraEngine 很奇怪,因為其他命令(例如uname -a0返回 output。

可能是 PHP 的$PATH環境變量有問題。 嘗試指定CuraEngine的絕對路徑(如果需要,使用whereis CuraEngine命令)。

這可能都是由於權限,因為我可以從許多其他在線帖子中找到。 嘗試這樣寫(注意末尾的 2>&1),output 應該指出是否是權限錯誤。

<?php
echo exec('CuraEngine slice -v -j resources/definitions/creality_ender3.def.json -o gcode/output.gcode -l STL/cube.stl  2>&1');
?>

之后,如果是權限錯誤,請應用本文中提到的所有權更改,它應該可以工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM