Matthew Daly's Blog

I'm a web developer in Norfolk. This is my blog...

15th December 2012 12:26 am

Running the PHP Development Server With Laravel

One thing that I’ve really never liked about PHP is the requirement to install a full-blown web server, so I was pleased when PHP 5.4 shipped with a built-in development server. However, it seems like no PHP framework has yet embraced this to the extent that their counterparts for languages like Python have.

I’ve recently decided that CodeIgniter is no longer fulfilling what I need from my main go-to PHP framework, and I’ve been looking at Laravel as a likely replacement. It occurred to me that I could create an Artisan task to run the development server quite easily, and after a little tinkering, I put this together, which worked well:

class Runserver_Task {
public function run($arguments)
$port = !isset($arguments[0]) ? 8000: $arguments[0];
echo 'Running PHP development server on port '.$port.'...';
passthru('php -S localhost:'.$port.' -t '.getcwd().'/public');

Once this is in place, you can just run php artisan runserver to run the development server, and hit Ctrl-C to stop it, giving you an experience much like that with Django. Note this requires PHP 5.4 or greater. You also have the option of specifying a different port eg php artisan runserver 7000 for port 7000.

Recent Posts

Snapshot Test Your Vue Components With Jest

Enforcing a Coding Standard With PHP Codesniffer

Decorating Laravel Repositories

My First Laravel Package

Integrating Behat With Laravel

About me

I'm a web and mobile app developer based in Norfolk. My skillset includes Python, PHP and Javascript, and I have extensive experience working with CodeIgniter, Laravel, Django, Phonegap and Angular.js.