Issue with connecting/excuting PHP through gulp-connect - php

I am trying to use/run Google Web-Starter-Kit with PHP code and surfing through internet I found gulp-connect-php which helps to run PHP files inside gulp server(we can connect gulp with our local php service). So that i installed gulp-connect-php and added the following code to gulpfile.js
code:
var connect = require('gulp-connect-php');
gulp.task('connect', function() {
connect.server({
hostname: '0.0.0.0',
bin: 'C:/wamp/bin/php/php5.5.12/php.exe',
ini: 'C:/wamp/bin/php/php5.5.12/php.ini',
port: 8000,
base: 'dev'
});
});
gulp.task('default', ['connect']);
and entered the below command to execute gulp server with gulp-conntect
>gulp connect
but it throwing some ERROR with path i specified for PHP applicatoin.
ERROR:
E:\my-project>gulp connect
[10:51:57] Using gulpfile E:\my-project\gulpfile.js
[10:51:57] Starting 'connect'...
[10:51:57] Finished 'connect' after 12 ms
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn C:/wamp/bin/php/php5.5.12/php.exe ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
I don't know where the issue lies on. please help on this.

An ENOENT error usually indicates that a file or directory is missing. Seeing that you are on windows, this would most likely be due to a wrong direction of slashes.
Try
bin: 'C:\\wamp\\bin\\php\\php5.5.12\\php.exe'
(same for ini) and make sure this file really exists! Other than that, if you can call php directly from your command line, you shouldn't need to point to the EXE file at all.

Related

net::ERR_CONNECTION_REFUSED using Laravel 9, ReactJs with vite js

I'm trying to build an app using Laravel 9 and ReactJS with vite js. I tried following command to build.
npm run dev
But I'm getting following errors,
GET http://[::1]:5173/resources/css/app.css net::ERR_CONNECTION_REFUSED
GET http://[::1]:5173/#vite/client net::ERR_CONNECTION_REFUSED
GET http://[::1]:5173/resources/js/app.jsx net::ERR_CONNECTION_REFUSED
GET http://[::1]:5173/#react-refresh net::ERR_CONNECTION_REFUSED
If you entered npm run build on production, your .env file looks good and you still have such errors as the author just delete hot file in public directory
This means that your assets are not built yet, use npm run build.
In my case the issue was that the port 5173 was already in use.
I've just freed it - and everything worked again. Hope that helps.
Its Work for me
1-First Run npm run dev in Terminal
2-Then Run npm run build
I think I may have found a solution with the build option called Rollup.
When building in production, rollup will remove unused code. In this process it will bundle the required assets and reference them in accordance to the URL that you would be using at that current moment.
To fixed it, you could try this:
export default defineConfig({
build: {
rollupOptions: {}
}
})
I was helped by a similar issue posted on Github so maybe you could use that as a point of reference.
Here is the Discussion
build assets before uploading your project in live server or cpanel
you can use this code - npm run build
you can see some change in your project folder after build assets file.
assets file will come to this folder - public->build
add host in your vite.config.js, so it will force it to IPv4
export default defineConfig({
server: {
host: '127.0.0.1', // Add this to force IPv4 only
},
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.js'],
refresh: true,
}),
],
});
Local is working fine for me, try adding this to vite.config.js file:
server: { cors: false },
or (try adding and mixing all values)
server: { https: false, cors: false, hmr: false, port: 8000 },

Unoconv and IIS perimission issues

Looking for some advise on setting up Unoconv on IIS.
I am trying to run this via PHP but I get the following error.
Verbosity set to level 3
Using office base path: C:\Program Files\LibreOffice
Using office binary path: C:\Program Files\LibreOffice\program
DEBUG: Connection type: socket,host=127.0.0.1,port=2002,tcpNoDelay=1;urp;StarOffice.ComponentContext
DEBUG: Existing listener not found.
DEBUG: Launching our own listener using C:\Program Files\LibreOffice\program\soffice.exe.
LibreOffice listener arguments are ['C:\\Program Files\\LibreOffice\\program\\soffice.exe', '--headless', '--invisible', '--nocrashreport', '--nodefault', '--nofirststartwizard', '--nologo', '--norestore', '--accept=socket,host=127.0.0.1,port=2002,tcpNoDelay=1;urp;StarOffice.ComponentContext'].
LibreOffice listener successfully started. (pid=8808)
Failed to connect to C:\Program Files\LibreOffice\program\soffice.exe (pid=8808) in 6 seconds.
Connector : couldn't connect to socket (WSAECONNREFUSED, Connection refused)
Error: Unable to connect or start own listener. Aborting.
If I run the following command in CMD unoconv --listener prior to running the PHP script to convert the file everything works as expected, but I do not want to manage the listener creation process myself as unoconv should do this.
If I switch the App Pool Identity to LocalSystem everything works the listener gets created and file conversion work, but this is giving too much access.
Any Ideas as to what I need to configure to get this to work via the usual ApplicationPoolIdentity ?
Thank you
Ged
Give NAME_OF_YOUR_MACHINE\IIS_IUSRS permissions on the relevant folders and try to use AppPoolIdentity

php command is not recognized in wamp

I'm working on websocket. I came across this article, and simply downloaded their file and try running it in my localhost.
https://www.sanwebe.com/2013/05/chat-using-websocket-php-socket
What I understand is, they want to sue local server's websocket server.
But I have problem in starting up the server. I'm using windows 10 with wamp 2.2. As I checked webscket is enabled in my php.ini's extention.
I followed this example to cmd the right path to start it but to no avail:
https://www.sanwebe.com/2013/05/chat-using-websocket-php-socket/comment-page-1#comment-5593
It says 'php.exe' is not recognized as an internal or external ...
I then searched online again, thus set the path to my php folder in the system's environment variable. The path is: C:\wamp\bin\php. Then I closed the cmd and relaunched. Nothing worked out. The same error shows up.
This is what I did on cmd:
1) cd C:\wamp\bin\php
2) php.exe -q C:\projects\myfolder\server.php
Please help me to connect to wamp server's websocket to run the example I've downloaded.In the console, the error shown is:
WebSocket connection to 'ws://localhost:9000/demo/server.php' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
I found the answer from this site: http://rodrixar.blogspot.my/2011/07/how-to-run-php-sockets-in-wamp.html
I did the following,
1) open cmd
2) cd C:\wamp\bin\php\php5.6.19
3)php.exe -q C:\projects\mysite\server.php
4) Firewall open up and allow access for CLI
5) now connection made already..

Laravel BrowserSync without proxy

I'm trying to use Elixir BrowserSync, one of the newest features of Laravel.
I added it to the gulp file
elixir(function(mix) {
mix.sass('app.scss')
.browserSync();
});
when I run "gulp watch" it output this message
[20:49:20] Using gulpfile ~/Desktop/laravel/gulpfile.js
[20:49:20] Starting 'watch'...
[20:49:20] Finished 'watch' after 11 ms
[BS] Proxying: http://homestead.app
[BS] Access URLs:
----------------------------------
Local: http://localhost:3000
External: http://10.9.0.48:3000
Automatically a browser is launched with the url http://localhost:3000 but nothing loads.
I think the problem is related to this line:
[BS] Proxying: http://homestead.app
You can if you use BrowserSyncs server.
mix.browserSync({
proxy: false,
server: {
baseDir: './'
}
});
Are you running multiple homestead sites? It looks like it defaults to proxying through homestead.app if you do not include a proxy setting. If you don't host your local on homestead.app it won't find it.
Try
.browserSync({ proxy: 'domain.app' });
Where domain.app is what you are serving the site with.
The direct answer to your question - it is not possible to not proxy the .browserSync. Long side-answer - you can still use elixir's implementation of browserSync in gulp, but you must have a separate PHP server to interpret the files.
Edit: I saw a way to not proxy by providing the script in the pages manually (by not giving any arguments in the .browserSync() call, but don't remember where and how to do it exactly.
The reason is that browserSync requests all the data from the server for you, injects a little javascript listener and displays everything else:
<script type='text/javascript' id="__bs_script__">//<![CDATA[document.write("<script async src='/browser-sync/browser-sync-client.2.9.11.js'><\/script>".replace("HOST", location.hostname));//]]></script>
One way is to php artisan serve --host=0.0.0.0 in a separate terminal to start up the server and then use the .browserSync({proxy: 'localhost:8000'}). It all works - the BrowserSync UI and all the calls to refresh the pages.
Note: I could not connect to artisan serve without the --host=0.0.0.0.
For those wanting an all automated solution via gulp, here it is:
Use the gulp packages gulp-connect-php and laravel-elixir-browsersync2. The first starts up the php artisan serve and the other connects it to browserSync.
Install the packages:
npm install laravel-elixir-browsersync2 --save-dev
npm install gulp-connect-php --save-dev
Add the required lines to your gulpfile.js:
Code:
var elixir = require('laravel-elixir'),
gulp = require('gulp');
var connectPHP = require('gulp-connect-php');
var BrowserSync = require('laravel-elixir-browsersync2');
elixir(function(mix) {
mix.sass('app.scss');
});
elixir(function(mix) {
connectPHP.server({
base: './public',
hostname: '0.0.0.0',
port: 8000
});
BrowserSync.init();
mix.BrowserSync(
{
proxy: 'localhost:8000',
logPrefix : "Laravel Eixir BrowserSync",
logConnections : false,
reloadOnRestart : false,
notify : false
});
});
Then - simply gulp.
Disclaimer: This might not work with the gulp watch, but there might be people with the answer to that.
There is also a line PHP server not started. Retrying... before the [Laravel Eixir BrowserSync] Proxying: http://localhost:8000. It belongs to gulp-connect-php when trying to check if the server is running.
I found other solution on laracast for Bloomanity and it works with me like a charm!
$ php artisan serve --host=0
and then in your gulp add:
mix.browserSync({proxy: 'localhost:8000'});

Gulp PHP with BrowserSync and a proxy server throwing error

I had to redownload all of my dev tools after upgrading/reset on Windows 10. I can't seem to get my server working with gulp-connect-php, gulp-browser-sync, and http-proxy. The task (below) is actually from this answer: Gulp-webapp running BrowserSync and PHP.
This is on top of a generation of gulp-webapp from Yeoman. The regular "serve" works, but of course doesn't spin up PHP files. I had it working before the upgrade, but now the http-proxy errors out with an ECONNREFUSED when I try to bring up the URL. Note that it doesn't error out until I actually go to the URL, if the task is setup to not open the browser automatically, it won't error until I go to localhost:3000.
Any ideas the cause of this error?
Gulp Task
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_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)
I think I know the reason.
Check or you have php installed on your machine and added to your path variables.
open your command line and type:
$ php --version
If it returns:
sh.exe": php: command not found
It means it is not installed or not in the path variable.
You can install php by simply installing WAMP/XAMP or MAMP
https://www.apachefriends.org/index.html
To make sure it is in your path I like to use patheditor
https://patheditor2.codeplex.com/
There go through these simple steps
1) open Path Editor
2) click 'add' in the 'user' section
3) search the folder where php.exe is. (usually something like: C:/xampp/php)
4) click 'ok' and 'ok' again to close path editor
5) reopen your commandline tool and you will see that $ php --version will find the php.exe
Try to run your gulp task again. It should work!
There was a bad install of http-proxy and/or gulp-php-connect. I uninstalled them, cleared npm cache, and did a fresh install. Everything worked fine after that.

Categories