docker php fpm alpine

Docker php fpm alpine

This PHP FPM and PHP CLI docker image based on Alpine. Alpine is based on Alpine Linux, lightweight Linux distribution based on BusyBox. The size of the image is very small, less than 50 MB!

Versions and tags are based on PHP versions.

Here are the supported tags and respective Dockerfile links.

The cli tag show that the PHP is used for command line and the fpm is designed to be used with PHP-FPM. It is fit with Alpine-Nginx docker image.

PHP 7.0 is still using edge/testing repository for PHP7 packages. PHP 7.0 CLI is not available yet, since there’s no php7-cli package in the repository.

This image is published in the Docker Hub. Simply run this command below to get it to your machine.

Or if you want to use cli image.

Alternatively you can clone this repository and build the image using the docker build command.

This image use Asia/Jakarta timezone by default. You can change the timezone by change the TIMEZONE environment on Dockerfile and then build.

The site data, config, and log data is configured to be located in a Docker volume so that it is persistent and can be shared by other containers or a backup container).

There is volume defined in this image /www that is shared with Nginx container. Please make sure both containers can access the directory. You can store the sites data to this directory.

The config is set using environments listed below on build.

Change it in Dockerfile and you can rebuild your image.

Create and Run The Container

If you run and want to link Nginx container, make sure you created and run this PHP-FPM the container before running this Nginx container. Make sure the /www volume in PHP-FPM container is mapped.

Stopping The Container

Start The Container Again

To ease the job, make alias for PHP-CLI. Add this line to

/.bashrc so we can call it as regular php command.

About

PHP FPM and PHP CLI docker image based on Alpine Linux

Источник

Запуск PHP приложения на Docker контейнерах (PHP-FPM, Nginx, PostgreSQL)

За последний год программное обеспечение для автоматизации развертывания в среде виртуализации на уровне операционной системы набирает большие обороты. Эта статья послужит новичкам в этой сфере примером, как нужно упаковывать свое приложение в Docker контейнеры.

В классическом виде, PHP приложение представляет из себя следующие составляющие:

1. Установка Docker

Для начала работы, нам потребуется Docker. Скачать его можно на официальном сайте Docker.

2. Создание образов

Docker создает образы на основе DockerFile файлов, в котором описывается функционал. Мы создадим 3 образа для наших составляющих.

DockerFileNginx

В данном DockerFile мы создаем пользователя www-data с группой 82 и устанавливаем Nginx. Последняя строка COPY предполагает, что у вас конфигурация приложения лежит в папке config/website.conf. Она скопируется в /etc/nginx/conf.d/website.conf.

Читайте также:  Что указывать в графе район

DockerFilePostgresql

В этом образе, мы будем отталкиваться от образа postgres:9.5.2 и выполним команду для определения локали и языка.

DockerFile

Этот образ послужит нам основным образом для нашего приложения. Сначала мы устанавливаем все необходимое для PHP и PHP-FPM. Далее, мы копируем текущую папку приложения в /usr/src/app, где будет распологаться наше приложение. В самом конце мы запускаем PHP-FPM.

Создание образов на основе DockerFile’ов

И так, у нас есть есть DockerFile’ы, на основе которых мы должны создать образы. Образы создаются очень просто. Достаточно выполнить следующие команды:

Мы создаем образы, прикрепляем их к нашему аккаунту на Docker Hub. Теперь, нам нужно отправить наши образы на репозиторий в Docker Hub. Выполняем следующие команды:

Запуск образов на сервере

Мы почти у цели! Нам осталось загрузить образы из репозитория и запустить их. Загружаем их с помощью следующих команд:

Осталось их запустить. Делается это так же просто.

Вуаля! Наше приложение запущено на Docker контейнерах. И тем не менее, всем читателям-новичкам я бы обязательно ознакомиться с документацией Docker.

Всем желаю успехов в освоении новых технологий!

Источник

Docker php fpm alpine

Docker PHP-FPM 8.0 & Nginx 1.20 on Alpine Linux

Example PHP-FPM 8.0 & Nginx 1.20 setup for Docker, build on Alpine Linux. The image is only +/- 40MB large.

Docker Hub repository name change

Since we switched to PHP8 the repository name trafex/alpine-nginx-php7 didn’t make sense anymore. Because you can’t change the name of the repository on Docker Hub I created a new one.

From now on this image can be pulled from Docker Hub under the name trafex/php-nginx.

The old repository will still be available and kept up to date with trafex/php-nginx.

Start the Docker container:

See the PHP info on http://localhost, or the static html page on http://localhost/test.html

Or mount your own code to be served by PHP-FPM & Nginx

In config/ you’ll find the default configuration files for Nginx, PHP and PHP-FPM. If you want to extend or customize that you can do so by mounting a configuration file in the correct folder;

If you need Composer in your project, here’s an easy way to add it.

Building with composer

If you are building an image with source code in it and dependencies managed by composer then the definition can be improved. The dependencies should be retrieved by the composer but the composer itself ( /usr/bin/composer ) is not necessary to be included in the image.

About

Docker image with Nginx 1.20 & PHP-FPM 8.0 on Alpine Linux

Источник

Docker php fpm alpine

PrivateBin on Nginx, php-fpm & Alpine

PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted and decrypted in the browser using 256bit AES in Galois Counter mode.

Читайте также:  Twink что это такое

This repository contains the Dockerfile and resources needed to create a docker image with a pre-installed PrivateBin instance in a secure default configuration. The images are based on the docker hub Alpine image, extended with the GD module required to generate discussion avatars and the Nginx webserver to serve static JavaScript libraries, CSS & the logos. All logs of php-fpm and Nginx (access & errors) are forwarded to docker logs.

This is the all-in-one image that can be used with any storage backend supported by PrivateBin: File based storage, database or Google Cloud Storage. We also offer dedicated images for each backend:

All images contain a release version of PrivateBin and are offered with the following tags:

If you update your images automatically via pulls, the nightly or latest are recommended. If you prefer to have control and reproducability or use a form of orchestration, the numeric tags are probably preferable. The edge tag offers a preview of software in future Alpine releases and as an early warning system to detect image build issues in these.

Assuming you have docker successfully installed and internet access, you can fetch and run the image from the docker hub like this:

The parameters in detail:

Note that the volume mounted must be owned by UID 65534 / GID 82. If you run the container in a docker instance with «userns-remap» you need to add your subuid/subgid range to these numbers.

In case you want to use a customized conf.php file, for example one that has file uploads enabled or that uses a different template, add the file as a second volume:

Note: The Filesystem data storage is supported out of the box. The image includes PDO modules for MySQL, PostgreSQL and SQLite, required for the Database one, but you still need to keep the /srv/data persisted for the server salt and the traffic limiter.

Adjusting nginx or php-fpm settings

You can attach your own php.ini or nginx configuration files to the folders /etc/php8/conf.d/ and /etc/nginx/conf.d/ respectively. This would for example let you adjust the maximum size these two services accept for file uploads, if you need more then the default 10 MiB.

The image supports the use of the following two environment variables to adjust the timezone. This is most useful to ensure the logs show the correct local time.

Note: The application internally handles expiration of pastes based on a UNIX timestamp that is calculated based on the timezone set during its creation. Changing the PHP_TZ will affect this and leads to earlier (if the timezone is increased) or later (if it is decreased) expiration then expected.

Читайте также:  Virginity syndrome что это

Below is an example deployment for Kubernetes.

Note that the volume privatebin-data has to be a shared, persisted volume across all nodes, i.e. on an NFS share. It is required even when using a database, as some data is always stored in files (server salt, traffic limiters IP hashes, purge limiter time stamp).

Rolling your own image

To reproduce the image, run:

The two processes, Nginx and php-fpm, are started by s6 overlay.

Nginx is required to serve static files and caches them, too. Requests to the index.php (which is the only PHP file exposed in the document root at /var/www) are passed to php-fpm via a socket at /run/php-fpm.sock. All other PHP files and the data are stored under /srv.

The Nginx setup supports only HTTP, so make sure that you run a reverse proxy in front of this for HTTPS offloading and reducing the attack surface on your TLS stack. The Nginx in this image is set up to deflate/gzip text content.

During the build of the image the PrivateBin release archive and the s6 overlay binaries are downloaded from Github. All the downloaded Alpine packages, s6 overlay binaries and the PrivateBin archive are validated using cryptographic signatures to ensure they have not been tempered with, before deploying them in the image.

About

PrivateBin docker image based on Nginx, php-fpm & Alpine Linux stack

Источник

How do I install XDebug on docker’s official php-fpm-alpine image?

I’ve tried RUN pecl install xdebug-2.5.0 && docker-php-ext-enable xdebug

which results in an error when building:

4 Answers 4

The following is sufficient for simply installing xdebug on that image:

Building that and then running from a shell inside the resulting image produces the following:

If you are concerned about image size you can remove the dependencies:

Great answer @msanchez_aplyca. Although more correctly removing the build dependancies via apk would be:

For PHP >= 7.2 you need to use Xdebug 2.6.0+

For example, install the Xdebug 3.0.0 (released on the 25th November 2020)

Now you set it up by adding something like (using Xdebug 3.0.0 syntax, more info here):

Not the answer you’re looking for? Browse other questions tagged php docker alpine or ask your own question.

Linked

Related

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.9.16.40232

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Образовательный портал