DEV Community

Cover image for Create Lumen development environment in 1 minute
Mạnh Đạt
Mạnh Đạt

Posted on

Create Lumen development environment in 1 minute

So recently I need to study lumen (from Laravel). I used Laravel back in version 4.2. A lot of things has changed. I need to setup the environment very quickly and dive right into writing application.

Having not so pleasant setting up Laravel (with Homestead, Vagrant...) I decide to find a method that help me (and other people like me) to get started quickly. After a few hours, I finally have the setup I really like.

TLDR:
Here is the video:
https://www.youtube.com/watch?v=nympC_8CWwE&feature=youtu.be
Here is the git repo:
https://github.com/datmt/docker-microservices

For the patient reader, read on.

Step 0: Clone the repo

This is a must.

Step 1: choose a domain name, put in your hosts file.

Don't worry, you don't need to buy any domain. You can pick any domain, even google.com.

In my case, I used cnn.com.

Alt Text

Step 2: Update the domain in default.conf file

Now, in the lumen-dev folder, there is a file called default.conf. This is the default configuration for nginx server.

Find the part says cnn.com and replace it with your own domain.

This is the content of the default.conf file

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    root   /usr/share/nginx/html;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php_server:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}


server {
    listen 80 default_server;


    root /usr/share/nginx/html/public;
    index index.php index.html index.htm;

    server_name cnn.com;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php_server:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }


}

Enter fullscreen mode Exit fullscreen mode

Step 3: Install composer packages

cd to src folder and run composer install. In case you don't have composer installed, download the lumen.tar.gz file under archives and extract it. There is a vendor folder there.
Copy that vendor folder to src/.

Step 4: Edit your port

My default configuration use port 8089. If you want to use other port, change it accordingly. One caution if you use port 80 is to make sure that port is free. Many applications use port 80 so you may not be able to start the application.
This is the docker-compose.yml file:

version: '3.8'

services:
    nginx:
        image: nginx:1.19.6
        container_name: nginx
        volumes:
            - ./src:/usr/share/nginx/html
            - ./default.conf:/etc/nginx/conf.d/default.conf
        ports:
            - 8089:80
        links:
            - php_server
    php_server:
        container_name: php_server
        image: php:7.4.14-fpm-buster
        volumes:
            - ./src:/usr/share/nginx/html


Enter fullscreen mode Exit fullscreen mode

Step 5: Use docker-compose to start the app

In lumen-dev folder (where you have docker-compose.yml file), run

docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

Now, you can open your browser and access your application at the port you choose.

Have questions? Please let me know

Top comments (0)