gpt4 book ai didi

php - Gulp PHP 与 BrowserSync 和代理服务器抛出错误

转载 作者:太空宇宙 更新时间:2023-11-03 22:14:54 24 4
gpt4 key购买 nike

在 Windows 10 上升级/重置后,我必须重新下载所有开发工具。我似乎无法让我的服务器使用 gulp-connect-php、gulp-browser-sync 和 http-proxy。任务(如下)实际上来自这个答案:Gulp-webapp running BrowserSync and PHP .

这是在 Yeoman 的一代 gulp-webapp 之上。常规的“服务”可以工作,但当然不会启动 PHP 文件。我在升级之前可以正常工作,但现在当我尝试打开 URL 时,http 代理会出现 ECONNREFUSED 错误。请注意,直到我实际访问该 URL 时它才会出错,如果该任务设置为不自动打开浏览器,则在我访问 localhost:3000 之前它不会出错。

有什么想法导致此错误的原因吗?

Gulp 任务

gulp.task('php-serve', ['styles', 'fonts'], () => {
phpConnect.server({
port: 9001,
base: 'app',
open: false
});
const proxy = httpProxy.createProxyServer({});
browserSync({
notify: false,
open: false,
port: 9000,
server: {
baseDir: ['.tmp', 'app'],
routes: {
'/bower_components': 'bower_components'
},
middleware: function (req, res, next) {
var url = req.url;
if (!url.match(/^\/(styles|fonts|bower_components)\//)) {
proxy.web(req, res, { target: 'http://127.0.0.1:9001' });
}
else {
next();
}
}
}
});

gulp.watch([
'app/*.html',
'app/*.php',
'app/scripts/**/*.js',
'app/images/**/*',
'.tmp/fonts/**/*'
]).on('change', reload);

gulp.watch('app/styles/**/*.scss', ['styles']);
gulp.watch('app/fonts/**/*', ['fonts']);
gulp.watch('bower.json', ['wiredep', 'fonts']);
});

Gulp 运行任务时出错

$ gulp php-serve
[07:30:09] Requiring external module babel-core/register
[07:30:11] Using gulpfile ~\...\gulpfile.babel.js
[07:30:11] Starting 'styles'...
[07:30:12] Starting 'fonts'...
[07:30:12] Finished 'styles' after 1.08 s
[07:30:12] Finished 'fonts' after 306 ms
[07:30:12] Starting 'php-serve'...
[07:30:12] Finished 'php-serve' after 183 ms

[BS] Access URLs:
----------------------------------
Local: http://localhost:9000
External: http://x.x.x.x:9000
----------------------------------
UI: http://localhost:3001
UI External: http://x.x.x.x:3001
----------------------------------
[BS] Serving files from: .tmp
[BS] Serving files from: app

C:\...\node_modules\http-proxy\lib\http-proxy\index.js:119

throw err;
^
Error: connect ECONNREFUSED
at exports._errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)

最佳答案

我想我知道原因了。

检查您的计算机上是否安装了 php 并将其添加到路径变量中。

打开命令行并输入:

$ php --version

如果返回:

sh.exe": php: command not found

表示没有安装或者不在path变量中。

只需安装WAMP/XAMP或MAMP即可安装php https://www.apachefriends.org/index.html

为了确保它在你的路径中,我喜欢使用路径编辑器 https://patheditor2.codeplex.com/

完成这些简单的步骤1)打开路径编辑器2)单击“用户”部分中的“添加”3)搜索php.exe所在的文件夹。 (通常类似于:C:/xampp/php)4) 单击“确定”并再次单击“确定”关闭路径编辑器5) 重新打开命令行工具,您将看到 $ php --version 将找到 php.exe

尝试再次运行 gulp 任务。它应该有效!

关于php - Gulp PHP 与 BrowserSync 和代理服务器抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32184965/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com