diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..beb2776 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,37 @@ +version: '3' + +services: + + php: + build: + context: ./docker/php + ports: + - 9000:9000 + volumes: + - './www-data:/srv/www/api' + - ./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf + environment: + MYSQL_USER: ${MYSQL_USER} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} + + nginx: + image: nginx:alpine + ports: + - 80:80 + volumes: + - ./www-data:/srv/www/api + - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf + depends_on: + - php + + mysql: + image: mariadb:latest + ports: + - 3306:3306 + depends_on: + - php + environment: + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} + MYSQL_DATABASE: ${MYSQL_DATABASE} + MYSQL_USER: ${MYSQL_USER} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} \ No newline at end of file diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf new file mode 100644 index 0000000..94b90c1 --- /dev/null +++ b/docker/nginx/default.conf @@ -0,0 +1,20 @@ + server { + listen 80 default_server; + + server_name api.com www.api.com; + + root /srv/www/api; + + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass php:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } + + error_log /var/log/nginx/api_error.log; + access_log /var/log/nginx/api_access.log; + } \ No newline at end of file diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile new file mode 100644 index 0000000..1729305 --- /dev/null +++ b/docker/php/Dockerfile @@ -0,0 +1,4 @@ + + FROM php:7.2-fpm + + RUN docker-php-ext-install mysqli \ No newline at end of file diff --git a/docker/php/www.conf b/docker/php/www.conf new file mode 100644 index 0000000..0a6cad1 --- /dev/null +++ b/docker/php/www.conf @@ -0,0 +1,12 @@ + [www] + + user = www-data + group = www-data + + listen = nginx:9000 + + pm = dynamic + pm.max_children = 5 + pm.start_servers = 2 + pm.min_spare_servers = 1 + pm.max_spare_servers = 3 \ No newline at end of file diff --git a/www-data/connect.php b/www-data/connect.php new file mode 100644 index 0000000..1afa35f --- /dev/null +++ b/www-data/connect.php @@ -0,0 +1,10 @@ +$host = 'mysql'; + $user = getenv('MYSQL_USER'); + $pass = getenv('MYSQL_PASSWORD'); + + $conn = mysqli_connect($host, $user, $pass); + if (!$conn) { + exit('Connection failed: '.mysqli_connect_error().PHP_EOL); + } + + echo 'Successful database connection!'.PHP_EOL; \ No newline at end of file diff --git a/www-data/index.html b/www-data/index.html new file mode 100644 index 0000000..3225efc --- /dev/null +++ b/www-data/index.html @@ -0,0 +1 @@ +HTML \ No newline at end of file diff --git a/www-data/index.php b/www-data/index.php new file mode 100644 index 0000000..f6b0c5b --- /dev/null +++ b/www-data/index.php @@ -0,0 +1 @@ +echo 'Welcome!'; \ No newline at end of file