Skip to content

Install xdebug and xhprof as standard #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2023
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/test_buildx_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
-e PHP_INI-apc.enable_cli=0 \
-e PHP_INI-pcov.enabled=1 \
-e PHP_INI-upload_max_filesize=20M \
-e PHP_EXTENSION_xhprof=1 \
moodle-php-apache
docker exec test0 php /var/www/html/test.php
docker exec test0 php /var/www/html/check-ini.php
Expand Down
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $ docker run --name web0 -p 8080:80 -v $PWD:/var/www/html moodlehq/moodle-php-a
* Verified by [automated tests](https://travis-ci.com/moodlehq/moodle-php-apache).
* Autobuilt from GHA, on push.
* Support for entrypoint scripts and PHP Configuration
* Many common extensions available

## Directories
To facilitate testing and easy setup the following directories are created and owned by www-data by default:
Expand Down Expand Up @@ -90,7 +91,71 @@ docker run \
moodle-php-apache:latest
```

## Extensions

The following extensions are inluded as standard:

* apcu
* exif
* gd
* igbinary
* intl
* ldap
* memcached
* mysqli
* oci8
* opcache
* pcov
* pgsql
* redis
* soap
* solr
* sqlsrv
* timezonedb
* uuid
* xdebug
* xhprof
* xsl
* zip

All of the above extensions are enabled by default, except for:

* pcov
* xdebug
* xhprof

### Enabling optional extensions

Several extensions are installed, but not enabled. You can enable them easily.

### xdebug

The `xdebug` extension can be enabled by specifying the following environment variable when starting the container:

```bash
PHP_EXTENSION_xdebug=1
```

### xhprof

The `xdebug` extension can be enabled by specifying the following environment variable when starting the container:

```bash
PHP_EXTENSION_xhprof=1
```

#### pcov

The `pcov` extension is typically not used in the web UI, but is widely used for code coverage generation in unit testing.

It can be enabled by specifying the following environment variable when starting the container:

```bash
PHP_INI-pcov.enabled=1
```

## See also

This container is part of a set of containers for Moodle development, see also:

* [moodle-docker](https://github.com/moodlehq/moodle-docker) a docker-composer based set of tools to get Moodle development running with zero configuration
Expand Down
3 changes: 3 additions & 0 deletions root/tmp/setup/php-extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ docker-php-ext-enable apcu igbinary memcached pcov redis timezonedb uuid

echo 'apc.enable_cli = On' >> /usr/local/etc/php/conf.d/10-docker-php-ext-apcu.ini

# Install, but do not enable, xdebug and xhprof.
pecl install xdebug xhprof

echo "pcov.enabled=0" >> /usr/local/etc/php/conf.d/10-docker-php-ext-pcov.ini
echo "pcov.exclude='~\/(tests|coverage|vendor|node_modules)\/~'" >> /usr/local/etc/php/conf.d/10-docker-php-ext-pcov.ini
echo "pcov.directory=." >> /usr/local/etc/php/conf.d/10-docker-php-ext-pcov.ini
Expand Down
11 changes: 11 additions & 0 deletions root/usr/local/bin/moodle-docker-php-ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ $name = $value

EOF
fi

if [[ $fullname = PHP_EXTENSION_* ]]; then
extension=`echo $fullname | sed 's/^PHP_EXTENSION_//'`
echo "=> Found extension to enable: '${extension}'"
if [[ -f "/usr/local/etc/php/conf.d/docker-php-ext-${extension}.ini" ]]; then
echo "=> Extension already enabled: '${extension}'"
else
echo "=> Enabling extension '${extension}'"
docker-php-ext-enable ${extension}
fi
fi
done
13 changes: 12 additions & 1 deletion tests/fixtures/check-ini.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


$allokay = true;
$message = [];

Expand Down Expand Up @@ -47,6 +46,18 @@
$message[] = "Maximum post size not set to 206M: ({$postmaxsize})";
}

$xhprof = extension_loaded('xhprof');
if (!$xhprof) {
$allokay = false;
$message[] = "xhprof extension not loaded (should be enabled)";
}

$xdebug = extension_loaded('xdebug');
if ($xdebug) {
$allokay = false;
$message[] = "xdebug extension loaded (should be disabled)";
}

if (php_sapi_name() === 'cli') {
if ($allokay) {
echo "OK\n";
Expand Down