简体   繁体   English

从PHP exec()函数运行Hugo

[英]Running Hugo from a PHP exec() function

I'm attempting to setup a continuous deployment script for Hugo on a LAMP stack server, and the last snag I'm running into is getting Hugo to run. 我正在尝试在LAMP堆栈服务器上为Hugo设置连续部署脚本,而我遇到的最后一个障碍是让Hugo运行。

The Background 的背景

I have Hugo and PHP installed on a VPS, and for my app, two directories: 我在VPS上安装了Hugo和PHP,对于我的应用程序,有两个目录:

  1. public , where my actual site lives. public ,我的实际站点所在的位置。
  2. hugo , where my entire Hugo setup gets pulled into from GitHub. hugo ,我的整个Hugo设置都从GitHub提取的。

I'm using a GitHub webhook to ping my deploy.php script when I merge into the master branch. 合并到master分支后,我使用GitHub webhook ping我的deploy.php脚本。 Here's the relevant part of that script: 这是该脚本的相关部分:

// 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');

What's happening 发生了什么

Items 1 and 3 run. 项目1和3运行。 Item 2 does not. 项目2没有。

More clearly stated: the latest build pulls from GitHub, and any files I've built ahead of time are copied from the Hugo build into the /public directory. 更明确地说:最新的构建来自GitHub,而我提前构建的所有文件都从Hugo构建复制到/public目录。

I cannot get hugo to run via exec() , though, and I'm not entirely sure why. 但是我无法通过exec()来运行hugo ,而且我也不完全知道为什么。

If I SSH into the server in a terminal window, cd into the /path/to/hugo directory, and run hugo there, everything compiles as expected, which eliminates things like, "Maybe Hugo is installed wrong" or "Maybe Hugo isn't accessible in that directory". 如果我在终端窗口中通过SSH进入服务器,在cd/path/to/hugo目录中,然后在其中运行hugo ,一切都会按预期进行编译,从而消除了诸如“也许Hugo安装错误”或“也许Hugo不是”之类的问题。不能在该目录中访问”。

So... what am I missing? 所以...我想念什么? Thanks in advance! 提前致谢!

Check if this is a path issue, meaning by default, a bash session won't execute a program just because you are in the right folder: you have to specify its path (in your case: the current folder) 检查这是否是路径问题,这意味着默认情况下,bash会话不会仅仅因为您位于正确的文件夹中而执行程序:您必须指定其路径(在您的情况下:当前文件夹)

That means: replace && hugo with && ./hugo 这意味着:用&& ./hugo替换&& hugo

Or, as the OP Chris Ferdinandi did ( comments ), you can use an absolute path: 或者,作为OP克里斯Ferdinandi做( 评论 ),您可以使用绝对路径:

I ssh-ed into the server and ran which hugo to get the appropriate path, and replaced && hugo with that. 我将ssh-sed到服务器中,然后运行which hugo以获得适当的路径,并用该替换了&& hugo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM