loading...

HTTPS Local Development using Caddy in Laradock

dendihandian profile image Dendi Handian ・2 min read

Explore Laradock Services (8 Part Series)

1) Laradock - A PHP Developer's best friend. 2) Redis in Laradock 3 ... 6 3) Mailhog in Laradock 4) PHP-Worker in Laradock 5) PHP-Worker for Scheduler in Laradock 6) RabbitMQ in Laradock 7) Elasticsearch in Laradock 8) HTTPS Local Development using Caddy in Laradock

Having only http protocol on your local development is enough, but sometimes when your project has to access some service locally, your project has to possess the https protocol.

If we are using nginx like in the previous posts, we can't make it to be https for the local development. So to enable this https in a fake way in our local development, we could use caddy instead of nginx.

Prerequisites

If you haven't use Laradock before, try to set up a simple Laravel project like I did here. Then starting from here, we can use caddy as an alternative for nginx.

Configure the Caddy file

You can find the caddy server configuration in caddy\caddy\Caddyfile file. There are some pre-written examples here, but we will use the actual one for the my-awesome-laravel-app from the previous post like this:

https://my-awesome-laravel-app.test {
    root /var/www/my-awesome-laravel-app/public
    fastcgi / php-fpm:9000 php {
        index index.php
    }

    rewrite {
        to {path} {path}/ /index.php?{query}
    }
    gzip
    browse
    log /var/log/caddy/access.log
    errors /var/log/caddy/error.log

    tls self_signed
}

Run the containers

If you have nginx container running, you have to stop it first with:

docker-compose stop nginx

Then, you should able to run caddy and php-fpm container with this command:

docker-compose up -d caddy php-fpm

You may want to set the APP_URL in the laravel .env:

APP_URL=https://my-awesome-laravel-app.test

Then you should able to access it on https://my-awesome-laravel-app.test. Although you will get the Not Secure status next to the address bar like in Chrome browser, you still able to open it in https.

Have fun exploring caddy!


Explore Laradock Services (8 Part Series)

1) Laradock - A PHP Developer's best friend. 2) Redis in Laradock 3 ... 6 3) Mailhog in Laradock 4) PHP-Worker in Laradock 5) PHP-Worker for Scheduler in Laradock 6) RabbitMQ in Laradock 7) Elasticsearch in Laradock 8) HTTPS Local Development using Caddy in Laradock

Posted on by:

dendihandian profile

Dendi Handian

@dendihandian

Please teach me how to prettify database schema, implement any design patterns and do TDD in Drupal / Wordpress and how to make them not slow as ever.

Discussion

markdown guide