From 911038f6fc71ec892f56c7d1f3b9fb4da5f6ff17 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:08:36 +0100 Subject: [PATCH 01/21] attempt 1 of moving to alpine --- Dockerfile | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index b4beec2..bd04d89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,10 @@ -FROM ubuntu:23.04 +FROM alpine:3.18.2 # Install dependencies -RUN apt update -RUN DEBIAN_FRONTEND=noninteractive \ -apt install nginx php8.1 php8.1-fpm php8.1-gd php8.1-imagick -y - -# Clean up -RUN apt clean +RUN apk update && \ + apk upgrade && \ + apk add --no-cache nginx php8.1 php8.1-fpm php8.1-gd php8.1-imagick && \ + rm -rf /var/cache/apk/* # Set up nginx COPY ./docker/nginx.conf /etc/nginx/nginx.conf -- 2.45.2 From f8a23c19ba3ab279e44492d4ebdb4e266e5122e7 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:10:16 +0100 Subject: [PATCH 02/21] attempt 2 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bd04d89..bed3faf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM alpine:3.18.2 # Install dependencies RUN apk update && \ apk upgrade && \ - apk add --no-cache nginx php8.1 php8.1-fpm php8.1-gd php8.1-imagick && \ + apk add --no-cache nginx php8 php8-fpm && \ rm -rf /var/cache/apk/* # Set up nginx -- 2.45.2 From 99ca7597f43ca7b17f79093fda6ac9dd1e210981 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:11:43 +0100 Subject: [PATCH 03/21] attempt 3 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bed3faf..81c9f1e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM alpine:3.18.2 # Install dependencies RUN apk update && \ apk upgrade && \ - apk add --no-cache nginx php8 php8-fpm && \ + apk add --no-cache nginx php php-fpm && \ rm -rf /var/cache/apk/* # Set up nginx -- 2.45.2 From 14ca6a6ba34d05235a7bbe522d44d05dbd687946 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:14:05 +0100 Subject: [PATCH 04/21] pin php version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 81c9f1e..4dfbb08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM alpine:3.18.2 # Install dependencies RUN apk update && \ apk upgrade && \ - apk add --no-cache nginx php php-fpm && \ + apk add --no-cache nginx php81 php81-fpm && \ rm -rf /var/cache/apk/* # Set up nginx -- 2.45.2 From bcb0a5d61a2ca2d1b1d3760107998add82294b7b Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:16:13 +0100 Subject: [PATCH 05/21] start work on making init script work --- docker/start.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/docker/start.sh b/docker/start.sh index 9751857..a0cb093 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -1,18 +1,20 @@ -if [[ -z "${MAX_UPLOAD_SIZE}" ]]; then +#!/bin/sh + +if [ -z "$MAX_UPLOAD_SIZE" ]; then MAX_UPLOAD_SIZE="8M" # Default fallback value fi echo "Checking if upload script exists in /var/www/html" if [ -f "/var/www/html/upload.php" ]; then - echo "Upload script was found, ignoring copy." + echo "Upload script was found, ignoring copy." else - cp /tmp/upload.php /var/www/html - echo "Upload script was not found, copying it." + cp /tmp/upload.php /var/www/html + echo "Upload script was not found, copying it." fi # Letting php know that we are running in docker -echo "env[DOCKER] = true" >> /etc/php/8.1/fpm/pool.d/www.conf -echo "clear_env = no" >> /etc/php/8.1/fpm/pool.d/www.conf +echo "env[DOCKER] = true" >> /etc/php81/php-fpm.d/www.conf +echo "clear_env = no" >> /etc/php81/php-fpm.d/www.conf echo "Setting permissions for upload script" chmod 777 /var/www/html/upload.php @@ -20,16 +22,15 @@ chmod 777 /var/www/html/upload.php echo "Setting max upload size to ${MAX_UPLOAD_SIZE}" # Set max upload size for php -sed -i "s/^upload_max_filesize = .*/upload_max_filesize = ${MAX_UPLOAD_SIZE}/" /etc/php/8.1/fpm/php.ini -sed -i "s/^post_max_size = .*/post_max_size = ${MAX_UPLOAD_SIZE}/" /etc/php/8.1/fpm/php.ini +sed -i "s/^upload_max_filesize = .*/upload_max_filesize = ${MAX_UPLOAD_SIZE}/" /etc/php81/php.ini +sed -i "s/^post_max_size = .*/post_max_size = ${MAX_UPLOAD_SIZE}/" /etc/php81/php.ini # Set max upload size for nginx sed -i "s/client_max_body_size 500M;/client_max_body_size ${MAX_UPLOAD_SIZE};/" /etc/nginx/nginx.conf function start() { echo "Starting PHP & Nginx" - /etc/init.d/php8.1-fpm start && - chmod 777 /run/php/php8.1-fpm.sock && + php-fpm8 && nginx -g 'daemon off;' } -- 2.45.2 From f7563615214eae936f8da33a3edbb18bc424aac6 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:18:05 +0100 Subject: [PATCH 06/21] no idea if this will work --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4dfbb08..551911c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,4 @@ COPY ./upload.php /tmp/upload.php COPY ./docker/start.sh /start.sh # Start server -CMD ["bash", "/start.sh"] \ No newline at end of file +CMD ["sh", "/start.sh"] \ No newline at end of file -- 2.45.2 From cf219a418e3d60b5ddf07908848c072bcff9aade Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:19:15 +0100 Subject: [PATCH 07/21] fix php not loading? --- docker/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/start.sh b/docker/start.sh index a0cb093..814482e 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -30,7 +30,7 @@ sed -i "s/client_max_body_size 500M;/client_max_body_size ${MAX_UPLOAD_SIZE};/" function start() { echo "Starting PHP & Nginx" - php-fpm8 && + php-fpm81 && nginx -g 'daemon off;' } -- 2.45.2 From ade90e81e97836c53bb2b2786b8e159bed9de45e Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:24:42 +0100 Subject: [PATCH 08/21] make php use a sock --- docker/nginx.conf | 2 +- docker/start.sh | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docker/nginx.conf b/docker/nginx.conf index df0dc49..217b5eb 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -44,7 +44,7 @@ http { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass unix:/run/php/php8.1-fpm.sock; + fastcgi_pass unix:/run/php/php.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_index index.php; diff --git a/docker/start.sh b/docker/start.sh index 814482e..2b39f2a 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -16,6 +16,9 @@ fi echo "env[DOCKER] = true" >> /etc/php81/php-fpm.d/www.conf echo "clear_env = no" >> /etc/php81/php-fpm.d/www.conf +# Set php-fpm to listen on socket +RUN sed -i 's/^listen = .*/listen = \/run\/php\/php.sock/' /etc/php8.1/php-fpm.d/www.conf + echo "Setting permissions for upload script" chmod 777 /var/www/html/upload.php -- 2.45.2 From cf5dd64b46000ee635826b1325ebf2ae9f996ae8 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:27:01 +0100 Subject: [PATCH 09/21] this isn't a Dockerfile skull --- docker/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/start.sh b/docker/start.sh index 2b39f2a..e602157 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -17,7 +17,7 @@ echo "env[DOCKER] = true" >> /etc/php81/php-fpm.d/www.conf echo "clear_env = no" >> /etc/php81/php-fpm.d/www.conf # Set php-fpm to listen on socket -RUN sed -i 's/^listen = .*/listen = \/run\/php\/php.sock/' /etc/php8.1/php-fpm.d/www.conf +sed -i 's/^listen = .*/listen = \/run\/php\/php.sock/' /etc/php8.1/php-fpm.d/www.conf echo "Setting permissions for upload script" chmod 777 /var/www/html/upload.php -- 2.45.2 From 50da4c5052b20b19a49579e94e18ec783fd469ad Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:28:33 +0100 Subject: [PATCH 10/21] chatgpt is silly, but I am more silly --- docker/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/start.sh b/docker/start.sh index e602157..ea8b702 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -17,7 +17,7 @@ echo "env[DOCKER] = true" >> /etc/php81/php-fpm.d/www.conf echo "clear_env = no" >> /etc/php81/php-fpm.d/www.conf # Set php-fpm to listen on socket -sed -i 's/^listen = .*/listen = \/run\/php\/php.sock/' /etc/php8.1/php-fpm.d/www.conf +sed -i 's/^listen = .*/listen = \/run\/php\/php.sock/' /etc/php81/php-fpm.d/www.conf echo "Setting permissions for upload script" chmod 777 /var/www/html/upload.php -- 2.45.2 From 1ac3a217761c7260ceab2786bdbc0b6bfbd404c6 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:30:33 +0100 Subject: [PATCH 11/21] maybe this will fix it? who knows --- docker/start.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/start.sh b/docker/start.sh index ea8b702..137b6fb 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -17,6 +17,7 @@ echo "env[DOCKER] = true" >> /etc/php81/php-fpm.d/www.conf echo "clear_env = no" >> /etc/php81/php-fpm.d/www.conf # Set php-fpm to listen on socket +touch /run/php/php.sock sed -i 's/^listen = .*/listen = \/run\/php\/php.sock/' /etc/php81/php-fpm.d/www.conf echo "Setting permissions for upload script" -- 2.45.2 From 75e5f47d8438e837220b56b5cc8b5569a87cb317 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:32:46 +0100 Subject: [PATCH 12/21] pls work - create php dir for socket --- docker/start.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker/start.sh b/docker/start.sh index 137b6fb..bae9ec1 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -16,6 +16,9 @@ fi echo "env[DOCKER] = true" >> /etc/php81/php-fpm.d/www.conf echo "clear_env = no" >> /etc/php81/php-fpm.d/www.conf +# Create the directory for PHP socket +mkdir -p /run/php + # Set php-fpm to listen on socket touch /run/php/php.sock sed -i 's/^listen = .*/listen = \/run\/php\/php.sock/' /etc/php81/php-fpm.d/www.conf -- 2.45.2 From 725f655fd9eab9a4c04896fa5cf39d2c1d287a60 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:34:15 +0100 Subject: [PATCH 13/21] show fallback msg --- docker/start.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/start.sh b/docker/start.sh index bae9ec1..a2df2d9 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -1,7 +1,9 @@ #!/bin/sh +# TODO: add all the other fallback values for the other variables if [ -z "$MAX_UPLOAD_SIZE" ]; then MAX_UPLOAD_SIZE="8M" # Default fallback value + echo "MAX_UPLOAD_SIZE was not set, using default value of ${MAX_UPLOAD_SIZE}" fi echo "Checking if upload script exists in /var/www/html" -- 2.45.2 From 6c1de0446bc72c940a1661fd242d7a8312ed9226 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:35:47 +0100 Subject: [PATCH 14/21] set socket perms --- docker/start.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/start.sh b/docker/start.sh index a2df2d9..c53aa40 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -40,6 +40,7 @@ sed -i "s/client_max_body_size 500M;/client_max_body_size ${MAX_UPLOAD_SIZE};/" function start() { echo "Starting PHP & Nginx" php-fpm81 && + chmod 777 /run/php/php.sock && nginx -g 'daemon off;' } -- 2.45.2 From e47372cdc4eebc456e66a6099644878c602f7a4e Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:41:26 +0100 Subject: [PATCH 15/21] re-add imagick --- Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Dockerfile b/Dockerfile index 551911c..de2bcd5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,17 @@ FROM alpine:3.18.2 +ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/ + # Install dependencies RUN apk update && \ apk upgrade && \ apk add --no-cache nginx php81 php81-fpm && \ rm -rf /var/cache/apk/* +# Install Imagick +RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \ + install-php-extensions imagick + # Set up nginx COPY ./docker/nginx.conf /etc/nginx/nginx.conf -- 2.45.2 From 2ce6d071b63930f745a6ac1c48f2d4fdf3148e85 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:42:40 +0100 Subject: [PATCH 16/21] part 2 --- Dockerfile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index de2bcd5..36ae65c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ FROM alpine:3.18.2 -ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/ - # Install dependencies RUN apk update && \ apk upgrade && \ @@ -9,8 +7,13 @@ RUN apk update && \ rm -rf /var/cache/apk/* # Install Imagick -RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \ - install-php-extensions imagick +RUN set -ex \ + && apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS imagemagick-dev libtool \ + && export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \ + && pecl install imagick-3.4.3 \ + && docker-php-ext-enable imagick \ + && apk add --no-cache --virtual .imagick-runtime-deps imagemagick \ + && apk del .phpize-deps # Set up nginx COPY ./docker/nginx.conf /etc/nginx/nginx.conf -- 2.45.2 From 34627788c632c13c90f16a47a0961f0ee03ed2fc Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:43:41 +0100 Subject: [PATCH 17/21] part 3 --- Dockerfile | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 36ae65c..6038798 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,13 +7,10 @@ RUN apk update && \ rm -rf /var/cache/apk/* # Install Imagick -RUN set -ex \ - && apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS imagemagick-dev libtool \ - && export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \ - && pecl install imagick-3.4.3 \ - && docker-php-ext-enable imagick \ - && apk add --no-cache --virtual .imagick-runtime-deps imagemagick \ - && apk del .phpize-deps +RUN apk add php82-pecl-imagick --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community +RUN apk --update add imagemagick +RUN pecl install imagick +RUN docker-php-ext-enable imagick # Set up nginx COPY ./docker/nginx.conf /etc/nginx/nginx.conf -- 2.45.2 From 1213a7a4a0fd9c7ef03326f848e4ab37983f4132 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:45:23 +0100 Subject: [PATCH 18/21] part 4 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6038798..64b5a54 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM alpine:3.18.2 # Install dependencies RUN apk update && \ apk upgrade && \ - apk add --no-cache nginx php81 php81-fpm && \ + apk add --no-cache nginx php81 php81-fpm php81-pear && \ rm -rf /var/cache/apk/* # Install Imagick -- 2.45.2 From 0f9c6789bfba7aac6d736edb186475a89d6213dc Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:47:22 +0100 Subject: [PATCH 19/21] i asked john, no idea what was changed --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 64b5a54..449cdbc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,14 +3,14 @@ FROM alpine:3.18.2 # Install dependencies RUN apk update && \ apk upgrade && \ - apk add --no-cache nginx php81 php81-fpm php81-pear && \ + apk add --no-cache nginx php81 php81-fpm php81-pear php81-gd && \ rm -rf /var/cache/apk/* # Install Imagick RUN apk add php82-pecl-imagick --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community RUN apk --update add imagemagick -RUN pecl install imagick -RUN docker-php-ext-enable imagick +RUN pecl install imagick && \ + docker-php-ext-enable imagick # Set up nginx COPY ./docker/nginx.conf /etc/nginx/nginx.conf -- 2.45.2 From 910963990845ef82c51c46e472855398b9176c3d Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:48:05 +0100 Subject: [PATCH 20/21] please work I am begging you --- Dockerfile | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 449cdbc..f9a0851 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,15 +3,9 @@ FROM alpine:3.18.2 # Install dependencies RUN apk update && \ apk upgrade && \ - apk add --no-cache nginx php81 php81-fpm php81-pear php81-gd && \ + apk add --no-cache nginx php81 php81-fpm php81-pecl-imagick && \ rm -rf /var/cache/apk/* -# Install Imagick -RUN apk add php82-pecl-imagick --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community -RUN apk --update add imagemagick -RUN pecl install imagick && \ - docker-php-ext-enable imagick - # Set up nginx COPY ./docker/nginx.conf /etc/nginx/nginx.conf -- 2.45.2 From d6f346200a26623b910afb80ab339d34d0114ce8 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Sat, 8 Jul 2023 00:51:33 +0100 Subject: [PATCH 21/21] revert to not using Imagick --- Dockerfile | 2 +- upload.php | 25 +++++-------------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index f9a0851..ab66bb0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM alpine:3.18.2 # Install dependencies RUN apk update && \ apk upgrade && \ - apk add --no-cache nginx php81 php81-fpm php81-pecl-imagick && \ + apk add --no-cache nginx php81 php81-fpm php81-gd && \ rm -rf /var/cache/apk/* # Set up nginx diff --git a/upload.php b/upload.php index 9ce8692..7915df5 100644 --- a/upload.php +++ b/upload.php @@ -162,28 +162,13 @@ try { // Check the file type and size if ($shouldConvertToWebp && in_array($fileType, ["png", "jpeg", "jpg"]) && $_FILES["sharex"]["size"] > $webpThreadhold) { - // Create an Imagick object from the uploaded file - $image = new Imagick($_FILES["sharex"]["tmp_name"]); - - // Convert the image to WebP - $image->setImageFormat("webp"); - $image->setImageCompressionQuality($webpQuality); - - // Set the output filename + $image = imagecreatefromstring(file_get_contents($_FILES["sharex"]["tmp_name"])); $webp_file = pathinfo($finalName, PATHINFO_FILENAME) . ".webp"; - - // Save the converted image - $image->writeImage($webp_file); - - // Free up memory - $image->clear(); - $image->destroy(); - - $fileSize = filesize($webp_file); // Update the file size - - // Update the final filename + imagewebp($image, $webp_file, 90); // Convert the image and save it + imagedestroy($image); // Free up memory $finalName = $webp_file; - $needsToBeSaved = false; + $shouldSave = false; + $fileSize = filesize($webp_file); // Update the file size } if ($needsToBeSaved) { // Save the file if it has not been saved yet -- 2.45.2