在升级/重置Windows 10后,我不得不重新下载所有的开发工具。我似乎无法让我的服务器与gulp-connect-php, gulp-browser-sync和http-proxy一起工作。下面的任务实际上来自这个答案:Gulp-webapp运行BrowserSync和PHP。
这是在约曼的gulp-webapp一代之上。常规的"服务"可以工作,但当然不会启动PHP文件。在升级之前,我让它工作,但是现在当我试图打开URL时,http代理会出现ECONNREFUSED错误。请注意,它不会出现错误,直到我真的去到URL,如果任务设置为不自动打开浏览器,它不会出现错误,直到我去到localhost:3000。
知道这个错误的原因吗?
<杯任务/strong>
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 Run Task with Error
$ 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_moduleshttp-proxylibhttp-proxyindex.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来安装phphttps://www.apachefriends.org/index.html
为了确保它在你的路径中,我喜欢使用路径编辑器https://patheditor2.codeplex.com/
下面就是这些简单的步骤1)打开路径编辑器2)点击"用户"部分的"添加"3)搜索php.exe所在的文件夹。(通常是:C:/xampp/php)4)再次点击"确定"one_answers"确定"关闭路径编辑器5)重新打开命令行工具,你会看到$ PHP——version会找到PHP .exe
尝试再次运行gulp任务。应该能行!
http-proxy和/或gulp-php-connect安装错误。我卸载了它们,清除了npm缓存,然后重新安装。之后一切正常