Andrew Koster
Andrew Koster

Reputation: 1845

How does one add PHP extensions to the docker-compose.yml configuration that comes with Laravel Sail?

I created a new Laravel 8 project, which comes with Laravel Sail, a pre-configured Docker environment. It works well, until I need to use a PHP extension.

The Laravel Sail documentation does not appear to mention anything about PHP extensions, which is a significant problem. Any non-trivial PHP site has to use several PHP extensions. Without the ability to add PHP extensions, Laravel Sail (or any other PHP environment) is more or less useless.

There's a Dockerfile and a php.ini in vendor/laravel/sail/runtimes/8.0/. I could copy those files out of vendor and into my own project's code, and hack the docker-compose.yml to point to my versions of those files. However, if I do that, I'll lose any future fixes or improvements that the Laravel Sail people make to those files.

I'm aware of the sail artisan sail:publish command that they mention at the end of the Laravel Sail documentation (https://laravel.com/docs/8.x/sail#sail-customization). It seems to just do what I mentioned above: copies the third-party code into my project, and now suddenly this end-user website is responsible for maintaining its own copy of Laravel Sail.

Surely there's an idiomatic way to add PHP extensions in Laravel Sail, without re-implementing a fork of Laravel Sail in my site's code?

Upvotes: 10

Views: 3388

Answers (1)

George
George

Reputation: 2960

Sail doesn't have any hooks to add your own extensions. The method mentioned in the documentation (and comments above) is the correct way:

Publish to get your own Dockerfile

sail artisan sail:publish

Then update the Dockerfile with your customisations. E.g. adding an extension would need a block like:

RUN apt-get update \
    && apt-get install -y php8.3-gnupg \
    && apt-get -y autoremove \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

It's worth noting though, that Sail is intended as a quick-start Docker development environment and once you get to the point that you require more that Sail offers out of the box you will need to start understanding more about how Docker works. Once you get that understanding, you probably don't need Sail any more.

Upvotes: 1

Related Questions