Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ A few links:
- [Report an issue](https://github.com/glpi-project/glpi/issues/new?template=bug_report.yml)
- [Documentation](https://glpi-project.org/documentation/)


This repository contains build files for docker images available in [Github Container Registry](https://github.com/orgs/glpi-project/packages?ecosystem=container) and [Docker hub](https://hub.docker.com/r/glpi/glpi).

## How to use this image

### via [docker compose](https://github.com/docker/compose)

**docker-compose.yml**
### docker-compose.yml

```yaml
services:
glpi:
Expand All @@ -28,6 +28,8 @@ services:
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
ports:
- "80:80"

Expand All @@ -49,17 +51,60 @@ services:
retries: 10
expose:
- "3306"

redis:
image: "redis:7-alpine"
restart: "unless-stopped"
command: redis-server --appendonly yes
volumes:
- "./storage/redis:/data"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
start_period: 5s
interval: 5s
timeout: 5s
retries: 10
expose:
- "6379"
```

And an .env file:

**.env**
### .env

```env
# Database configuration
GLPI_DB_HOST=db
GLPI_DB_PORT=3306
GLPI_DB_NAME=glpi
GLPI_DB_USER=glpi
GLPI_DB_PASSWORD=glpi

# Redis session configuration
# Set to "true" to use Redis for PHP sessions (recommended for multi-instance deployments)
# Set to "false" to use file-based sessions (default, suitable for single instance)
GLPI_USE_REDIS_SESSION=false
GLPI_REDIS_SESSION_HOST=redis:6379

# PHP configuration - General
PHP_MEMORY_LIMIT=256M
PHP_MAX_EXECUTION_TIME=60
PHP_MAX_INPUT_VARS=5000

# PHP configuration - File uploads
PHP_POST_MAX_SIZE=20M
PHP_UPLOAD_MAX_FILESIZE=20M

# PHP configuration - Security
PHP_SESSION_COOKIE_HTTPONLY=on
PHP_SESSION_COOKIE_SAMESITE=Strict
PHP_EXPOSE_PHP=off

# PHP configuration - OPcache
PHP_OPCACHE_VALIDATE_TIMESTAMPS=1
PHP_OPCACHE_MAX_ACCELERATED_FILES=10000
PHP_OPCACHE_MEMORY_CONSUMPTION=128
PHP_OPCACHE_MAX_WASTED_PERCENTAGE=5
```

Then launch it with:
Expand Down Expand Up @@ -93,6 +138,7 @@ If you want to initialize the timezones support for GLPI, we need to first GRANT
```bash
docker exec -it <db_container_id> mysql -u root -p -e "GRANT SELECT ON mysql.time_zone_name TO 'glpi'@'%';FLUSH PRIVILEGES;"
```

The root password will be the one you found in the logs of the `db` container previously.

Then you can run the following command to initialize the timezones on the GLPI container:
Expand Down
20 changes: 18 additions & 2 deletions glpi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ RUN ln -s $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
COPY ./files/etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default.conf
COPY ./files/etc/apache2/conf-available/zzz-glpi.conf /etc/apache2/conf-available/zzz-glpi.conf
COPY ./files/etc/cron.d/glpi /etc/cron.d/glpi
COPY ./files/etc/php/conf.d/glpi.ini $PHP_INI_DIR/conf.d/glpi.ini
COPY ./files/opt/glpi/ /opt/glpi/
RUN find /opt/glpi -type f -iname "*.sh" -exec chmod u+x {} \;

Expand All @@ -162,7 +161,24 @@ ENV \
GLPI_VAR_DIR=/var/glpi/files \
GLPI_LOG_DIR=/var/glpi/logs \
GLPI_SKIP_AUTOINSTALL=false \
GLPI_SKIP_AUTOUPDATE=false
GLPI_SKIP_AUTOUPDATE=false \
GLPI_USE_REDIS_SESSION=false \
GLPI_REDIS_SESSION_HOST=redis:6379

# PHP configuration environment variables
ENV \
PHP_SESSION_COOKIE_HTTPONLY=on \
PHP_SESSION_COOKIE_SAMESITE=Strict \
PHP_EXPOSE_PHP=off \
PHP_POST_MAX_SIZE=20M \
PHP_UPLOAD_MAX_FILESIZE=20M \
PHP_MEMORY_LIMIT=256M \
PHP_MAX_INPUT_VARS=5000 \
PHP_MAX_EXECUTION_TIME=60 \
PHP_OPCACHE_VALIDATE_TIMESTAMPS=1 \
PHP_OPCACHE_MAX_ACCELERATED_FILES=10000 \
PHP_OPCACHE_MEMORY_CONSUMPTION=128 \
PHP_OPCACHE_MAX_WASTED_PERCENTAGE=5

# Copy the env variables to `/etc/environment`, to make them available for the commands executed by the cron service
RUN printenv > /etc/environment
Expand Down
7 changes: 0 additions & 7 deletions glpi/files/etc/php/conf.d/glpi.ini

This file was deleted.

2 changes: 2 additions & 0 deletions glpi/files/opt/glpi/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
set -e -u -o pipefail

/opt/glpi/entrypoint/init-volumes-directories.sh
/opt/glpi/entrypoint/configure-php.sh
/opt/glpi/entrypoint/configure-session.sh
/opt/glpi/entrypoint/forward-logs.sh

exec "$@"
36 changes: 36 additions & 0 deletions glpi/files/opt/glpi/entrypoint/configure-php.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
set -e -u -o pipefail

echo "Configuring PHP settings from environment variables..."

# Create dynamic PHP configuration file
cat > /usr/local/etc/php/conf.d/glpi-dynamic.ini <<EOF
; Session cookies security
session.cookie_httponly = ${PHP_SESSION_COOKIE_HTTPONLY}
session.cookie_samesite = "${PHP_SESSION_COOKIE_SAMESITE}"

; Do not expose PHP version
expose_php = ${PHP_EXPOSE_PHP}

; Allow posting larger files (e.g., for attachments)
post_max_size = ${PHP_POST_MAX_SIZE}
upload_max_filesize = ${PHP_UPLOAD_MAX_FILESIZE}

; Increase values for large operations
memory_limit = ${PHP_MEMORY_LIMIT}
max_input_vars = ${PHP_MAX_INPUT_VARS}
max_execution_time = ${PHP_MAX_EXECUTION_TIME}

; OPCache settings
opcache.validate_timestamps = ${PHP_OPCACHE_VALIDATE_TIMESTAMPS}
opcache.max_accelerated_files = ${PHP_OPCACHE_MAX_ACCELERATED_FILES}
opcache.memory_consumption = ${PHP_OPCACHE_MEMORY_CONSUMPTION}
opcache.max_wasted_percentage = ${PHP_OPCACHE_MAX_WASTED_PERCENTAGE}
EOF

echo "PHP configuration applied:"
echo " - Memory limit: ${PHP_MEMORY_LIMIT}"
echo " - Post max size: ${PHP_POST_MAX_SIZE}"
echo " - Upload max filesize: ${PHP_UPLOAD_MAX_FILESIZE}"
echo " - Max execution time: ${PHP_MAX_EXECUTION_TIME}s"
echo " - OPcache memory: ${PHP_OPCACHE_MEMORY_CONSUMPTION}M"
21 changes: 21 additions & 0 deletions glpi/files/opt/glpi/entrypoint/configure-session.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -e -u -o pipefail

# Configure PHP session handler based on environment variables
if [ "${GLPI_USE_REDIS_SESSION:-false}" = "true" ]; then
echo "Configuring PHP to use Redis for session management..."
echo "Redis host: ${GLPI_REDIS_SESSION_HOST}"

# Create session configuration file
cat > /usr/local/etc/php/conf.d/session-redis.ini <<EOF
; Redis session configuration
session.save_handler = redis
session.save_path = "tcp://${GLPI_REDIS_SESSION_HOST}"
EOF

echo "Redis session configuration applied."
else
echo "Using default file-based session management..."
# Remove Redis session config if it exists
rm -f /usr/local/etc/php/conf.d/session-redis.ini
fi
10 changes: 10 additions & 0 deletions glpi/files/opt/glpi/startup/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ Install_GLPI() {
--no-interaction --quiet'
}

Configure_Redis_Cache() {
if [ "${GLPI_USE_REDIS_SESSION:-false}" = "true" ]; then
echo "Configuring GLPI to use Redis for cache..."
su www-data -s /bin/bash -c "bin/console cache:configure --context core --dsn redis://${GLPI_REDIS_SESSION_HOST}/1 --no-interaction"
echo "Redis cache configuration applied."
fi
}

greetings() {
local new_installation="$1"

Expand Down Expand Up @@ -65,12 +73,14 @@ if ! GLPI_Installed; then
echo "GLPI is not installed. but auto-install is enabled. Starting installation."
echo "Please wait until you see the greeting, this may take a minute..."
Install_GLPI
Configure_Redis_Cache
greetings true
fi
else
if ! $GLPI_SKIP_AUTOUPDATE; then
echo "GLPI is installed, and auto-update is enabled. Starting update..."
Update_GLPI
Configure_Redis_Cache
greetings false
fi
fi