Browse Source

chore: updated the PHP version from 7.4 to 8 for better performance

Junior L. Botelho (JLB) 2 years ago
parent
commit
3bd1ba068b

+ 7 - 0
Dockerfile

@@ -17,6 +17,7 @@ LABEL name="LibreX" \
 # Include arguments as temporary environment variables to be handled by Docker during the image build process
 # Change or add new arguments to customize the image generated by 'docker build' command
 ARG DOCKER_SCRIPTS="docker"
+ARG NGINX_PORT=8080
 
 # Customize the environment during both execution and build time by modifying the environment variables added to the container's shell
 # When building your image, make sure to set the 'TZ' environment variable to your desired time zone location, for example 'America/Sao_Paulo'
@@ -32,9 +33,15 @@ RUN   chmod u+x "${DOCKER_SCRIPTS}/php/prepare.sh" &&\
       chmod u+x "${DOCKER_SCRIPTS}/entrypoint.sh" &&\
       chmod u+x "${DOCKER_SCRIPTS}/attributes.sh"
 
+RUN   apk add openrc abuild-rootbld --no-cache
+
 # The following lines import all Dockerfiles from other folders so that they can be built together in the final build
 INCLUDE+ docker/php/php.dockerfile
 INCLUDE+ docker/server/nginx.dockerfile
 
+RUN   apk del -r abuild-rootbld
+
+EXPOSE ${NGINX_PORT}
+
 # Configures the container to be run as an executable.
 ENTRYPOINT ["/bin/sh", "-c", "docker/entrypoint.sh"]

+ 5 - 1
docker/entrypoint.sh

@@ -1,2 +1,6 @@
 #!/bin/sh
-exec sleep infinity
+
+service php-fpm8 start
+service nginx start
+
+exec nginx -g daemon off;

+ 5 - 5
docker/php/php.dockerfile

@@ -1,5 +1,5 @@
 # Set this argument during build time to indicate that the path is for php's www.conf
-ARG WWW_CONFIG="/etc/php7/php-fpm.d/www.conf"
+ARG WWW_CONFIG="/etc/php8/php-fpm.d/www.conf"
 
 # Configure 'opensearch.xml' with Librex configuration metadata, such as the encoding and the host that stores the site
 # These configurations will replace the 'opensearch.xml' inside '.dockers/templates' for the best setup for your instance
@@ -7,7 +7,7 @@ ENV OPEN_SEARCH_TITLE="LibreX"
 ENV OPEN_SEARCH_DESCRIPTION="Framework and javascript free privacy respecting meta search engine"
 ENV OPEN_SEARCH_ENCODING="UTF-8"
 ENV OPEN_SEARCH_LONG_NAME="LibreX Search"
-ENV OPEN_SEARCH_HOST="127.0.0.1"
+ENV OPEN_SEARCH_HOST="http://localhost:${NGINX_PORT}"
 
 # Replace the 'config.php' script, which contains the most common search engine configurations, with these environment setups
 # These environment setups can be found in 'config.php', and the default configurations can be useful for most use cases
@@ -49,10 +49,10 @@ ENV CURLOPT_VERBOSE=false
 
 # Install PHP-FPM using Alpine's package manager, apk
 # Configure PHP-FPM to listen on a Unix socket instead of a TCP port, which is more secure and efficient
-RUN apk add php7 php7-fpm php7-dom php7-curl php7-xml abuild-rootbld --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing &&\
-    sed -i 's/^\s*listen = 127.0.0.1:9000/listen = \/run\/php-fpm\/php-fpm.sock/' ${WWW_CONFIG} &&\
+RUN apk add php8 php8-fpm php8-dom php8-curl php8-xml --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing &&\
+    sed -i 's/^\s*listen = 127.0.0.1:9000/listen = \/run\/php8\/php-fpm8.sock/' ${WWW_CONFIG} &&\
     sed -i 's/^\s*;\s*listen.owner = nobody/listen.owner = nginx/' ${WWW_CONFIG} &&\
     sed -i 's/^\s*;\s*listen.group = nobody/listen.group = nginx/' ${WWW_CONFIG} &&\
     sed -i 's/^\s*;\s*listen.mode = 0660/listen.mode = 0660/' ${WWW_CONFIG}
     
-RUN docker/php/prepare.sh
+CMD [ "/bin/sh", "-c", "docker/php/prepare.sh" ]

+ 1 - 1
docker/server/fastcgi.conf

@@ -1,6 +1,6 @@
 # These settings should work well for serving as a front-end of many search engines
 # on our PHP website. However, we may need to adjust them based on our specific requirements.
-fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
+fastcgi_param SCRIPT_FILENAME       $document_root$fastcgi_script_name;
 fastcgi_param QUERY_STRING          $query_string;
 fastcgi_param REQUEST_METHOD        $request_method;
 fastcgi_param CONTENT_TYPE          $content_type;

+ 3 - 3
docker/server/nginx.conf

@@ -1,6 +1,6 @@
 server {
-    listen       80;
-    server_name  ${OPEN_SEARCH_HOST} localhost;
+    listen       8080;
+    server_name  ${OPEN_SEARCH_HOST_FOR_NGINX} localhost;
 
     root   /var/www/html;
     index  index.php;
@@ -10,7 +10,7 @@ server {
     }
 
     location ~ \.php$ {
-        fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
+        fastcgi_pass   unix:/run/php8/php-fpm8.sock;
         fastcgi_index  index.php;
         include        fastcgi.conf;
     }

+ 1 - 1
docker/server/nginx.dockerfile

@@ -6,4 +6,4 @@ ADD "docker/server/nginx.conf" /etc/nginx/http.d/librex.conf
 RUN chmod u+x "/etc/nginx/fastcgi.conf" &&\
     chmod u+x "/etc/nginx/http.d/librex.conf"
 
-RUN docker/server/prepare.sh
+CMD [ "/bin/sh", "-c", "docker/server/prepare.sh" ]

+ 10 - 1
docker/server/prepare.sh

@@ -3,6 +3,15 @@
 # Load all environment variables from 'attributes.sh' using the command 'source /path/attributes.sh'
 source "docker/attributes.sh"
 
+# This condition creates the Unix socket if 'php-fpm8.sock' does not already exist.
+# This fixes an issue where Nginx starts but does not serve content
+if [ ! -d "/run/php8" ] || [ ! -S "/run/php8/php-fpm8.sock" ]; then
+    mkdir /run/php8
+    touch /run/php8/php-fpm8.sock
+fi
+
+export OPEN_SEARCH_HOST_FOR_NGINX="$(echo "${OPEN_SEARCH_HOST}" | cut -d "/" -f 3 | cut -d ":" -f 1)"
+
 # The lines below will replace the environment variables in the templates with the corresponding variables listed above. To accomplish this, the GNU 'envsubst' package will be used
 # Although not recommended (if you do not know what you are doing), you still have the option to add new substitution file templates using any required environment variables
-exec cat 'docker/server/nginx.conf' | envsubst > ${CONFIG_NGINX_TEMPLATE};
+[[ ! -s ${CONFIG_NGINX_TEMPLATE} ]] && cat 'docker/server/nginx.conf' | envsubst '${OPEN_SEARCH_HOST_FOR_NGINX}' > ${CONFIG_NGINX_TEMPLATE};