Skip to content

Commit e934518

Browse files
andrewnicolsstronk7
authored andcommitted
Install xdebug and xhprof as standard
This also adds a new PHP_EXTENSION-[name]=1 environment variable option to call docker-php-ext-enable on start.
1 parent 3911520 commit e934518

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed

.github/workflows/test_buildx_and_publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
-e PHP_INI-apc.enable_cli=0 \
3333
-e PHP_INI-pcov.enabled=1 \
3434
-e PHP_INI-upload_max_filesize=20M \
35+
-e PHP_EXTENSION_xhprof=1 \
3536
moodle-php-apache
3637
docker exec test0 php /var/www/html/test.php
3738
docker exec test0 php /var/www/html/check-ini.php

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ $ docker run --name web0 -p 8080:80 -v $PWD:/var/www/html moodlehq/moodle-php-a
2323
* Verified by [automated tests](https://travis-ci.com/moodlehq/moodle-php-apache).
2424
* Autobuilt from GHA, on push.
2525
* Support for entrypoint scripts and PHP Configuration
26+
* Many common extensions available
2627

2728
## Directories
2829
To facilitate testing and easy setup the following directories are created and owned by www-data by default:
@@ -73,7 +74,72 @@ docker run \
7374
moodle-php-apache:latest
7475
```
7576

77+
## Extensions
78+
79+
The following extensions are inluded as standard:
80+
81+
* apcu
82+
* exif
83+
* gd
84+
* igbinary
85+
* intl
86+
* ldap
87+
* memcached
88+
* mysqli
89+
* oci8
90+
* opcache
91+
* pcov
92+
* pgsql
93+
* redis
94+
* soap
95+
* solr
96+
* sqlsrv
97+
* timezonedb
98+
* uuid
99+
* xdebug
100+
* xhprof
101+
* xmlrpc-beta
102+
* xsl
103+
* zip
104+
105+
All of the above extensions are enabled by default, except for:
106+
107+
* pcov
108+
* xdebug
109+
* xhprof
110+
111+
### Enabling optional extensions
112+
113+
Several extensions are installed, but not enabled. You can enable them easily.
114+
115+
### xdebug
116+
117+
The `xdebug` extension can be enabled by specifying the following environment variable when starting the container:
118+
119+
```bash
120+
PHP_EXTENSION_xdebug=1
121+
```
122+
123+
### xhprof
124+
125+
The `xdebug` extension can be enabled by specifying the following environment variable when starting the container:
126+
127+
```bash
128+
PHP_EXTENSION_xhprof=1
129+
```
130+
131+
#### pcov
132+
133+
The `pcov` extension is typically not used in the web UI, but is widely used for code coverage generation in unit testing.
134+
135+
It can be enabled by specifying the following environment variable when starting the container:
136+
137+
```bash
138+
PHP_INI-pcov.enabled=1
139+
```
140+
76141
## See also
142+
77143
This container is part of a set of containers for Moodle development, see also:
78144

79145
* [moodle-docker](https://github.com/moodlehq/moodle-docker) a docker-composer based set of tools to get Moodle development running with zero configuration

root/tmp/setup/php-extensions.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ docker-php-ext-enable apcu igbinary memcached mongodb pcov redis solr timezonedb
6363

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

66+
# Install, but do not enable, xdebug and xhprof.
67+
pecl install xdebug xhprof
68+
6669
echo "pcov.enabled=0" >> /usr/local/etc/php/conf.d/10-docker-php-ext-pcov.ini
6770
echo "pcov.exclude='~\/(tests|coverage|vendor|node_modules)\/~'" >> /usr/local/etc/php/conf.d/10-docker-php-ext-pcov.ini
6871
echo "pcov.directory=." >> /usr/local/etc/php/conf.d/10-docker-php-ext-pcov.ini

root/usr/local/bin/moodle-docker-php-ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,15 @@ $name = $value
2626
2727
EOF
2828
fi
29+
30+
if [[ $fullname = PHP_EXTENSION_* ]]; then
31+
extension=`echo $fullname | sed 's/^PHP_EXTENSION_//'`
32+
echo "=> Found extension to enable: '${extension}'"
33+
if [[ -f "/usr/local/etc/php/conf.d/docker-php-ext-${extension}.ini" ]]; then
34+
echo "=> Extension already enabled: '${extension}'"
35+
else
36+
echo "=> Enabling extension '${extension}'"
37+
docker-php-ext-enable ${extension}
38+
fi
39+
fi
2940
done

tests/fixtures/check-ini.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
43
$allokay = true;
54
$message = [];
65

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

49+
$xhprof = extension_loaded('xhprof');
50+
if (!$xhprof) {
51+
$allokay = false;
52+
$message[] = "xhprof extension not loaded (should be enabled)";
53+
}
54+
55+
$xdebug = extension_loaded('xdebug');
56+
if ($xdebug) {
57+
$allokay = false;
58+
$message[] = "xdebug extension loaded (should be disabled)";
59+
}
60+
5061
if (php_sapi_name() === 'cli') {
5162
if ($allokay) {
5263
echo "OK\n";

0 commit comments

Comments
 (0)