PHP is a popular general-purpose scripting language that is especially suited to web development.
### Usage
This container contains the PHP 7.4.8 runtime and the PHP CLI, which is the default entrypoint. The default command is the `-v` flag, which will print version information for the PHP runtime installed.
This container hosts the PHP CLI and PHP-FPM, which is the default command fed to the entrypoint script, and will run continuously in the foreground on port 9000. PHP-FPM is the gateway program used by webservers to interpret PHP sourcecode.
Alternatively, the PHP CLI may be called as the command to the entrypoint script.
*Run*: `docker run php:7.4`
The default configuration for PHP-FPM will look for PHP content in ``/var/www/html/``.
#### Kubernetes
While this container could be configured to run Apache httpd in addtion to PHP-FPM, it is preferable to run only a single service per container, especailly in a Kuberenetes context where multiple containers can easily work in conjunction with one another. Therefore, the recommended method of using this container is alongside another webserver container, such as nginx.
In order for for your webserver container and the php-fpm contianer to opperate successfully, you will need to crete a shared volume between the containers at /var/www/html/ (by default) containing the HTML and PHP content you wish to run.
**PHP manifest example**
```
apiVersion: apps/v1
kind: Deployment
metadata:
name: php-deployment
spec:
replicas: 1
template:
metadata:
name: php-pod
spec:
serviceAccount: php-sa
volumes:
- name: php
persistentVolumeClaim:
claimName: php-app-pvc
containers:
- image: nginx:1.17.6
name: nginx
ports:
- containerPort: 80
volumeMounts:
- mountPath: "/var/www/html"
name: php-source
- image: php:7.4.8
name: php
ports:
- containerPort: 9000
volumeMounts:
- mountPath: "/var/www/html"
name: php-source
```
#### Configuration
#### PHP
The location searched for the php.ini file is specified by the ``${PHP_INI_PATH}`` environment variable, which is set to /usr/local/etc/php/ by default. To change default PHP behavior, you may do one of the following:
1. Replace the ``${PHP_INI_PATH}/pip.ini`` file with php.ini containing the desired settings
2. Add additional configuration in ``${PHP_INI_PATH}/conf.d``
3. Change the value of the ``${PHP_INI_PATH}`` env var to a directory containing your desired configuration files
See ``config/php.ini`` for the default settings for this image.
*Enabled Extensions*
The follwoing extensions are available by default in this image:
- fpm
- pdo-sqlite
- sqlite3
**NOTE**
fpm and PEAR are disabled by default for this image. To enable these, you will need to rerun the configuration script in `/usr/local/src/php` with the appropriate flags set/omitted.
PEAR is disabled by default for this image. To enable PEAR and other extensions, you will need to rerun the configuration script in `/usr/local/src/php` with the appropriate flags set/omitted.
#### PHP-FPM
PHP-FPM has its own configuration files, which are generated by the ./configure script run as part of this installation, and are located at ``/usr/local/etc/php-fpm.conf`` and ``/usr/local/etc/php-fpm.d/``.