Skip to content

Commit

Permalink
Docker configuration
Browse files Browse the repository at this point in the history
Docker configuration. Thanks to Jesús Manuel Vargas, I have reworked his stack https://github.com/jmvargas/docker-compose-php-stack
  • Loading branch information
davidecristiani committed Jan 30, 2022
1 parent 28fbc6f commit adef51c
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor/
node_modules/
npm-debug.log
yarn-error.log
yarn-error.log
/log/
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ The result is a set of all possible teams, i.e., an array **assembled_texts**.
###Technical notes
The program is educational and is written in the programming language PHP.

The program is included in the index.php file.
The program is included in the _/src/index.php_ file.

All the words you see in bold in this README will be found with the same name as variables in the program.
If a word is a plural (with a final "s") it's an indication that the variable is an array.

A Docker Compose "nginx"/"php-fpm" configuration is included
to allow you to run the file without using your own web server.

To execute the program with Docker Compose:

- Install and activate Docker (if you haven't already)
- Open the terminal
- Execute a `cd` command the main directory (the directory that contains the file _docker-compose.yml_).
- Execute the command `docker-compose up`
- Open your browser and go to the address [http://localhost](http://localhost)

All the words you see in this README in this will be found with the same name in the form of variables in the program.
If the word is a plural (with a final "s") it is an indication that the variable is an array.
A docker configuration is included to allow you to run the file without installing it on a server.
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '2'
services:
# PHP
phpfpm:
restart: always
build: php-fpm
volumes:
- ./php-fpm/php-fpm.conf:/usr/local/etc/php-fpm.conf
- ./php-fpm/php.ini:/usr/local/etc/php/php.ini
- ./src:/var/www/html
- ./log/php-fpm:/var/log/php-fpm

# Nginx
nginx:
restart: always
image: nginx:1-alpine
ports:
- "80:80"
links:
- phpfpm:phpfpm
volumes:
- ./nginx/vhost.conf:/etc/nginx/conf.d/default.conf
- ./src:/var/www/html
- ./log/nginx:/var/log/nginx
32 changes: 32 additions & 0 deletions nginx/vhost.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
server {
listen 0.0.0.0:80;
server_name localhost;

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

root /var/www/html/;

location / {
index index.php;
}

location ~ \.php$ {
fastcgi_pass phpfpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

location /php/fpm/status {
fastcgi_pass phpfpm:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

location /php/fpm/ping {
fastcgi_pass phpfpm:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
3 changes: 3 additions & 0 deletions php-fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM php:8.1-fpm

CMD ["php-fpm"]
28 changes: 28 additions & 0 deletions php-fpm/php-fpm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[global]

error_log = /var/log/php-fpm/fpm-error.log
daemonize = no

[www]

user = www-data
group = www-data

listen = [::]:9000

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.status_path = /php/fpm/status

clear_env = no

access.log = /var/log/php-fpm/access.log
access.format = "%t \"%m %r%Q%q\" %s %{mili}dms %{kilo}Mkb %C%%"
catch_workers_output = yes

php_flag[display_errors] = on
;php_admin_flag[log_errors] = true
php_admin_value[date.timezone] = "Europe/Rome"
2 changes: 2 additions & 0 deletions php-fpm/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Date]
date.timezone = "Europe/Rome"
3 changes: 3 additions & 0 deletions src/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

echo "Hello world!";

0 comments on commit adef51c

Please sign in to comment.