运行 来自 PHP exec() 函数的 Hugo
Running Hugo from a PHP exec() function
我正在尝试在 LAMP 堆栈服务器上为 Hugo 设置一个持续部署脚本,我 运行 遇到的最后一个障碍是让 Hugo 到 运行 .
背景
我在 VPS 上安装了 Hugo 和 PHP,对于我的应用程序,有两个目录:
public
,我的实际站点所在的位置。
hugo
,我的整个 Hugo 设置从 GitHub. 拉入
当我合并到 master
分支时,我正在使用 GitHub webhook 来 ping 我的 deploy.php
脚本。这是该脚本的相关部分:
// 1. Pull the latest build from GitHub
exec('cd /path/to/hugo && git fetch --all && git reset --hard origin/master');
// 2. Run Hugo to compile any new posts and pages into HTML
exec('cd /path/to/hugo && hugo');
// 3. Copy the files in the /public directory from Hugo into the /public app directory
exec('cd /path/to/hugo && cp -r /path/to/hugo/public/. public');
发生了什么事
项目 1 和 3 运行。项目 2 没有。
更明确地说:最新版本来自 GitHub,我提前构建的任何文件都从 Hugo 版本复制到 /public
目录。
不过,我无法通过 exec()
将 hugo
转换为 运行,而且我不完全确定为什么。
如果我在终端 window 中通过 SSH 连接到服务器,cd
进入 /path/to/hugo
目录,然后 运行 hugo
在那里,一切都会编译为预期的,它消除了 "Maybe Hugo is installed wrong" 或 "Maybe Hugo isn't accessible in that directory".
之类的东西
所以...我错过了什么?提前致谢!
检查这是否是路径问题,这意味着默认情况下,bash 会话不会仅仅因为您在正确的文件夹中而执行程序:您必须指定其路径(在您的情况下:当前文件夹)
意思是:用&& ./hugo
替换&& hugo
或者,如OP Chris Ferdinandi did (),可以使用绝对路径:
I ssh-ed into the server and ran which hugo
to get the appropriate path, and replaced && hugo
with that.
我正在尝试在 LAMP 堆栈服务器上为 Hugo 设置一个持续部署脚本,我 运行 遇到的最后一个障碍是让 Hugo 到 运行 .
背景
我在 VPS 上安装了 Hugo 和 PHP,对于我的应用程序,有两个目录:
public
,我的实际站点所在的位置。hugo
,我的整个 Hugo 设置从 GitHub. 拉入
当我合并到 master
分支时,我正在使用 GitHub webhook 来 ping 我的 deploy.php
脚本。这是该脚本的相关部分:
// 1. Pull the latest build from GitHub
exec('cd /path/to/hugo && git fetch --all && git reset --hard origin/master');
// 2. Run Hugo to compile any new posts and pages into HTML
exec('cd /path/to/hugo && hugo');
// 3. Copy the files in the /public directory from Hugo into the /public app directory
exec('cd /path/to/hugo && cp -r /path/to/hugo/public/. public');
发生了什么事
项目 1 和 3 运行。项目 2 没有。
更明确地说:最新版本来自 GitHub,我提前构建的任何文件都从 Hugo 版本复制到 /public
目录。
不过,我无法通过 exec()
将 hugo
转换为 运行,而且我不完全确定为什么。
如果我在终端 window 中通过 SSH 连接到服务器,cd
进入 /path/to/hugo
目录,然后 运行 hugo
在那里,一切都会编译为预期的,它消除了 "Maybe Hugo is installed wrong" 或 "Maybe Hugo isn't accessible in that directory".
所以...我错过了什么?提前致谢!
检查这是否是路径问题,这意味着默认情况下,bash 会话不会仅仅因为您在正确的文件夹中而执行程序:您必须指定其路径(在您的情况下:当前文件夹)
意思是:用&& ./hugo
&& hugo
或者,如OP Chris Ferdinandi did (
I ssh-ed into the server and ran
which hugo
to get the appropriate path, and replaced&& hugo
with that.