Coder Social home page Coder Social logo

grunt-php's Introduction

grunt-php

Start a PHP server

Useful for developing PHP projects or running tests on them.

Pretty much a drop-in replacement for grunt-contrib-connect, except for the middleware option.

Uses the PHP built-in server.

Install

$ npm install --save-dev grunt-php

Usage

require('load-grunt-tasks')(grunt);

grunt.initConfig({
	php: {
		dist: {
			options: {
				port: 5000
			}
		}
	}
});

grunt.registerTask('default', ['php']);

Examples

Start a persistent PHP server and open in browser

grunt.initConfig({
	php: {
		test: {
			options: {
				keepAlive: true,
				open: true
			}
		}
	}
});

grunt.registerTask('test', ['php', 'mocha']);

Use it with BrowserSync

grunt.initConfig({
	php: {
		dist: {
			options: {
				port: 9000,
				base: 'dist' // Project root
			}
		}
	},
	browserSync: {
		dist: {
			bsFiles: {
				src: [
					// Files you want to watch for changes
				]
			},
			options: {
				proxy: '<%= php.dist.options.hostname %>:<%= php.dist.options.port %>',
				watchTask: true,
				notify: true,
				open: true,
				logLevel: 'silent',
				ghostMode: {
					clicks: true,
					scroll: true,
					links: true,
					forms: true
				}
			}
		}
	},
	watch: {
		// Your watch tasks
	}
});

grunt.registerTask('serve', [
	'php:dist',         // Start PHP Server
	'browserSync:dist', // Using the PHP instance as a proxy
	'watch'             // Any other watch tasks you want to run
]);
grunt.initConfig({
	php: {
		watch: {}
	}
});

grunt.registerTask('phpwatch', ['php:watch', 'watch']);

Add path for a custom error log

const path = require('path');

grunt.initConfig({
	php: {
		dist: {
			options: {
				directives: {
					'error_log': path.resolve('logs/error.log')
				}
			}
		}
	}
});

grunt.registerTask('default', ['php']);

Options

Supports all the php-server options in addition to the ones below.

keepAlive

Type: boolean
Default: false

Keep the server alive indefinitely. Any task specified after this will not run.

This option can also be enabled ad-hoc by running the task like grunt php:targetname:keepAlive.

silent

Type: boolean
Default: false

Suppress output produced by the PHP server.

Related

License

MIT © Sindre Sorhus

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.