Skip to content

Commit 1c57b7e

Browse files
committed
Install xdebug and xhprof as standard
This also adds a new PHP_EXTENSION-[name]=1 environment variable optino to call docker-php-ext-enable on start.
1 parent ff023e2 commit 1c57b7e

File tree

5 files changed

+99
-4
lines changed

5 files changed

+99
-4
lines changed

.github/workflows/test_buildx_and_publish.yml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
-v $PWD/tests/docker-entrypoint.d:/docker-entrypoint.d \
3030
-e PHP_INI-memory_limit=256M \
3131
-e PHP_INI-apc.enabled=0 \
32+
-e PHP_EXTENSION-xhprof=1 \
3233
moodle-php-apache
3334
docker exec test0 php /var/www/html/test.php
3435
docker exec test0 php /var/www/html/check-ini.php

README.md

+68
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,74 @@ 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+
* xmlrpc-beta
119+
* xsl
120+
* zip
121+
122+
All of the above extensions are enabled by default, except for:
123+
124+
* pcov
125+
* xdebug
126+
* xhprof
127+
128+
### Enabling optional extensions
129+
130+
Several extensions are installed, but not enabled. You can enable them easily.
131+
132+
### xdebug
133+
134+
The `xdebug` extension can be enabled by specifying the following environment variable when starting the container:
135+
136+
```bash
137+
PHP_EXTENSION-xdebug=1
138+
```
139+
140+
### xhprof
141+
142+
The `xdebug` extension can be enabled by specifying the following environment variable when starting the container:
143+
144+
```bash
145+
PHP_EXTENSION-xhprof=1
146+
```
147+
148+
#### pcov
149+
150+
The `pcov` extension is typically not used in the web UI, and is no longer recommended for use in code coverage generation in the CLI.
151+
152+
It is currently included but may be removed at a later date.
153+
154+
It can be enabled by specifying the following environment variable when starting the container:
155+
156+
```bash
157+
PHP_INI-pcov.enabled=1
158+
```
159+
93160
## See also
161+
94162
This container is part of a set of containers for Moodle development, see also:
95163

96164
* [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
@@ -67,6 +67,9 @@ docker-php-ext-install -j$(nproc) ldap
6767
pecl install apcu igbinary memcached pcov redis solr timezonedb uuid xmlrpc-beta
6868
docker-php-ext-enable apcu igbinary memcached pcov redis solr timezonedb uuid xmlrpc
6969

70+
# Install, but do not enable, xdebug and xhprof.
71+
pecl install xdebug xhprof
72+
7073
echo 'apc.enable_cli = On' >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini
7174

7275
echo "pcov.enabled=0" >> /usr/local/etc/php/conf.d/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

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
<?php
22

3-
$fileuploads = ini_get('file_uploads');
4-
$apcenabled = ini_get('apc.enabled');
5-
$memorylimit = ini_get('memory_limit');
6-
73
$allokay = true;
84
$message = [];
5+
6+
$fileuploads = ini_get('file_uploads');
97
if (!empty($fileuploads)) {
108
$allokay = false;
119
$message[] = "Uploads are enabled and should be disabled.";
1210
$message[] = var_export($fileuploads, true);
1311
}
1412

13+
$apcenabled = ini_get('apc.enabled');
1514
if (!empty($apcenabled)) {
1615
$allokay = false;
1716
$message[] = "apc.enabled is not Off (0): ({$apcenabled})";
1817
}
1918

19+
$memorylimit = ini_get('memory_limit');
2020
if ($memorylimit !== '256M') {
2121
$allokay = false;
2222
$message[] = "Memory limit not set to 256M: ({$memorylimit})";
2323
}
2424

25+
$xhprof = extension_loaded('xhprof');
26+
if (!$xhprof) {
27+
$allokay = false;
28+
$message[] = "xhprof extension not loaded (should be enabled)";
29+
}
30+
31+
$xdebug = extension_loaded('xdebug');
32+
if ($xdebug) {
33+
$allokay = false;
34+
$message[] = "xdebug extension loaded (should be disabled)";
35+
}
36+
2537
if (php_sapi_name() === 'cli') {
2638
if ($allokay) {
2739
echo "OK\n";

0 commit comments

Comments
 (0)