Skip to content

Commit ddb1d9f

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 300f29b commit ddb1d9f

File tree

5 files changed

+92
-1
lines changed

5 files changed

+92
-1
lines changed

.github/workflows/test_buildx_and_publish.yml

+1
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

+65
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ $ docker run --name web0 -p 8080:80 -v $PWD:/var/www/html moodlehq/moodle-php-a
4040
* Verified by [automated tests](https://travis-ci.com/moodlehq/moodle-php-apache).
4141
* Autobuilt from GHA, on push.
4242
* Support for entrypoint scripts and PHP Configuration
43+
* Many common extensions available
4344

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

94+
## Extensions
95+
96+
The following extensions are inluded as standard:
97+
98+
* apcu
99+
* exif
100+
* gd
101+
* igbinary
102+
* intl
103+
* ldap
104+
* memcached
105+
* mysqli
106+
* oci8
107+
* opcache
108+
* pcov
109+
* pgsql
110+
* redis
111+
* soap
112+
* solr
113+
* sqlsrv
114+
* timezonedb
115+
* uuid
116+
* xdebug
117+
* xhprof
118+
* xsl
119+
* zip
120+
121+
All of the above extensions are enabled by default, except for:
122+
123+
* pcov
124+
* xdebug
125+
* xhprof
126+
127+
### Enabling optional extensions
128+
129+
Several extensions are installed, but not enabled. You can enable them easily.
130+
131+
### xdebug
132+
133+
The `xdebug` extension can be enabled by specifying the following environment variable when starting the container:
134+
135+
```bash
136+
PHP_EXTENSION_xdebug=1
137+
```
138+
139+
### xhprof
140+
141+
The `xdebug` extension can be enabled by specifying the following environment variable when starting the container:
142+
143+
```bash
144+
PHP_EXTENSION_xhprof=1
145+
```
146+
147+
#### pcov
148+
149+
The `pcov` extension is typically not used in the web UI, but is widely used for code coverage generation in unit testing.
150+
151+
It can be enabled by specifying the following environment variable when starting the container:
152+
153+
```bash
154+
PHP_INI-pcov.enabled=1
155+
```
156+
93157
## See also
158+
94159
This container is part of a set of containers for Moodle development, see also:
95160

96161
* [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

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ docker-php-ext-enable apcu igbinary memcached pcov redis timezonedb uuid
6464

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

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

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

+11
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

+12-1
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)