与浏览器同步和代理服务器抛出错误的Gulp PHP
在Windows 10升级/重置后,我不得不重新下载我所有的开发工具。我似乎无法让我的服务器与gulp-connect-php,gulp-browser-sync和http-proxy一起工作。 下面的任务实际上是从这个答案: Gulp-webapp运行BrowserSync和PHP 。
这是来自Yeoman的一代gulp-webapp。 常规的“服务”工程,但当然不会启动PHP文件。 在升级之前,我已经使用了它,但是现在,当我尝试启动URL时,http-proxy错误与ECONNREFUSED一起出现。 请注意,它不会错误,直到我实际上去的URL,如果任务设置为不自动打开浏览器,它不会错误,直到我去localhost:3000。
任何想法这个错误的原因?
吞噬任务
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 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://xxxx:9000 ---------------------------------- UI: http://localhost:3001 UI External: http://xxxx: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,并将其添加到pathvariables中。
打开你的命令行并键入:
$ php --version
如果它返回:
sh.exe": php: command not found
这意味着它没有安装或不在pathvariables中。
你可以通过安装WAMP / XAMP或MAMP来安装php https://www.apachefriends.org/index.html
为了确保它在你的path中,我喜欢使用patheditor https://patheditor2.codeplex.com/
通过这些简单的步骤1)打开path编辑器2)单击“添加”在“用户”部分3)searchphp.exe所在的文件夹。 (通常类似于:C:/ xampp / php)4)再次单击“确定”和“确定”closurespath编辑器5)重新打开命令行工具,您将看到$ php –version将findphp.exe
尝试再次运行你的吞咽任务。 它应该工作!
http-proxy和/或gulp-php-connect的安装很糟糕。 我卸载了他们,清除了npmcaching,并做了全新的安装。 之后一切正常。
- BrowserSync不断地使用Express / Gulp进行GET
- nmp ubuntu错误权限被拒绝
- 节点更新特定的包
- 为每个路线重新加载浏览器(Express + gulp + Browsersync)
- Gulp在我的macOS上没有成功运行
- Node.js – 自动刷新在Dev
- browserSync的modRewrite不适用于angularjs html5mode的path“app / index.html”与吞咽
- Gulp突然停止了与BrowserSync的合作。 node_modules / glob-watcher上的RangeError
- BrowserSync:如何同时处理HTTP和HTTPS?