Getting Started With Lumen
In my posts, I discuss micro-frameworks quite often. It is clear that I am a big proponent of micro-frameworks as far as php development is concerned and if you consider the benefits of micro-frameworks, it’s easy to see why. They are lightweight, they have low overhead in setting up and most of them are fairly versatile. Not to mention that they are easily extensible. For these reasons, I take great interest in experimenting with micro-frameworks and Lumen has been my most recent experimental project.
Lumen is a micro-framework developed by Laravel. It offers all the features and benefits you’d expect from such a lightweight micro-framework but there’s one that particularly stands out. Lumen makes it incredibly easy to upgrade your project into a Laravel project. This is important if your project grows in size and requires you to upgrade from a micro-framework to a full framework like Laravel. That’s a topic for a future post though. In this post, I will mainly address setting up a lumen project and getting started. This will be done on a windows machine. If you’re interested in looking at the docs directly, you can do so here. On this post, I will attempt to simplify the process as much as possible.
You will need to install composer for this process. If you haven’t done so, you can check out my last post on how to do it.
Like, the laravel framework, lumen has some system requirements to be met. If you don’t want to worry about installing dependencies yourself, you can set up the Laravel Homestead virtual machine. This is the recommended approach. This is not my personal method of choice however. I will be going over setting up a lumen project using composer.
It’s worth to note that if you’re not using Homestead, then you need to make sure the server meets these requirements:
- PHP ≥ 7.0
- OpenSSL PHP Extension
- PDO PHP Extension
- Mbstring PHP Extension
Using the Lumen Installer
In order to use the lumen installer, download it using composer as follows:
composer global require "laravel/lumen-installer"
Once this is done, place the “composer/vendor/bin” directory in your PATH environment variables. This will allow you to execute the “lumen” command on your command line.
After the the installation process is complete, you can now create a new project in a specified directory by typing
lumen new [project-name]
This is my favourite method to start a new Lumen project as it only takes one line and you’re ready to go.
Navigate to the directory of your choice and execute the following composer command:
composer create-project --prefer-dist laravel/lumen [project-name]
This will create the lumen project and download all the necessary dependencies as well.
Now that you’ve created your Lumen project, it’s time to serve it and take a look at your work so far. Type the following on your command prompt in the directory of your project:
php -S localhost:8000 -t public
This means your app will be served on port 8000 of the localhost server. You can change this port if you wish to do so.
To view your new app, open your browser and visit “http://localhost:8000”.