The PHP Interpreter
If you like / use this project, please let me known by adding a ★ on the GitHub repository.
# Define installation folder
export INSTALL_DIRECTORY=/usr/bin
# Use local installation
sudo bin/installer install
# Use remote installation
curl --location "https://github.com/timonier/php/raw/master/bin/installer" | sudo sh -s -- installNote 1: If you do not define INSTALL_DIRECTORY, installer will use in /usr/local/bin.
Note 2: docker-for-mac users have to configure native NFS server.
Run the command php:
# See all php options
php --help
# Run php as interactive shell
php -a
#Interactive shell
#
#php >
# Define date.timezone
php -d date.timezone=Europe/Paris -i | grep "date.timezone"
# Enable xdebug
php -m | grep "xdebug"
# (empty)
php -d zend_extension=xdebug.so -m | grep "xdebug"
# xdebugNote: You can also define the PHP configuration in ${HOME}/.php.
# Create index.php
cat > index.php << "EOF"
<?php
phpinfo();
EOF
# Create nginx configuration
cat > default.conf << "EOF"
server {
listen *:80 default_server;
server_name _;
index index.php;
root /home/www-data;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
EOF
# Start services
docker run --detach --net host --volume $PWD:/home/www-data:ro timonier/php:fpm
docker run --detach --net host --volume $PWD:/etc/nginx/conf.d:ro --volume $PWD:/home/www-data:ro timonier/nginx
# Go to "http://localhost/"It is possible to change UID and / or GID of user www-data (user used to run php-fpm) with environment variables PHP_UID and PHP_GID:
docker run --env PHP_GID=1005 --env PHP_UID=1005 --interactive --rm --tty timonier/php:fpmIt is possible to run a container in read-only mode if you mount the following folders:
/etcand/home/www-dataif you want to changeUIDorGIDof userphp-fpm./run,/tmp,/usr/local/etc/phpand/usr/local/etc/php-fpm.d.
Note: /run and /tmp can be mount as tmpfs. In that case, /run must have flag exec.
# If you do not want to change "UID" or "GID" of user "www-data"
docker run --interactive --read-only --rm --tmpfs /run:exec --tmpfs /tmp --tty timonier/php:fpm
# If you want to change "UID" or "GID" of user "nginx"
docker run --interactive --read-only --rm --tmpfs /run:exec --tmpfs /tmp --tty --volume /etc --volume /home/www-data timonier/php:nginxdocker run --interactive --publish 80:80 --rm --tty timonier/php:nginxNote: By default nginx opens port 80.
It is possible to change UID and / or GID of users nginx (user used to run nginx) and www-data (user used to run php-fpm) with environment variables NGINX_UID, NGINX_GID, PHP_UID and PHP_GID:
docker run --env NGINX_GID=1005 --env NGINX_UID=1005 --env PHP_GID=1006 --env PHP_UID=1006 --interactive --publish 80:80 --rm --tty timonier/php:nginxIt is possible to run a container in read-only mode if you mount the following folders:
/etcif you want to changeUIDorGIDof usernginx./etcand/home/www-dataif you want to changeUIDorGIDof userphp-fpm./etc/nginx,/run,/tmp,/usr/local/etc/php,/usr/local/etc/php-fpm.dand/var/cache/nginx.
Note: /run, /tmp and /var/cache/nginx can be mount as tmpfs. In that case, /run must have flag exec.
# If you do not want to change "UID" or "GID" of user "nginx"
docker run --interactive --publish 80:80 --read-only --rm --tmpfs /run:exec --tmpfs /tmp --tmpfs /var/cache/nginx --tty timonier/php:nginx
# If you want to change "UID" or "GID" of user "nginx"
docker run --interactive --publish 80:80 --read-only --rm --tmpfs /run:exec --tmpfs /tmp --tmpfs /var/cache/nginx --tty --volume /etc --volume /home/www-data timonier/php:nginx