Create a server running PHP with Gulp and Livereload

I would like to adapt this code to work with PHP files. I have a local server running MAMP, but I can’t understand how this code works to make the necessary changes. I know that the Node server will not interpret PHP files, but I am confused by this architecture using serve-static and serve-index , because apparently I can’t just use the local file path inside the local MAMP host to serve these files. right? I also wonder why he needs 2 ports (9000 and 35729).

 gulp.task('connect', ['styles'], function () { var serveStatic = require('serve-static'); var serveIndex = require('serve-index'); var app = require('connect')() .use(require('connect-livereload')({port: 35729})) .use(serveStatic('.tmp')) .use(serveStatic('app')) .use('/bower_components', serveStatic('bower_components')) .use(serveIndex('app')); require('http').createServer(app) .listen(9000) .on('listening', function () { console.log('Started connect web server on http://localhost:9000'); }); }); gulp.task('serve', ['connect', 'watch'], function () { require('opn')('http://localhost:9000'); }); gulp.task('watch', ['connect'], function () { $.livereload.listen(); // watch for changes gulp.watch([ 'app/*.php', '.tmp/styles/**/*.css', 'app/scripts/**/*.js', 'app/images/**/*' ]).on('change', $.livereload.changed); gulp.watch('app/styles/**/*.scss', ['styles']); gulp.watch('bower.json', ['wiredep']); }); 

Basically I want to use PHP for templates (footer, header, etc.) for a website like this person posted here .

I have the feeling that people don’t do this anymore, so any suggestions for developing an interface with static assets and templates (for subsequent adaptation to WordPress or other PHP-based CMS) are welcome.

EDIT

Read the following: Gulp -webapp launches BrowserSync and PHP

+5
source share
1 answer

I use my own PHP installation as a server, but I start this server using the plugin 'gulp -connect-php'. I haven't used it with XAMPP / MAMP yet, but probably you just need to reinstall "bin" and "ini" to install XAMPP / MAMP PHP. But I have no solution how you can connect Gulp to your database.

'gulp -connect-php':

https://www.npmjs.com/package/gulp-connect-php

 var gulp = require('gulp'), livereload = require('gulp-livereload'), connectPHP = require('gulp-connect-php'); gulp.task('connect', function() { connectPHP.server({ hostname: '0.0.0.0', bin: 'C:/php/php.exe', ini: 'C:/php/php.ini', port: 8000, base: 'dev', livereload: true }); }); 

Gulp Only Connect can start the Node server (if I'm not mistaken).

Port 35729 is for javascript, which you need to place at the bottom of your PHP HTML files, where you put your other scripts. Grunt also uses the exact same code:

 <script src="//localhost:35729/livereload.js"></script> 

Port 9000 is probably the specific port for the Gulp Connect server.

+2
source

Source: https://habr.com/ru/post/1208148/


All Articles